Skip to content

Commit

Permalink
Merge pull request #20762 from impact27/add_test
Browse files Browse the repository at this point in the history
PR: Enable running renamed and IPython files again
  • Loading branch information
ccordoba12 authored Jun 25, 2023
2 parents 2507709 + 33568c3 commit f8e5290
Show file tree
Hide file tree
Showing 15 changed files with 269 additions and 143 deletions.
4 changes: 2 additions & 2 deletions spyder/app/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,8 @@ def generate_run_parameters(mainwindow, filename, selected=None,
file_run_params = StoredRunConfigurationExecutor(
executor=executor,
selected=selected,
display_dialog=False,
first_execution=False)
display_dialog=False
)

return {file_uuid: file_run_params}

Expand Down
89 changes: 88 additions & 1 deletion spyder/app/tests/test_mainwindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
WorkingDirSource, RunContext)
from spyder.py3compat import qbytearray_to_str, to_text_string
from spyder.utils.environ import set_user_env
from spyder.utils.misc import remove_backslashes
from spyder.utils.misc import remove_backslashes, rename_file
from spyder.utils.clipboard_helper import CLIPBOARD_HELPER
from spyder.utils.programs import find_program
from spyder.widgets.dock import DockTitleBar
Expand Down Expand Up @@ -6364,5 +6364,92 @@ def test_runfile_namespace(main_window, qtbot, tmpdir):
assert "test_globals True" in control.toPlainText()


@pytest.mark.skipif(
os.name == 'nt',
reason="No quotes on Windows file paths"
)
def test_quotes_rename_ipy(main_window, qtbot, tmpdir):
"""
Test that we can run files with quotes in name, renamed files,
and ipy files.
"""
# create a file with a funky name
path = "a'b\"c\\.py"
file = tmpdir.join(path)
file.write("print(23 + 780)")
path = to_text_string(file)
main_window.editor.load(path)

# Run file
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)

with qtbot.waitSignal(shell.executed):
qtbot.mouseClick(main_window.run_button, Qt.LeftButton)

assert "803" in control.toPlainText()
assert "error" not in control.toPlainText()

code_editor = main_window.editor.get_focus_widget()
code_editor.set_text("print(22 + 780)")

with qtbot.waitSignal(shell.executed):
qtbot.mouseClick(main_window.run_cell_button, Qt.LeftButton)

assert "802" in control.toPlainText()
assert "error" not in control.toPlainText()

# Make sure this works with ipy and renamed files too

# Rename the file to IPython and emit the signal for that
rename_file(path, path[:-2] + "ipy")
explorer = main_window.get_plugin(Plugins.Explorer)
explorer.sig_file_renamed.emit(path, path[:-2] + "ipy")

code_editor.set_text("print(21 + 780)")

with qtbot.waitSignal(shell.executed):
qtbot.mouseClick(main_window.run_button, Qt.LeftButton)

assert "801" in control.toPlainText()
assert "error" not in control.toPlainText()
assert "\\.ipy" in control.toPlainText()

# Create an untitled file
main_window.editor.new()

assert "untitled" in main_window.editor.get_current_filename()

code_editor = main_window.editor.get_focus_widget()
code_editor.set_text("print(20 + 780)")

with qtbot.waitSignal(shell.executed):
qtbot.mouseClick(main_window.run_cell_button, Qt.LeftButton)

assert "800" in control.toPlainText()
assert "error" not in control.toPlainText()
assert "untitled" in control.toPlainText()

# Save file in a new folder
code_editor.set_text("print(19 + 780)")

with tempfile.TemporaryDirectory() as td:

editorstack = main_window.editor.get_current_editorstack()
editorstack.select_savename = lambda fn: os.path.join(td, "fn.ipy")
main_window.editor.save()
with qtbot.waitSignal(shell.executed):
qtbot.mouseClick(main_window.run_cell_button, Qt.LeftButton)

assert "799" in control.toPlainText()
assert "error" not in control.toPlainText()
assert "fn.ipy" in control.toPlainText()
main_window.editor.close_file()



if __name__ == "__main__":
pytest.main()
8 changes: 4 additions & 4 deletions spyder/plugins/debugger/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def on_initialize(self):

self.python_editor_run_configuration = {
'origin': self.NAME,
'extension': 'py',
'extension': ['py', 'ipy'],
'contexts': [
{
'name': 'File'
Expand All @@ -92,7 +92,7 @@ def on_initialize(self):

self.executor_configuration = [
{
'input_extension': 'py',
'input_extension': ['py', 'ipy'],
'context': {
'name': 'File'
},
Expand All @@ -102,7 +102,7 @@ def on_initialize(self):
'priority': 10
},
{
'input_extension': 'py',
'input_extension': ['py', 'ipy'],
'context': {
'name': 'Cell'
},
Expand All @@ -112,7 +112,7 @@ def on_initialize(self):
'priority': 10
},
{
'input_extension': 'py',
'input_extension': ['py', 'ipy'],
'context': {
'name': 'Selection'
},
Expand Down
Loading

0 comments on commit f8e5290

Please sign in to comment.