Given a list of inputs, run an interactive help session. Returns a string of what would be shown on screen.
(self, inputs)
| 2150 | |
| 2151 | class 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), |
no test coverage detected