Machinery for tests of the main interact loop. Used by the mock_input decorator.
| 104 | |
| 105 | |
| 106 | class mock_input_helper(object): |
| 107 | """Machinery for tests of the main interact loop. |
| 108 | |
| 109 | Used by the mock_input decorator. |
| 110 | """ |
| 111 | |
| 112 | def __init__(self, testgen): |
| 113 | self.testgen = testgen |
| 114 | self.exception = None |
| 115 | self.ip = get_ipython() |
| 116 | |
| 117 | def __enter__(self): |
| 118 | self.orig_prompt_for_code = self.ip.prompt_for_code |
| 119 | self.ip.prompt_for_code = self.fake_input |
| 120 | return self |
| 121 | |
| 122 | def __exit__(self, etype, value, tb): |
| 123 | self.ip.prompt_for_code = self.orig_prompt_for_code |
| 124 | |
| 125 | def fake_input(self): |
| 126 | try: |
| 127 | return next(self.testgen) |
| 128 | except StopIteration: |
| 129 | self.ip.keep_running = False |
| 130 | return "" |
| 131 | except: |
| 132 | self.exception = sys.exc_info() |
| 133 | self.ip.keep_running = False |
| 134 | return "" |
| 135 | |
| 136 | |
| 137 | def mock_input(testfunc): |
no outgoing calls
searching dependent graphs…