Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PR: Add test for file directory change in the Project Explorer. #6413

Merged
merged 8 commits into from
Feb 15, 2018
Merged
46 changes: 46 additions & 0 deletions spyder/app/tests/test_mainwindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,18 @@
# =============================================================================
# Utility functions
# =============================================================================


def select_directory(main_window, directory=None):
"""Open a file using the Editor and its open file dialog"""
top_level_widgets = QApplication.topLevelWidgets()
for w in top_level_widgets:
if isinstance(w, QFileDialog):
if directory is not None:
w.setDirectory(directory)
QTest.keyClick(w, Qt.Key_Enter)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This auxiliary function is not needed anymore. Please remove it.



def open_file_in_editor(main_window, fname, directory=None):
"""Open a file using the Editor and its open file dialog"""
top_level_widgets = QApplication.topLevelWidgets()
Expand Down Expand Up @@ -205,6 +217,40 @@ def test_calltip(main_window, qtbot):
main_window.editor.close_file()


@pytest.mark.slow
@flaky(max_runs=3)
def test_change_directory_in_project_explorer(main_window, qtbot, tmpdir):
Copy link
Member

@ccordoba12 ccordoba12 Feb 11, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test doesn't need to interact with other plugins (e.g. the IPython console), so it doesn't belong here. Please move it to spyder/plugins/tests/test_projects.py.

"""Test changing a file from directory in the Project explorer."""
projects = main_window.projects

# Create a temp project directory
project_dir = str(tmpdir.mkdir('project'))
project_dir_tmp = osp.join(project_dir, 'tmpá')

# Create an empty file in the project dir
project_file = osp.join(LOCATION, 'script.py')
shutil.copy(project_file, osp.join(project_dir, 'script.py'))
os.mkdir(project_dir_tmp)

# Create project
with qtbot.waitSignal(projects.sig_project_loaded):
projects._create_project(project_dir)

# Select file in the project explorer
idx = projects.treewidget.get_index('script.py')
projects.treewidget.setCurrentIndex(idx)

# Move Python file
projects.treewidget.move(fnames=[osp.join(project_dir, 'script.py')],
directory=project_dir_tmp)

# Assert content was moved
assert osp.isfile(osp.join(project_dir_tmp, 'script.py'))

# Close project
projects.close_project()


@pytest.mark.slow
@pytest.mark.single_instance
def test_single_instance_and_edit_magic(main_window, qtbot, tmpdir):
Expand Down
8 changes: 6 additions & 2 deletions spyder/widgets/explorer.py
Original file line number Diff line number Diff line change
Expand Up @@ -694,14 +694,18 @@ def rename(self, fnames=None):
self.rename_file(fname)

@Slot()
def move(self, fnames=None):
def move(self, fnames=None, directory=None):
"""Move files/directories"""
if fnames is None:
fnames = self.get_selected_filenames()
orig = fixpath(osp.dirname(fnames[0]))
while True:
self.parent_widget.redirect_stdio.emit(False)
folder = getexistingdirectory(self, _("Select directory"), orig)
if directory is None:
folder = getexistingdirectory(self, _("Select directory"),
orig)
else:
folder = directory
self.parent_widget.redirect_stdio.emit(True)
if folder:
folder = fixpath(folder)
Expand Down