Temporarily replace the input() function to return the given values Use as a context manager: with fake_input(['result1', 'result2']): ... Values are returned in order. If input() is called again after the last value was used, EOFError is raised.
(inputs)
| 429 | os.unlink(name) |
| 430 | |
| 431 | def fake_input(inputs): |
| 432 | """Temporarily replace the input() function to return the given values |
| 433 | |
| 434 | Use as a context manager: |
| 435 | |
| 436 | with fake_input(['result1', 'result2']): |
| 437 | ... |
| 438 | |
| 439 | Values are returned in order. If input() is called again after the last value |
| 440 | was used, EOFError is raised. |
| 441 | """ |
| 442 | it = iter(inputs) |
| 443 | def mock_input(prompt=''): |
| 444 | try: |
| 445 | return next(it) |
| 446 | except StopIteration: |
| 447 | raise EOFError('No more inputs given') |
| 448 | |
| 449 | return patch('builtins.input', mock_input) |
| 450 | |
| 451 | def help_output_test(subcommand=''): |
| 452 | """test that `ipython [subcommand] -h` works""" |
nothing calls this directly
no outgoing calls
no test coverage detected