From 8a82ca6f2ba1aae2bf2c3b6a2db0cf45f298d692 Mon Sep 17 00:00:00 2001 From: Rafael Laverde Date: Thu, 27 Jul 2017 09:55:19 -0500 Subject: [PATCH 01/14] Fix error with non-assci directories. --- spyder/plugins/workingdirectory.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spyder/plugins/workingdirectory.py b/spyder/plugins/workingdirectory.py index c2d7ea99a50..0f21c109da3 100644 --- a/spyder/plugins/workingdirectory.py +++ b/spyder/plugins/workingdirectory.py @@ -283,7 +283,7 @@ def chdir(self, directory, browsing_history=False, self.histindex = len(self.history)-1 # Changing working directory - os.chdir( to_text_string(directory) ) + os.chdir(encoding.to_unicode_from_fs(directory)) self.refresh_plugin() if refresh_explorer: self.set_explorer_cwd.emit(directory) From 577dc3c05f9363f2d492c617c0f5d3b57ec76d21 Mon Sep 17 00:00:00 2001 From: Rafael Laverde Date: Thu, 27 Jul 2017 09:56:51 -0500 Subject: [PATCH 02/14] Parametrize test_change_cwd_ipython_console to test with non ascii directory. --- spyder/app/tests/test_mainwindow.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/spyder/app/tests/test_mainwindow.py b/spyder/app/tests/test_mainwindow.py index 38571f44cd5..acfcae2c26f 100644 --- a/spyder/app/tests/test_mainwindow.py +++ b/spyder/app/tests/test_mainwindow.py @@ -345,8 +345,9 @@ def test_change_types_in_varexp(main_window, qtbot): assert shell.get_value('a') == 10 +@pytest.mark.parametrize("test_directory", ["test_dir", "non_ascii_ñ_í_ç"]) @flaky(max_runs=3) -def test_change_cwd_ipython_console(main_window, qtbot, tmpdir): +def test_change_cwd_ipython_console(main_window, qtbot, tmpdir, test_directory): """ Test synchronization with working directory and File Explorer when changing cwd in the IPython console. @@ -356,7 +357,7 @@ def test_change_cwd_ipython_console(main_window, qtbot, tmpdir): qtbot.waitUntil(lambda: shell._prompt_html is not None, timeout=SHELL_TIMEOUT) # Change directory in ipython console using %cd - temp_dir = str(tmpdir.mkdir("test_dir")) + temp_dir = str(tmpdir.mkdir(test_directory)) with qtbot.waitSignal(shell.executed): shell.execute("%cd {}".format(temp_dir)) qtbot.wait(1000) From f439539442e3475c1778018fa9a65b99f967e212 Mon Sep 17 00:00:00 2001 From: Carlos Cordoba Date: Thu, 27 Jul 2017 23:00:42 -0500 Subject: [PATCH 03/14] Use to_unicode_from_fs and to_fs_from_unicode in the right places --- spyder/plugins/workingdirectory.py | 12 ++++++++---- spyder/widgets/ipythonconsole/shell.py | 5 ++++- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/spyder/plugins/workingdirectory.py b/spyder/plugins/workingdirectory.py index 0f21c109da3..4a10463cbf7 100644 --- a/spyder/plugins/workingdirectory.py +++ b/spyder/plugins/workingdirectory.py @@ -26,7 +26,7 @@ from spyder.config.base import _, get_conf_path, get_home_dir from spyder.plugins import SpyderPluginMixin from spyder.plugins.configdialog import PluginConfigPage -from spyder.py3compat import to_text_string, getcwd +from spyder.py3compat import PY2, to_text_string, getcwd from spyder.utils import encoding from spyder.utils import icon_manager as ima from spyder.utils.qthelpers import create_action @@ -267,7 +267,11 @@ def chdir(self, directory, browsing_history=False, refresh_explorer=True, refresh_console=True): """Set directory as working directory""" if directory: - directory = osp.abspath(to_text_string(directory)) + if PY2: + directory = encoding.to_fs_from_unicode(directory) + else: + directory = to_text_string(directory) + directory = osp.abspath(directory) # Working directory history management if browsing_history: @@ -282,8 +286,8 @@ def chdir(self, directory, browsing_history=False, self.history.append(directory) self.histindex = len(self.history)-1 - # Changing working directory - os.chdir(encoding.to_unicode_from_fs(directory)) + # Changing working directory + os.chdir(directory) self.refresh_plugin() if refresh_explorer: self.set_explorer_cwd.emit(directory) diff --git a/spyder/widgets/ipythonconsole/shell.py b/spyder/widgets/ipythonconsole/shell.py index bed2d395b6f..cf60c828817 100644 --- a/spyder/widgets/ipythonconsole/shell.py +++ b/spyder/widgets/ipythonconsole/shell.py @@ -15,7 +15,8 @@ from qtpy.QtWidgets import QMessageBox from spyder.config.base import _ from spyder.config.gui import config_shortcut -from spyder.py3compat import to_text_string +from spyder.py3compat import PY2, to_text_string +from spyder.utils import encoding from spyder.utils import programs from spyder.utils.ipython.style import create_qss_style, create_style_class from spyder.widgets.ipythonconsole import (ControlWidget, DebuggingWidget, @@ -321,6 +322,8 @@ def handle_exec_method(self, msg): elif 'get_cwd' in method: if data is not None and 'text/plain' in data: self._cwd = ast.literal_eval(data['text/plain']) + if PY2: + self._cwd = encoding.to_unicode_from_fs(self._cwd) else: self._cwd = '' self.sig_change_cwd.emit(self._cwd) From 3c570f8721a41f03dc9923e0839fc52d6de47685 Mon Sep 17 00:00:00 2001 From: Carlos Cordoba Date: Sun, 30 Jul 2017 14:30:12 -0500 Subject: [PATCH 04/14] Encode/decode dir sent from Working directory to File Explorer in PY2 --- spyder/plugins/workingdirectory.py | 2 ++ spyder/widgets/explorer.py | 5 ++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/spyder/plugins/workingdirectory.py b/spyder/plugins/workingdirectory.py index 4a10463cbf7..e17546fca87 100644 --- a/spyder/plugins/workingdirectory.py +++ b/spyder/plugins/workingdirectory.py @@ -290,6 +290,8 @@ def chdir(self, directory, browsing_history=False, os.chdir(directory) self.refresh_plugin() if refresh_explorer: + if PY2: + directory = encoding.to_unicode_from_fs(directory) self.set_explorer_cwd.emit(directory) if refresh_console: self.set_as_current_console_wd() diff --git a/spyder/widgets/explorer.py b/spyder/widgets/explorer.py index 752f6cccca1..39e1dd7629e 100644 --- a/spyder/widgets/explorer.py +++ b/spyder/widgets/explorer.py @@ -1052,7 +1052,10 @@ def toggle_show_cd_only(self, checked): def set_current_folder(self, folder): """Set current folder and return associated model index""" index = self.fsmodel.setRootPath(folder) - self.__last_folder = folder + if PY2: + self.__last_folder = encoding.to_fs_from_unicode(folder) + else: + self.__last_folder = folder if self.show_cd_only: if self.__original_root_index is None: self.__original_root_index = self.rootIndex() From 584af8d94071f7f5606fda1f3e2d8c93a575fbd5 Mon Sep 17 00:00:00 2001 From: Carlos Cordoba Date: Sun, 30 Jul 2017 14:34:07 -0500 Subject: [PATCH 05/14] Working directory: Fix EOLs --- spyder/plugins/workingdirectory.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spyder/plugins/workingdirectory.py b/spyder/plugins/workingdirectory.py index e17546fca87..586f73b9ed4 100644 --- a/spyder/plugins/workingdirectory.py +++ b/spyder/plugins/workingdirectory.py @@ -286,8 +286,8 @@ def chdir(self, directory, browsing_history=False, self.history.append(directory) self.histindex = len(self.history)-1 - # Changing working directory - os.chdir(directory) + # Changing working directory + os.chdir(directory) self.refresh_plugin() if refresh_explorer: if PY2: From 65f5cda4f67f9ba3ffb2e614d24178eff0eb58bf Mon Sep 17 00:00:00 2001 From: Carlos Cordoba Date: Sun, 30 Jul 2017 14:34:48 -0500 Subject: [PATCH 06/14] Testing: Fix error when running tests locally on Windows --- spyder/utils/tests/test_programs.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spyder/utils/tests/test_programs.py b/spyder/utils/tests/test_programs.py index 2b936d50d9a..93c36f4943e 100644 --- a/spyder/utils/tests/test_programs.py +++ b/spyder/utils/tests/test_programs.py @@ -18,7 +18,7 @@ if os.name == 'nt': - python_dir = os.environ['PYTHON'] + python_dir = os.environ['PYTHON'] if os.environ.get('CI', None) else '' VALID_INTERPRETER = os.path.join(python_dir, 'python.exe') INVALID_INTERPRETER = os.path.join(python_dir, 'Scripts', 'ipython.exe') else: From d3e51f864852a34696675219ccd8579745205322 Mon Sep 17 00:00:00 2001 From: Carlos Cordoba Date: Sun, 30 Jul 2017 14:40:54 -0500 Subject: [PATCH 07/14] Testing: Fix test_change_cwd_ipython_console --- spyder/app/tests/test_mainwindow.py | 36 +++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/spyder/app/tests/test_mainwindow.py b/spyder/app/tests/test_mainwindow.py index acfcae2c26f..9075d7ac065 100644 --- a/spyder/app/tests/test_mainwindow.py +++ b/spyder/app/tests/test_mainwindow.py @@ -29,6 +29,7 @@ from spyder.config.main import CONF from spyder.plugins.runconfig import RunConfiguration from spyder.py3compat import PY2 +from spyder.utils import encoding from spyder.utils.ipython.kernelspec import SpyderKernelSpec from spyder.utils.programs import is_module_installed from spyder.utils.test import close_save_message_box @@ -345,28 +346,45 @@ def test_change_types_in_varexp(main_window, qtbot): assert shell.get_value('a') == 10 -@pytest.mark.parametrize("test_directory", ["test_dir", "non_ascii_ñ_í_ç"]) +@pytest.mark.parametrize("test_directory", [u"non_ascii_ñ_í_ç", u"test_dir"]) @flaky(max_runs=3) def test_change_cwd_ipython_console(main_window, qtbot, tmpdir, test_directory): """ Test synchronization with working directory and File Explorer when changing cwd in the IPython console. """ - # Wait until the window is fully up + wdir = main_window.workingdirectory + treewidget = main_window.explorer.treewidget shell = main_window.ipyconsole.get_current_shellwidget() + + # Wait until the window is fully up qtbot.waitUntil(lambda: shell._prompt_html is not None, timeout=SHELL_TIMEOUT) - # Change directory in ipython console using %cd - temp_dir = str(tmpdir.mkdir(test_directory)) + # Create temp directory + if PY2: + temp_dir_unicode = osp.join(encoding.to_unicode_from_fs(tempfile.gettempdir()), + test_directory) + temp_dir = encoding.to_fs_from_unicode(temp_dir_unicode) + try: + os.makedirs(temp_dir) + except: + pass + else: + temp_dir = str(tmpdir.mkdir(test_directory)) + + # Change directory in IPython console using %cd with qtbot.waitSignal(shell.executed): - shell.execute("%cd {}".format(temp_dir)) + if PY2: + shell.execute(u"%cd {}".format(temp_dir_unicode)) + else: + shell.execute("%cd {}".format(temp_dir)) qtbot.wait(1000) - # assert that cwd changed in workingdirectory - assert osp.normpath(main_window.workingdirectory.history[-1]) == osp.normpath(temp_dir) + # Assert that cwd changed in workingdirectory + assert osp.normpath(wdir.history[-1]) == osp.normpath(temp_dir) - # assert that cwd changed in explorer - assert osp.normpath(main_window.explorer.treewidget.get_current_folder()) == osp.normpath(temp_dir) + # Assert that cwd changed in explorer + assert osp.normpath(treewidget.get_current_folder()) == osp.normpath(temp_dir) @flaky(max_runs=3) From 5eaa52c9888fc33c8027d41c28dc62f711b3b8dc Mon Sep 17 00:00:00 2001 From: Carlos Cordoba Date: Sun, 30 Jul 2017 15:36:26 -0500 Subject: [PATCH 08/14] Encode as unicode dir sent from Working directory to IPython console in PY2 --- spyder/plugins/ipythonconsole.py | 1 - spyder/plugins/workingdirectory.py | 12 +++++------- spyder/widgets/ipythonconsole/shell.py | 7 ++++++- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/spyder/plugins/ipythonconsole.py b/spyder/plugins/ipythonconsole.py index 9551e4d795b..f4e43518b35 100644 --- a/spyder/plugins/ipythonconsole.py +++ b/spyder/plugins/ipythonconsole.py @@ -883,7 +883,6 @@ def set_current_client_working_directory(self, directory): """Set current client working directory.""" shellwidget = self.get_current_shellwidget() if shellwidget is not None: - directory = encoding.to_unicode_from_fs(directory) shellwidget.set_cwd(directory) def set_working_directory(self, dirname): diff --git a/spyder/plugins/workingdirectory.py b/spyder/plugins/workingdirectory.py index 586f73b9ed4..c5dba29ec3d 100644 --- a/spyder/plugins/workingdirectory.py +++ b/spyder/plugins/workingdirectory.py @@ -289,14 +289,12 @@ def chdir(self, directory, browsing_history=False, # Changing working directory os.chdir(directory) self.refresh_plugin() + + # Refresh other plugins + if PY2: + directory = encoding.to_unicode_from_fs(directory) if refresh_explorer: - if PY2: - directory = encoding.to_unicode_from_fs(directory) self.set_explorer_cwd.emit(directory) if refresh_console: - self.set_as_current_console_wd() + self.set_current_console_wd.emit(directory) self.refresh_findinfiles.emit() - - def set_as_current_console_wd(self): - """Set as current console working directory""" - self.set_current_console_wd.emit(getcwd()) diff --git a/spyder/widgets/ipythonconsole/shell.py b/spyder/widgets/ipythonconsole/shell.py index cf60c828817..301ef66b77e 100644 --- a/spyder/widgets/ipythonconsole/shell.py +++ b/spyder/widgets/ipythonconsole/shell.py @@ -9,6 +9,7 @@ """ import ast +import os import uuid from qtpy.QtCore import Signal @@ -93,7 +94,11 @@ def is_spyder_kernel(self): def set_cwd(self, dirname): """Set shell current working directory.""" - code = u"get_ipython().kernel.set_cwd(r'{}')".format(dirname) + # Replace single for double backslashes on Windows + if os.name == 'nt': + dirname = dirname.replace(u"\\", u"\\\\") + + code = u"get_ipython().kernel.set_cwd(u'{}')".format(dirname) if self._reading: self.kernel_client.input(u'!' + code) else: From e5e1b29ab83e7f0cf77ea838a2d4c06b5bc6a8f7 Mon Sep 17 00:00:00 2001 From: Carlos Cordoba Date: Sun, 30 Jul 2017 15:37:08 -0500 Subject: [PATCH 09/14] Kernel: Remove wrong return statement in set_cwd --- spyder/utils/ipython/spyder_kernel.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spyder/utils/ipython/spyder_kernel.py b/spyder/utils/ipython/spyder_kernel.py index dc94d85cc22..5ae109ee05b 100644 --- a/spyder/utils/ipython/spyder_kernel.py +++ b/spyder/utils/ipython/spyder_kernel.py @@ -241,7 +241,7 @@ def get_source(self, objtxt): # --- Additional methods def set_cwd(self, dirname): """Set current working directory.""" - return os.chdir(dirname) + os.chdir(dirname) def get_cwd(self): """Get current working directory.""" From 1a657d6229e6e7f1b48cb49d78ac46200d8f599b Mon Sep 17 00:00:00 2001 From: Carlos Cordoba Date: Sun, 30 Jul 2017 15:54:38 -0500 Subject: [PATCH 10/14] Testing: Add non-ascii dir to test_change_cwd_explorer --- spyder/app/tests/test_mainwindow.py | 33 +++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/spyder/app/tests/test_mainwindow.py b/spyder/app/tests/test_mainwindow.py index 9075d7ac065..01138c386a7 100644 --- a/spyder/app/tests/test_mainwindow.py +++ b/spyder/app/tests/test_mainwindow.py @@ -346,8 +346,8 @@ def test_change_types_in_varexp(main_window, qtbot): assert shell.get_value('a') == 10 -@pytest.mark.parametrize("test_directory", [u"non_ascii_ñ_í_ç", u"test_dir"]) @flaky(max_runs=3) +@pytest.mark.parametrize("test_directory", [u"non_ascii_ñ_í_ç", u"test_dir"]) def test_change_cwd_ipython_console(main_window, qtbot, tmpdir, test_directory): """ Test synchronization with working directory and File Explorer when @@ -388,25 +388,40 @@ def test_change_cwd_ipython_console(main_window, qtbot, tmpdir, test_directory): @flaky(max_runs=3) -def test_change_cwd_explorer(main_window, qtbot, tmpdir): +@pytest.mark.parametrize("test_directory", [u"non_ascii_ñ_í_ç", u"test_dir"]) +def test_change_cwd_explorer(main_window, qtbot, tmpdir, test_directory): """ Test synchronization with working directory and IPython console when changing directories in the File Explorer. """ - # Wait until the window is fully up + wdir = main_window.workingdirectory + explorer = main_window.explorer shell = main_window.ipyconsole.get_current_shellwidget() + + # Wait until the window is fully up qtbot.waitUntil(lambda: shell._prompt_html is not None, timeout=SHELL_TIMEOUT) + # Create temp directory + if PY2: + temp_dir_unicode = osp.join(encoding.to_unicode_from_fs(tempfile.gettempdir()), + test_directory) + temp_dir = encoding.to_fs_from_unicode(temp_dir_unicode) + try: + os.makedirs(temp_dir) + except: + pass + else: + temp_dir = str(tmpdir.mkdir(test_directory)) + # Change directory in the explorer widget - temp_dir = str(tmpdir.mkdir("test_dir")) - main_window.explorer.chdir(temp_dir) + explorer.chdir(temp_dir_unicode) qtbot.wait(1000) - # assert that cwd changed in workingdirectory - assert osp.normpath(main_window.workingdirectory.history[-1]) == osp.normpath(temp_dir) + # Assert that cwd changed in workingdirectory + assert osp.normpath(wdir.history[-1]) == osp.normpath(temp_dir) - # assert that cwd changed in ipythonconsole - assert osp.normpath(temp_dir) == osp.normpath(shell._cwd) + # Assert that cwd changed in IPython console + assert osp.normpath(temp_dir_unicode) == osp.normpath(shell._cwd) @flaky(max_runs=3) From 2f85cab28349583d4c40961f06c6183db58c3ed3 Mon Sep 17 00:00:00 2001 From: Carlos Cordoba Date: Sun, 30 Jul 2017 16:12:16 -0500 Subject: [PATCH 11/14] Testing: Fix test_change_cwd_explorer in Python 3 --- spyder/app/tests/test_mainwindow.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spyder/app/tests/test_mainwindow.py b/spyder/app/tests/test_mainwindow.py index 01138c386a7..d833512770d 100644 --- a/spyder/app/tests/test_mainwindow.py +++ b/spyder/app/tests/test_mainwindow.py @@ -411,7 +411,7 @@ def test_change_cwd_explorer(main_window, qtbot, tmpdir, test_directory): except: pass else: - temp_dir = str(tmpdir.mkdir(test_directory)) + temp_dir = temp_dir_unicode = str(tmpdir.mkdir(test_directory)) # Change directory in the explorer widget explorer.chdir(temp_dir_unicode) From da90882b79e7566b1e50309388c930d76cb67216 Mon Sep 17 00:00:00 2001 From: Carlos Cordoba Date: Sun, 30 Jul 2017 16:32:31 -0500 Subject: [PATCH 12/14] Working directory and File Explorer: Use unicode to save cwd internal value --- spyder/plugins/workingdirectory.py | 8 +------- spyder/widgets/explorer.py | 5 +---- 2 files changed, 2 insertions(+), 11 deletions(-) diff --git a/spyder/plugins/workingdirectory.py b/spyder/plugins/workingdirectory.py index c5dba29ec3d..d9907b27f55 100644 --- a/spyder/plugins/workingdirectory.py +++ b/spyder/plugins/workingdirectory.py @@ -267,10 +267,7 @@ def chdir(self, directory, browsing_history=False, refresh_explorer=True, refresh_console=True): """Set directory as working directory""" if directory: - if PY2: - directory = encoding.to_fs_from_unicode(directory) - else: - directory = to_text_string(directory) + directory = to_text_string(directory) directory = osp.abspath(directory) # Working directory history management @@ -290,9 +287,6 @@ def chdir(self, directory, browsing_history=False, os.chdir(directory) self.refresh_plugin() - # Refresh other plugins - if PY2: - directory = encoding.to_unicode_from_fs(directory) if refresh_explorer: self.set_explorer_cwd.emit(directory) if refresh_console: diff --git a/spyder/widgets/explorer.py b/spyder/widgets/explorer.py index 39e1dd7629e..752f6cccca1 100644 --- a/spyder/widgets/explorer.py +++ b/spyder/widgets/explorer.py @@ -1052,10 +1052,7 @@ def toggle_show_cd_only(self, checked): def set_current_folder(self, folder): """Set current folder and return associated model index""" index = self.fsmodel.setRootPath(folder) - if PY2: - self.__last_folder = encoding.to_fs_from_unicode(folder) - else: - self.__last_folder = folder + self.__last_folder = folder if self.show_cd_only: if self.__original_root_index is None: self.__original_root_index = self.rootIndex() From 2a001cf4d317a0a09dd2fe2a8682e43bf91becc7 Mon Sep 17 00:00:00 2001 From: Carlos Cordoba Date: Sun, 30 Jul 2017 16:41:59 -0500 Subject: [PATCH 13/14] Testing: Simplify tests according to last commit --- spyder/app/tests/test_mainwindow.py | 36 ++++++----------------------- 1 file changed, 7 insertions(+), 29 deletions(-) diff --git a/spyder/app/tests/test_mainwindow.py b/spyder/app/tests/test_mainwindow.py index d833512770d..6c4f2ae9d76 100644 --- a/spyder/app/tests/test_mainwindow.py +++ b/spyder/app/tests/test_mainwindow.py @@ -28,8 +28,7 @@ from spyder.config.base import get_home_dir from spyder.config.main import CONF from spyder.plugins.runconfig import RunConfiguration -from spyder.py3compat import PY2 -from spyder.utils import encoding +from spyder.py3compat import PY2, to_text_string from spyder.utils.ipython.kernelspec import SpyderKernelSpec from spyder.utils.programs import is_module_installed from spyder.utils.test import close_save_message_box @@ -360,24 +359,12 @@ def test_change_cwd_ipython_console(main_window, qtbot, tmpdir, test_directory): # Wait until the window is fully up qtbot.waitUntil(lambda: shell._prompt_html is not None, timeout=SHELL_TIMEOUT) - # Create temp directory - if PY2: - temp_dir_unicode = osp.join(encoding.to_unicode_from_fs(tempfile.gettempdir()), - test_directory) - temp_dir = encoding.to_fs_from_unicode(temp_dir_unicode) - try: - os.makedirs(temp_dir) - except: - pass - else: - temp_dir = str(tmpdir.mkdir(test_directory)) + # Create temp dir + temp_dir = to_text_string(tmpdir.mkdir(test_directory)) # Change directory in IPython console using %cd with qtbot.waitSignal(shell.executed): - if PY2: - shell.execute(u"%cd {}".format(temp_dir_unicode)) - else: - shell.execute("%cd {}".format(temp_dir)) + shell.execute(u"%cd {}".format(temp_dir)) qtbot.wait(1000) # Assert that cwd changed in workingdirectory @@ -402,26 +389,17 @@ def test_change_cwd_explorer(main_window, qtbot, tmpdir, test_directory): qtbot.waitUntil(lambda: shell._prompt_html is not None, timeout=SHELL_TIMEOUT) # Create temp directory - if PY2: - temp_dir_unicode = osp.join(encoding.to_unicode_from_fs(tempfile.gettempdir()), - test_directory) - temp_dir = encoding.to_fs_from_unicode(temp_dir_unicode) - try: - os.makedirs(temp_dir) - except: - pass - else: - temp_dir = temp_dir_unicode = str(tmpdir.mkdir(test_directory)) + temp_dir = to_text_string(tmpdir.mkdir(test_directory)) # Change directory in the explorer widget - explorer.chdir(temp_dir_unicode) + explorer.chdir(temp_dir) qtbot.wait(1000) # Assert that cwd changed in workingdirectory assert osp.normpath(wdir.history[-1]) == osp.normpath(temp_dir) # Assert that cwd changed in IPython console - assert osp.normpath(temp_dir_unicode) == osp.normpath(shell._cwd) + assert osp.normpath(temp_dir) == osp.normpath(shell._cwd) @flaky(max_runs=3) From d08234c6e1118e6016d432a033268f09918a18ca Mon Sep 17 00:00:00 2001 From: Carlos Cordoba Date: Sun, 30 Jul 2017 16:54:07 -0500 Subject: [PATCH 14/14] Working directory: Remove unneeded import --- spyder/plugins/workingdirectory.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/spyder/plugins/workingdirectory.py b/spyder/plugins/workingdirectory.py index d9907b27f55..94f3e3612b4 100644 --- a/spyder/plugins/workingdirectory.py +++ b/spyder/plugins/workingdirectory.py @@ -26,7 +26,7 @@ from spyder.config.base import _, get_conf_path, get_home_dir from spyder.plugins import SpyderPluginMixin from spyder.plugins.configdialog import PluginConfigPage -from spyder.py3compat import PY2, to_text_string, getcwd +from spyder.py3compat import to_text_string, getcwd from spyder.utils import encoding from spyder.utils import icon_manager as ima from spyder.utils.qthelpers import create_action @@ -267,8 +267,7 @@ def chdir(self, directory, browsing_history=False, refresh_explorer=True, refresh_console=True): """Set directory as working directory""" if directory: - directory = to_text_string(directory) - directory = osp.abspath(directory) + directory = osp.abspath(to_text_string(directory)) # Working directory history management if browsing_history: