MCPcopy Index your code
hub / github.com/ipython/ipython / mock_input_helper

Class mock_input_helper

tests/test_interactivshell.py:106–134  ·  view source on GitHub ↗

Machinery for tests of the main interact loop. Used by the mock_input decorator.

Source from the content-addressed store, hash-verified

104
105
106class 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
137def mock_input(testfunc):

Callers 1

test_methodFunction · 0.85

Calls

no outgoing calls

Tested by 1

test_methodFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…