apache_beam.runners.interactive.testing.mock_ipython module

apache_beam.runners.interactive.testing.mock_ipython.mock_get_ipython()[source]

Mock an ipython environment w/o setting up real ipython kernel.

Each entering of get_ipython() invocation will have the prompt increased by one. Grouping arbitrary python code into separate cells using with clause.

Examples:

# Usage, before each test function, prepend:
@patch('IPython.get_ipython', new_callable=mock_get_ipython)

# In the test function's signature, add an argument for the patch, e.g.:
def some_test(self, cell):

# Group lines of code into a cell using the argument:
with cell:
  # arbitrary python code
  # ...
  # arbitrary python code

# Next cell with prompt increased by one:
with cell:  # Auto-incremental
  # arbitrary python code
  # ...
  # arbitrary python code