def test_python_run_script(): """ Ensure that running the script launches the process as expected. """ editor = mock.MagicMock() editor.envars = [["name", "value"]] view = mock.MagicMock() view.current_tab.path = "/foo/bar" view.current_tab.isModified.return_value = True view.current_tab.text = mock.MagicMock(return_value="abc") mock_runner = mock.MagicMock() view.add_python3_runner.return_value = mock_runner pm = PythonMode(editor, view) pm.run_script() editor.save_tab_to_file.assert_called_once_with(view.current_tab) view.add_python3_runner.assert_called_once_with("/foo/bar", "/foo", interactive=True, envars=editor.envars) mock_runner.process.waitForStarted.assert_called_once_with() # Check the buttons are set to the correct state when other aspects of the # mode are also in play. pm.set_buttons = mock.MagicMock() pm.kernel_runner = True pm.run_script() pm.set_buttons.assert_called_once_with(plotter=False) pm.set_buttons.reset_mock() pm.kernel_runner = False pm.plotter = True pm.run_script() pm.set_buttons.assert_called_once_with(repl=False)
def test_python_run_script(): """ Ensure that running the script launches the process as expected. """ editor = mock.MagicMock() editor.envars = [['name', 'value']] view = mock.MagicMock() view.current_tab.path = '/foo/bar' view.current_tab.isModified.return_value = True view.current_tab.text = mock.MagicMock(return_value="abc") mock_runner = mock.MagicMock() view.add_python3_runner.return_value = mock_runner pm = PythonMode(editor, view) pm.run_script() editor.save_tab_to_file.assert_called_once_with(view.current_tab) view.add_python3_runner.assert_called_once_with('/foo/bar', '/foo', interactive=True, envars=editor.envars) mock_runner.process.waitForStarted.assert_called_once_with() # Check the buttons are set to the correct state when other aspects of the # mode are also in play. pm.set_buttons = mock.MagicMock() pm.kernel_runner = True pm.run_script() pm.set_buttons.assert_called_once_with(plotter=False) pm.set_buttons.reset_mock() pm.kernel_runner = False pm.plotter = True pm.run_script() pm.set_buttons.assert_called_once_with(repl=False)
def test_python_on_data_flood(): """ Ensure that Python 3 mode cleans up correctly after a data flood of the plotter is detected: reset the buttons, stop either the REPL or runner and then call the base method. """ editor = mock.MagicMock() view = mock.MagicMock() pm = PythonMode(editor, view) pm.set_buttons = mock.MagicMock() pm.run_toggle = mock.MagicMock() pm.remove_repl = mock.MagicMock() pm.runner = True with mock.patch("builtins.super") as mock_super: pm.on_data_flood() pm.set_buttons.assert_called_once_with(run=True, repl=True, debug=True) pm.run_toggle.assert_called_once_with(None) mock_super().on_data_flood.assert_called_once_with() pm.set_buttons.reset_mock() pm.runner = False pm.kernel_runner = True with mock.patch("builtins.super") as mock_super: pm.on_data_flood() pm.set_buttons.assert_called_once_with(run=True, repl=True, debug=True) pm.remove_repl.assert_called_once_with() mock_super().on_data_flood.assert_called_once_with()
def test_python_on_data_flood(): """ Ensure that Python 3 mode cleans up correctly after a data flood of the plotter is detected: reset the buttons, stop either the REPL or runner and then call the base method. """ editor = mock.MagicMock() view = mock.MagicMock() pm = PythonMode(editor, view) pm.set_buttons = mock.MagicMock() pm.run_toggle = mock.MagicMock() pm.remove_repl = mock.MagicMock() pm.runner = True with mock.patch('builtins.super') as mock_super: pm.on_data_flood() pm.set_buttons.assert_called_once_with(run=True, repl=True, debug=True) pm.run_toggle.assert_called_once_with(None) mock_super().on_data_flood.assert_called_once_with() pm.set_buttons.reset_mock() pm.runner = False pm.kernel_runner = True with mock.patch('builtins.super') as mock_super: pm.on_data_flood() pm.set_buttons.assert_called_once_with(run=True, repl=True, debug=True) pm.remove_repl.assert_called_once_with() mock_super().on_data_flood.assert_called_once_with()
def test_python_toggle_repl(): """ Ensure the REPL handling works as expected. """ editor = mock.MagicMock() view = mock.MagicMock() pm = PythonMode(editor, view) pm.add_repl = mock.MagicMock() pm.remove_repl = mock.MagicMock() pm.toggle_repl(None) pm.add_repl.assert_called_once_with() pm.kernel_runner = True pm.toggle_repl(None) pm.remove_repl.assert_called_once_with()
def test_python_run_script(): """ Ensure that running the script launches the process as expected. """ editor = mock.MagicMock() editor.envars = [['name', 'value']] view = mock.MagicMock() view.current_tab.path = '/foo' view.current_tab.isModified.return_value = True mock_runner = mock.MagicMock() view.add_python3_runner.return_value = mock_runner pm = PythonMode(editor, view) pm.workspace_dir = mock.MagicMock(return_value='/bar') with mock.patch('builtins.open') as oa, \ mock.patch('mu.modes.python3.write_and_flush'): pm.run_script() oa.assert_called_once_with('/foo', 'w', newline='') view.add_python3_runner.assert_called_once_with('/foo', '/bar', interactive=True, envars=editor.envars) mock_runner.process.waitForStarted.assert_called_once_with() # Check the buttons are set to the correct state when other aspects of the # mode are also in play. pm.set_buttons = mock.MagicMock() pm.kernel_runner = True with mock.patch('builtins.open') as oa, \ mock.patch('mu.modes.python3.write_and_flush'): pm.run_script() pm.set_buttons.assert_called_once_with(plotter=False) pm.set_buttons.reset_mock() pm.kernel_runner = False pm.plotter = True with mock.patch('builtins.open') as oa, \ mock.patch('mu.modes.python3.write_and_flush'): pm.run_script() pm.set_buttons.assert_called_once_with(repl=False)