Skip to content

Commit 1a36bc2

Browse files
committed
Fix test_open_console_when_no_kernel and move to test_main_widget.py
* The test that no console was opened did not work because this can be done asynchronously, so instead test for the signal requesting that the console be opened. * The test now only needs the main widget, not the plugin, so move it accordingly.
1 parent 9f42b4a commit 1a36bc2

File tree

2 files changed

+28
-29
lines changed

2 files changed

+28
-29
lines changed

spyder_notebook/tests/test_plugin.py

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -119,35 +119,6 @@ def fake_get_server(filename, interpreter, start):
119119
# =============================================================================
120120
# Tests
121121
# =============================================================================
122-
# Teardown sometimes fails on Mac with Python 3.8 due to NoProcessException
123-
# in shutdown_server() in notebookapp.py in external notebook library
124-
@flaky
125-
def test_open_console_when_no_kernel(notebook, qtbot, mocker):
126-
"""Test that open_console() handles the case when there is no kernel."""
127-
# Create mock IPython console plugin and QMessageBox
128-
MockMessageBox = mocker.patch(
129-
'spyder_notebook.widgets.main_widget.QMessageBox')
130-
131-
# Wait for prompt
132-
nbwidget = notebook.get_widget().tabwidget.currentWidget().notebookwidget
133-
qtbot.waitUntil(lambda: prompt_present(nbwidget, qtbot),
134-
timeout=NOTEBOOK_UP)
135-
136-
# Shut the kernel down and check that this is successful
137-
client = notebook.get_widget().tabwidget.currentWidget()
138-
kernel_id = client.get_kernel_id()
139-
sessions_url = client.get_session_url()
140-
client.shutdown_kernel()
141-
assert not is_kernel_up(kernel_id, sessions_url)
142-
143-
# Try opening a console
144-
notebook.get_widget().open_console(client)
145-
146-
# Assert that a dialog is displayed and no console was opened
147-
MockMessageBox.critical.assert_called()
148-
ipyconsole = notebook.get_plugin(Plugins.IPythonConsole)
149-
ipyconsole._create_client_for_kernel.assert_not_called()
150-
151122

152123
def test_on_mainwindow_visible_with_opened_notebooks(plugin_no_server):
153124
"""

spyder_notebook/widgets/tests/test_main_widget.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,34 @@ def test_shutdown_notebook_kernel(main_widget, qtbot):
205205
assert not is_kernel_up(kernel_id, sessions_url)
206206

207207

208+
@flaky
209+
def test_open_console_when_no_kernel(main_widget, qtbot, mocker):
210+
"""Test that open_console() handles the case when there is no kernel."""
211+
# Create mock QMessageBox
212+
MockMessageBox = mocker.patch(
213+
'spyder_notebook.widgets.main_widget.QMessageBox')
214+
215+
# Create new notebook tab and wait for prompt
216+
main_widget.create_new_client()
217+
client = main_widget.tabwidget.currentWidget()
218+
nbwidget = client.notebookwidget
219+
qtbot.waitUntil(lambda: prompt_present(nbwidget, qtbot),
220+
timeout=NOTEBOOK_UP)
221+
222+
# Shut the kernel down and check that this is successful
223+
kernel_id = client.get_kernel_id()
224+
sessions_url = client.get_session_url()
225+
client.shutdown_kernel()
226+
assert not is_kernel_up(kernel_id, sessions_url)
227+
228+
# Try opening a console and check corresponding signal is not emitted
229+
with qtbot.assertNotEmitted(main_widget.sig_open_console_requested):
230+
main_widget.open_console(client)
231+
232+
# Assert that a dialog is displayed and no console was opened
233+
MockMessageBox.critical.assert_called()
234+
235+
208236
def test_file_in_temp_dir_deleted_after_notebook_closed(main_widget, qtbot):
209237
"""Test that notebook file in temporary directory is deleted after the
210238
notebook is closed."""

0 commit comments

Comments
 (0)