##// END OF EJS Templates
Temporary fix to get setup.py to not crash. Full fix on the way.
Temporary fix to get setup.py to not crash. Full fix on the way.

File last commit:

r1201:05d203a8
r1271:5b9f261c
Show More
test_cpaste.ipy
62 lines | 1.3 KiB | text/plain | TextLexer
Ville M. Vainio
%cpaste enhancement (accept '> > > as prefix), patch + test by Stefan, close #216
r1001 """Test cpaste magic"""
tests = {'pass': ["> > > run()",
">>> > run()",
"+++ run()",
vivainio2
%cpaste: strip whitespace before >>> in regex to allow pasting doctests
r1201 "++ run()",
" >>> run()"],
Ville M. Vainio
%cpaste enhancement (accept '> > > as prefix), patch + test by Stefan, close #216
r1001
'fail': ["+ + run()",
" ++ run()"]}
from StringIO import StringIO
import sys
stdin_save = sys.stdin
# NOTE: no blank lines allowed in function definition
def testcase(code,should_fail=False):
"""Execute code via 'cpaste' and ensure it was executed, unless
should_fail is set.
"""
_ip.user_ns['code_ran'] = False
#
src = StringIO()
src.write('\n')
src.write(code)
src.write('\n--\n')
src.seek(0)
#
sys.stdin = src
try:
cpaste
except:
if not should_fail:
raise AssertionError("Failure not expected : '%s'" %
code)
else:
assert code_ran
if should_fail:
raise AssertionError("Failure expected : '%s'" % code)
#
finally:
sys.stdin = stdin_save
#
def run():
"""Marker function: sets a flag when executed.
"""
_ip.user_ns['code_ran'] = True
return 'run' # return string so '+ run()' doesn't result in success
### Actual testing happens here
for code in tests['pass']:
testcase(code)
for code in tests['fail']:
testcase(code,should_fail=True)