Skip to content

Commit

Permalink
Testing: Check we can use custom run configs for multiple executors
Browse files Browse the repository at this point in the history
  • Loading branch information
ccordoba12 committed Jan 28, 2025
1 parent 33db20c commit 9e3fea6
Showing 1 changed file with 117 additions and 3 deletions.
120 changes: 117 additions & 3 deletions spyder/app/tests/test_mainwindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,13 @@
from qtpy import PYQT_VERSION, PYQT5
from qtpy.QtCore import QPoint, Qt, QTimer, QUrl
from qtpy.QtGui import QImage, QTextCursor
from qtpy.QtWidgets import QAction, QApplication, QInputDialog, QWidget
from qtpy.QtWidgets import (
QAction,
QApplication,
QDialogButtonBox,
QInputDialog,
QWidget,
)
from qtpy.QtWebEngineWidgets import WEBENGINE
from spyder_kernels.utils.pythonenv import is_conda_env

Expand Down Expand Up @@ -81,8 +87,13 @@
from spyder.plugins.layout.layouts import DefaultLayouts
from spyder.plugins.toolbar.api import ApplicationToolbars
from spyder.plugins.run.api import (
RunExecutionParameters, ExtendedRunExecutionParameters, WorkingDirOpts,
WorkingDirSource, RunContext)
ExtendedRunExecutionParameters,
RunActions,
RunContext,
RunExecutionParameters,
WorkingDirOpts,
WorkingDirSource,
)
from spyder.plugins.shortcuts.widgets.table import SEQUENCE
from spyder.py3compat import qbytearray_to_str, to_text_string
from spyder.utils.environ import set_user_env
Expand Down Expand Up @@ -7109,5 +7120,108 @@ def test_editor_window_outline_and_toolbars(main_window, qtbot):
debug_toolbar_action.trigger()


@flaky(max_runs=3)
def test_custom_run_config_for_multiple_executors(
main_window, qtbot, tmp_path
):
"""
Check that we correctly use custom run configurations for multiple
executors.
This is a regression test for issue spyder-ide/spyder#22496
"""
# Auxiliary function
def change_run_options(
executor: str, change_cwd: bool, dedicated_console: bool
):
# Select executor
dialog = main_window.run.get_container().dialog
dialog.select_executor(executor)

# Use a fixed path for cwd
if change_cwd:
dialog.fixed_dir_radio.setChecked(True)
dialog.wd_edit.setText(str(tmp_path))

if dedicated_console:
dialog.current_widget.dedicated_radio.setChecked(True)

# Accept changes
ok_btn = dialog.bbox.button(QDialogButtonBox.Ok)
ok_btn.animateClick()

# Wait for a bit until changes are saved to disk
qtbot.wait(500)

# Wait until the window is fully up
shell = main_window.ipyconsole.get_current_shellwidget()
control = shell._control
qtbot.waitUntil(
lambda: shell.spyder_kernel_ready and shell._prompt_html is not None,
timeout=SHELL_TIMEOUT
)

# Open test file
main_window.editor.load(osp.join(LOCATION, 'script.py'))

# Configure debugger with custom options
run_config_action = main_window.run.get_action(RunActions.Configure)
run_config_action.trigger()
change_run_options(
executor=Plugins.Debugger,
change_cwd=True,
dedicated_console=False,
)

# Run test file
run_action = main_window.run.get_action(RunActions.Run)
with qtbot.waitSignal(shell.executed):
run_action.trigger()

# Check we used the default executor, i.e. we ran the file instead of
# debugging it (the run config per file dialog must be used for
# configuration only, not to decide what plugin gets associated to the
# Run file, cell, selection actions).
assert "runfile" in control.toPlainText()

# Check we didn't change the cwd
assert str(tmp_path) not in control.toPlainText()

# Configure IPython console with custom options
run_config_action.trigger()
change_run_options(
executor=Plugins.IPythonConsole,
change_cwd=False,
dedicated_console=True,
)

# Debug file
debug_action = main_window.run.get_action(
"run file in debugger"
)
with qtbot.waitSignal(shell.executed):
debug_action.trigger()

# Check debugging happened in the same console and not in a new one
assert (
"debugfile" in control.toPlainText()
and "runfile" in control.toPlainText()
)

# Check we used the selected cwd for debugging
assert str(tmp_path) in control.toPlainText()

# Run file again
run_action.trigger()

# Check a new console was created
ipyconsole_widget = main_window.ipyconsole.get_widget()
qtbot.waitUntil(lambda: len(ipyconsole_widget.clients) == 2)

# Check it's a dedicated console for the file we're running
client = main_window.ipyconsole.get_current_client()
assert "script.py" in client.get_name()


if __name__ == "__main__":
pytest.main()

0 comments on commit 9e3fea6

Please sign in to comment.