Test cpaste magic
()
| 66 | |
| 67 | |
| 68 | def test_cpaste(): |
| 69 | """Test cpaste magic""" |
| 70 | |
| 71 | def runf(): |
| 72 | """Marker function: sets a flag when executed.""" |
| 73 | ip.user_ns["code_ran"] = True |
| 74 | return "runf" # return string so '+ runf()' doesn't result in success |
| 75 | |
| 76 | tests = { |
| 77 | "pass": [ |
| 78 | "runf()", |
| 79 | "In [1]: runf()", |
| 80 | "In [1]: if 1:\n ...: runf()", |
| 81 | "> > > runf()", |
| 82 | ">>> runf()", |
| 83 | " >>> runf()", |
| 84 | ], |
| 85 | "fail": [ |
| 86 | "1 + runf()", |
| 87 | "++ runf()", |
| 88 | ], |
| 89 | } |
| 90 | |
| 91 | ip.user_ns["runf"] = runf |
| 92 | |
| 93 | for code in tests["pass"]: |
| 94 | check_cpaste(code) |
| 95 | |
| 96 | for code in tests["fail"]: |
| 97 | check_cpaste(code, should_fail=True) |
| 98 | |
| 99 | |
| 100 | class PasteTestCase(TestCase): |
nothing calls this directly
no test coverage detected
searching dependent graphs…