Skip to content

Commit

Permalink
IPython console: Update cwd for first consoles
Browse files Browse the repository at this point in the history
- Those are created not only when Spyder is started but also when
opening/closing projects.
- Expand tests to check that cwd is synced when opening/closing
projects.
  • Loading branch information
ccordoba12 committed Aug 17, 2022
1 parent 9035b4e commit 5de8c91
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
25 changes: 24 additions & 1 deletion spyder/app/tests/test_mainwindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -5482,7 +5482,7 @@ def test_console_initial_cwd_is_synced(main_window, qtbot, tmpdir):
assert shell.get_cwd() == str(tmpdir) == workdir.get_workdir() == \
files.get_current_folder()

# Check that new clients with a fixed directory
# Check new clients with a fixed directory
ipyconsole.set_conf('console/use_cwd', False, section='workingdir')
ipyconsole.set_conf(
'console/use_fixed_directory',
Expand All @@ -5505,6 +5505,29 @@ def test_console_initial_cwd_is_synced(main_window, qtbot, tmpdir):
assert shell.get_cwd() == fixed_dir == workdir.get_workdir() == \
files.get_current_folder()

# Check when opening projects
project_path = str(tmpdir.mkdir('test_project'))
main_window.projects.open_project(path=project_path)
qtbot.wait(500)

shell = ipyconsole.get_current_shellwidget()
qtbot.waitUntil(lambda: shell._prompt_html is not None,
timeout=SHELL_TIMEOUT)
qtbot.wait(500)
assert shell.get_cwd() == project_path == workdir.get_workdir() == \
files.get_current_folder()

# Check when closing projects
main_window.projects.close_project()
qtbot.wait(500)

shell = ipyconsole.get_current_shellwidget()
qtbot.waitUntil(lambda: shell._prompt_html is not None,
timeout=SHELL_TIMEOUT)
qtbot.wait(500)
assert shell.get_cwd() == get_home_dir() == workdir.get_workdir() == \
files.get_current_folder()


if __name__ == "__main__":
pytest.main()
1 change: 0 additions & 1 deletion spyder/plugins/ipythonconsole/widgets/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,6 @@ def _set_initial_cwd_in_kernel(self):
cwd_path = get_home_dir()
if project_path is not None:
cwd_path = project_path
update_in_spyder = False
elif self.get_conf(
'startup/use_fixed_directory',
section='workingdir'
Expand Down

0 comments on commit 5de8c91

Please sign in to comment.