Show More
The requested changes are too big and content was truncated. Show full diff
1 | NO CONTENT: modified file |
|
NO CONTENT: modified file | ||
The requested commit or file is too big and content was truncated. Show full diff |
1 | NO CONTENT: modified file |
|
NO CONTENT: modified file | ||
The requested commit or file is too big and content was truncated. Show full diff |
@@ -1,61 +1,62 b'' | |||||
1 | """Test cpaste magic""" |
|
1 | """Test cpaste magic""" | |
2 |
|
2 | |||
3 | tests = {'pass': ["> > > run()", |
|
3 | tests = {'pass': ["> > > run()", | |
4 | ">>> > run()", |
|
4 | ">>> > run()", | |
5 | "+++ run()", |
|
5 | "+++ run()", | |
6 |
"++ run()" |
|
6 | "++ run()", | |
|
7 | " >>> run()"], | |||
7 |
|
8 | |||
8 | 'fail': ["+ + run()", |
|
9 | 'fail': ["+ + run()", | |
9 | " ++ run()"]} |
|
10 | " ++ run()"]} | |
10 |
|
11 | |||
11 | from StringIO import StringIO |
|
12 | from StringIO import StringIO | |
12 | import sys |
|
13 | import sys | |
13 |
|
14 | |||
14 | stdin_save = sys.stdin |
|
15 | stdin_save = sys.stdin | |
15 |
|
16 | |||
16 | # NOTE: no blank lines allowed in function definition |
|
17 | # NOTE: no blank lines allowed in function definition | |
17 | def testcase(code,should_fail=False): |
|
18 | def testcase(code,should_fail=False): | |
18 | """Execute code via 'cpaste' and ensure it was executed, unless |
|
19 | """Execute code via 'cpaste' and ensure it was executed, unless | |
19 | should_fail is set. |
|
20 | should_fail is set. | |
20 |
|
21 | |||
21 | """ |
|
22 | """ | |
22 | _ip.user_ns['code_ran'] = False |
|
23 | _ip.user_ns['code_ran'] = False | |
23 | # |
|
24 | # | |
24 | src = StringIO() |
|
25 | src = StringIO() | |
25 | src.write('\n') |
|
26 | src.write('\n') | |
26 | src.write(code) |
|
27 | src.write(code) | |
27 | src.write('\n--\n') |
|
28 | src.write('\n--\n') | |
28 | src.seek(0) |
|
29 | src.seek(0) | |
29 | # |
|
30 | # | |
30 | sys.stdin = src |
|
31 | sys.stdin = src | |
31 |
|
32 | |||
32 | try: |
|
33 | try: | |
33 | cpaste |
|
34 | cpaste | |
34 | except: |
|
35 | except: | |
35 | if not should_fail: |
|
36 | if not should_fail: | |
36 | raise AssertionError("Failure not expected : '%s'" % |
|
37 | raise AssertionError("Failure not expected : '%s'" % | |
37 | code) |
|
38 | code) | |
38 | else: |
|
39 | else: | |
39 | assert code_ran |
|
40 | assert code_ran | |
40 | if should_fail: |
|
41 | if should_fail: | |
41 | raise AssertionError("Failure expected : '%s'" % code) |
|
42 | raise AssertionError("Failure expected : '%s'" % code) | |
42 | # |
|
43 | # | |
43 | finally: |
|
44 | finally: | |
44 | sys.stdin = stdin_save |
|
45 | sys.stdin = stdin_save | |
45 | # |
|
46 | # | |
46 |
|
47 | |||
47 | def run(): |
|
48 | def run(): | |
48 | """Marker function: sets a flag when executed. |
|
49 | """Marker function: sets a flag when executed. | |
49 |
|
50 | |||
50 | """ |
|
51 | """ | |
51 | _ip.user_ns['code_ran'] = True |
|
52 | _ip.user_ns['code_ran'] = True | |
52 | return 'run' # return string so '+ run()' doesn't result in success |
|
53 | return 'run' # return string so '+ run()' doesn't result in success | |
53 |
|
54 | |||
54 |
|
55 | |||
55 | ### Actual testing happens here |
|
56 | ### Actual testing happens here | |
56 |
|
57 | |||
57 | for code in tests['pass']: |
|
58 | for code in tests['pass']: | |
58 | testcase(code) |
|
59 | testcase(code) | |
59 |
|
60 | |||
60 | for code in tests['fail']: |
|
61 | for code in tests['fail']: | |
61 | testcase(code,should_fail=True) |
|
62 | testcase(code,should_fail=True) |
General Comments 0
You need to be logged in to leave comments.
Login now