##// END OF EJS Templates
%cpaste: strip whitespace before >>> in regex to allow pasting doctests
vivainio2 -
Show More

The requested changes are too big and content was truncated. Show full diff

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