def test_start_server_no_tab(): """ If there's no tab, the resver isn't started. """ editor = mock.MagicMock() view = mock.MagicMock() view.current_tab = None wm = WebMode(editor, view) wm.stop_server = mock.MagicMock() wm.start_server() wm.stop_server.assert_called_once_with() assert view.add_python3_runner.call_count == 0
def test_start_server(): """ The server is started and stored as the runner associated with the mode. """ editor = mock.MagicMock() view = mock.MagicMock() view.current_tab.path = "foo.py" view.current_tab.isModified.return_value = True wm = WebMode(editor, view) wm.stop_server = mock.MagicMock() wm.start_server() assert view.add_python3_runner.call_count == 1 view.add_python3_runner().process.waitForStarted.assert_called_once_with()
def test_start_server_unsaved_tab(): """ If there's a tab, but no associated path, then call the save method on the editor to get one. If none is returned no further action is taken. """ editor = mock.MagicMock() editor.save.return_value = None view = mock.MagicMock() view.current_tab.path = None wm = WebMode(editor, view) wm.start_server() assert editor.save.call_count == 1 assert view.add_python3_runner.call_count == 0
def test_start_server_not_python_file(): """ If the user attempts to start the server from not-a-Python-file, then complain and abort. """ editor = mock.MagicMock() view = mock.MagicMock() view.current_tab.path = "foo.html" wm = WebMode(editor, view) wm.stop_server = mock.MagicMock() wm.start_server() assert view.show_message.call_count == 1 wm.stop_server.assert_called_once_with() assert view.add_python3_runner.call_count == 0
def test_start_server_no_templates(): """ If the user attempts to start the server from a location without a templates directory, then complain and abort. """ editor = mock.MagicMock() view = mock.MagicMock() view.current_tab.path = "foo.py" wm = WebMode(editor, view) wm.stop_server = mock.MagicMock() with mock.patch("os.path.isdir", return_value=False): wm.start_server() assert view.show_message.call_count == 1 wm.stop_server.assert_called_once_with() assert view.add_python3_runner.call_count == 0
def test_start_server_no_duplicate_envars(): """ Check that we don't add repeated envars to the Python3 Environment. """ editor = mock.MagicMock() editor.envars = {} view = mock.MagicMock() view.current_tab.path = "foo.py" view.current_tab.isModified.return_value = True wm = WebMode(editor, view) wm.stop_server = mock.MagicMock() with mock.patch("os.path.isdir", return_value=True): wm.start_server() assert len(editor.envars) == 4 with mock.patch("os.path.isdir", return_value=True): wm.start_server() assert len(editor.envars) == 4
def test_run_toggle_on(): """ Check the handler for running the local server starts the sub-process and updates the UI state. """ editor = mock.MagicMock() view = mock.MagicMock() wm = WebMode(editor, view) wm.runner = None def runner(wm=wm): wm.runner = True wm.start_server = mock.MagicMock(side_effect=runner) wm.set_buttons = mock.MagicMock() wm.run_toggle(None) wm.start_server.assert_called_once_with() slot = wm.view.button_bar.slots["run"] assert slot.setIcon.call_count == 1 slot.setText.assert_called_once_with("Stop") slot.setToolTip.assert_called_once_with("Stop the web server.") wm.set_buttons.assert_called_once_with(modes=False)