MCPcopy Create free account
hub / github.com/ipython/ipython / mock_input_helper

Class mock_input_helper

IPython/terminal/tests/test_interactivshell.py:61–88  ·  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

59# Decorator for interaction loop tests -----------------------------------------
60
61class mock_input_helper(object):
62 """Machinery for tests of the main interact loop.
63
64 Used by the mock_input decorator.
65 """
66 def __init__(self, testgen):
67 self.testgen = testgen
68 self.exception = None
69 self.ip = get_ipython()
70
71 def __enter__(self):
72 self.orig_prompt_for_code = self.ip.prompt_for_code
73 self.ip.prompt_for_code = self.fake_input
74 return self
75
76 def __exit__(self, etype, value, tb):
77 self.ip.prompt_for_code = self.orig_prompt_for_code
78
79 def fake_input(self):
80 try:
81 return next(self.testgen)
82 except StopIteration:
83 self.ip.keep_running = False
84 return u''
85 except:
86 self.exception = sys.exc_info()
87 self.ip.keep_running = False
88 return u''
89
90def mock_input(testfunc):
91 """Decorator for tests of the main interact loop.

Callers 1

test_methodFunction · 0.85

Calls

no outgoing calls

Tested by 1

test_methodFunction · 0.68