Show More
@@ -29,7 +29,7 b' def check_cpaste(code, should_fail=False):' | |||||
29 | """Execute code via 'cpaste' and ensure it was executed, unless |
|
29 | """Execute code via 'cpaste' and ensure it was executed, unless | |
30 | should_fail is set. |
|
30 | should_fail is set. | |
31 | """ |
|
31 | """ | |
32 |
|
|
32 | ip.user_ns['code_ran'] = False | |
33 |
|
33 | |||
34 | src = StringIO() |
|
34 | src = StringIO() | |
35 | if not hasattr(src, 'encoding'): |
|
35 | if not hasattr(src, 'encoding'): | |
@@ -45,10 +45,10 b' def check_cpaste(code, should_fail=False):' | |||||
45 | try: |
|
45 | try: | |
46 | context = tt.AssertPrints if should_fail else tt.AssertNotPrints |
|
46 | context = tt.AssertPrints if should_fail else tt.AssertNotPrints | |
47 | with context("Traceback (most recent call last)"): |
|
47 | with context("Traceback (most recent call last)"): | |
48 |
|
|
48 | ip.magic('cpaste') | |
49 |
|
49 | |||
50 | if not should_fail: |
|
50 | if not should_fail: | |
51 |
assert |
|
51 | assert ip.user_ns['code_ran'] | |
52 | finally: |
|
52 | finally: | |
53 | sys.stdin = stdin_save |
|
53 | sys.stdin = stdin_save | |
54 |
|
54 | |||
@@ -60,7 +60,7 b' def test_cpaste():' | |||||
60 | def runf(): |
|
60 | def runf(): | |
61 | """Marker function: sets a flag when executed. |
|
61 | """Marker function: sets a flag when executed. | |
62 | """ |
|
62 | """ | |
63 |
|
|
63 | ip.user_ns['code_ran'] = True | |
64 | return 'runf' # return string so '+ runf()' doesn't result in success |
|
64 | return 'runf' # return string so '+ runf()' doesn't result in success | |
65 |
|
65 | |||
66 | tests = {'pass': ["runf()", |
|
66 | tests = {'pass': ["runf()", | |
@@ -80,7 +80,7 b' def test_cpaste():' | |||||
80 | if not PY31: |
|
80 | if not PY31: | |
81 | tests['fail'].append("++ runf()") |
|
81 | tests['fail'].append("++ runf()") | |
82 |
|
82 | |||
83 |
|
|
83 | ip.user_ns['runf'] = runf | |
84 |
|
84 | |||
85 | for code in tests['pass']: |
|
85 | for code in tests['pass']: | |
86 | check_cpaste(code) |
|
86 | check_cpaste(code) |
General Comments 0
You need to be logged in to leave comments.
Login now