Esempio n. 1
0
        def worker(inputs, result_container):
            def mock_stdin_provider():
                if not inputs:
                    return None

                val = inputs.pop(0)
                if val == 'interrupt':
                    raise KeyboardInterrupt
                return val

            mock_stdin_widget, echo_updater_calls = create_mock_stdin_widget()
            with \
              mock.patch.object(
                  _message,
                  '_read_stdin_message',
                  side_effect=mock_stdin_provider,
                  autospec=True), \
              mock.patch.object(
                  _system_commands,
                  '_display_stdin_widget',
                  mock_stdin_widget):
                _system_commands._register_magics(self.ip)

                with io.capture_output() as captured:
                    with mock.patch.object(
                            captured._stdout,
                            'flush',
                            wraps=captured._stdout.flush) as stdout_flushes:
                        self.ip.run_cell(cell_contents)

                run_cell_result = RunCellResult(captured, echo_updater_calls,
                                                stdout_flushes.call_count)
                result_container['run_cell_result'] = run_cell_result
        def worker(inputs, result_container):
            def mock_stdin_provider():
                if not inputs:
                    return None

                val = inputs.pop(0)
                if val == 'interrupt':
                    raise KeyboardInterrupt
                return val

            mock_stdin_widget, echo_updater_calls = create_mock_stdin_widget()
            with \
              mock.patch.object(
                  _message,
                  '_read_stdin_message',
                  side_effect=mock_stdin_provider,
                  autospec=True), \
              mock.patch.object(
                  _system_commands,
                  '_display_stdin_widget',
                  mock_stdin_widget):
                _system_commands._register_magics(self.ip)

                with io.capture_output() as captured:
                    self.ip.run_cell(cell_contents)

                result_container.update({
                    'output':
                    captured,
                    'echo_updater_calls':
                    echo_updater_calls,
                })
Esempio n. 3
0
def load_ipython_extension(ipython):
  """Called by IPython when this module is loaded as an IPython extension."""
  _shell_customizations.initialize()
  _system_commands._register_magics(ipython)  # pylint:disable=protected-access
  _installation_commands._register_magics(ipython)  # pylint:disable=protected-access
  _import_hooks._register_hooks()  # pylint:disable=protected-access
  _tensorflow_magics._register_magics(ipython)  # pylint:disable=protected-access