1
"""Test cpaste magic"""
3
tests = {'pass': ["> > > run()",
12
from StringIO import StringIO
15
stdin_save = sys.stdin
17
# NOTE: no blank lines allowed in function definition
18
def testcase(code,should_fail=False):
19
"""Execute code via 'cpaste' and ensure it was executed, unless
23
_ip.user_ns['code_ran'] = False
37
raise AssertionError("Failure not expected : '%s'" %
42
raise AssertionError("Failure expected : '%s'" % code)
45
sys.stdin = stdin_save
49
"""Marker function: sets a flag when executed.
52
_ip.user_ns['code_ran'] = True
53
return 'run' # return string so '+ run()' doesn't result in success
56
### Actual testing happens here
58
for code in tests['pass']:
61
for code in tests['fail']:
62
testcase(code,should_fail=True)