##// END OF EJS Templates
Fixed unused %cpaste test and moved into proper test suite.
Fernando Perez -
Show More
@@ -299,3 +299,59 b' def test_dirops():'
299 nt.assert_equal(curpath(), startdir)
299 nt.assert_equal(curpath(), startdir)
300 finally:
300 finally:
301 os.chdir(startdir)
301 os.chdir(startdir)
302
303
304 def check_cpaste(code, should_fail=False):
305 """Execute code via 'cpaste' and ensure it was executed, unless
306 should_fail is set.
307 """
308 _ip.user_ns['code_ran'] = False
309
310 src = StringIO()
311 src.write('\n')
312 src.write(code)
313 src.write('\n--\n')
314 src.seek(0)
315
316 stdin_save = sys.stdin
317 sys.stdin = src
318
319 try:
320 _ip.magic('cpaste')
321 except:
322 if not should_fail:
323 raise AssertionError("Failure not expected : '%s'" %
324 code)
325 else:
326 assert _ip.user_ns['code_ran']
327 if should_fail:
328 raise AssertionError("Failure expected : '%s'" % code)
329 finally:
330 sys.stdin = stdin_save
331
332
333 def test_cpaste():
334 """Test cpaste magic"""
335
336 def run():
337 """Marker function: sets a flag when executed.
338 """
339 _ip.user_ns['code_ran'] = True
340 return 'run' # return string so '+ run()' doesn't result in success
341
342 tests = {'pass': ["> > > run()",
343 ">>> > run()",
344 "+++ run()",
345 "++ run()",
346 " >>> run()"],
347
348 'fail': ["+ + run()",
349 " ++ run()"]}
350
351 _ip.user_ns['run'] = run
352
353 for code in tests['pass']:
354 check_cpaste(code)
355
356 for code in tests['fail']:
357 check_cpaste(code, should_fail=True)
1 NO CONTENT: file was removed
NO CONTENT: file was removed
General Comments 0
You need to be logged in to leave comments. Login now