Test cpaste magic
()
| 47 | sys.stdin = stdin_save |
| 48 | |
| 49 | def test_cpaste(): |
| 50 | """Test cpaste magic""" |
| 51 | |
| 52 | def runf(): |
| 53 | """Marker function: sets a flag when executed. |
| 54 | """ |
| 55 | ip.user_ns['code_ran'] = True |
| 56 | return 'runf' # return string so '+ runf()' doesn't result in success |
| 57 | |
| 58 | tests = {'pass': ["runf()", |
| 59 | "In [1]: runf()", |
| 60 | "In [1]: if 1:\n ...: runf()", |
| 61 | "> > > runf()", |
| 62 | ">>> runf()", |
| 63 | " >>> runf()", |
| 64 | ], |
| 65 | |
| 66 | 'fail': ["1 + runf()", |
| 67 | "++ runf()", |
| 68 | ]} |
| 69 | |
| 70 | ip.user_ns['runf'] = runf |
| 71 | |
| 72 | for code in tests['pass']: |
| 73 | check_cpaste(code) |
| 74 | |
| 75 | for code in tests['fail']: |
| 76 | check_cpaste(code, should_fail=True) |
| 77 | |
| 78 | |
| 79 | class PasteTestCase(TestCase): |
nothing calls this directly
no test coverage detected