MCPcopy Index your code
hub / github.com/python/cpython / mock_interactive_session

Method mock_interactive_session

Lib/test/test_pydoc/test_pydoc.py:2152–2171  ·  view source on GitHub ↗

Given a list of inputs, run an interactive help session. Returns a string of what would be shown on screen.

(self, inputs)

Source from the content-addressed store, hash-verified

2150
2151class TestHelper(unittest.TestCase):
2152 def mock_interactive_session(self, inputs):
2153 """
2154 Given a list of inputs, run an interactive help session. Returns a string
2155 of what would be shown on screen.
2156 """
2157 input_iter = iter(inputs)
2158
2159 def mock_getline(prompt):
2160 output.write(prompt)
2161 next_input = next(input_iter)
2162 output.write(next_input + os.linesep)
2163 return next_input
2164
2165 with captured_stdout() as output:
2166 helper = pydoc.Helper(output=output)
2167 with unittest.mock.patch.object(helper, "getline", mock_getline):
2168 helper.interact()
2169
2170 # handle different line endings across platforms consistently
2171 return output.getvalue().strip().splitlines(keepends=False)
2172
2173 def test_keywords(self):
2174 self.assertEqual(sorted(pydoc.Helper.keywords),

Calls 5

interactMethod · 0.95
captured_stdoutFunction · 0.90
splitlinesMethod · 0.45
stripMethod · 0.45
getvalueMethod · 0.45

Tested by

no test coverage detected