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

Function fake_input

IPython/testing/tools.py:431–449  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

429 os.unlink(name)
430
431def 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
451def help_output_test(subcommand=''):
452 """test that `ipython [subcommand] -h` works"""

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected