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
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
10 changes: 7 additions & 3 deletions spyder/widgets/projects/explorer.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ def delete(self, fnames=None):

class ProjectExplorerWidget(QWidget):
"""Project Explorer"""
redirect_stdio = Signal(bool)
Copy link
Member

Choose a reason for hiding this comment

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

Is this signal necessary?

Copy link
Member Author

Choose a reason for hiding this comment

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

sig_option_changed = Signal(str, object)
sig_open_file = Signal(str)

Expand Down Expand Up @@ -261,13 +262,16 @@ def delete_project(self):
# Tests
#==============================================================================
class ProjectExplorerTest(QWidget):
def __init__(self):
def __init__(self, directory=None):
Copy link
Member

Choose a reason for hiding this comment

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

Please make directory an attribute of this class, i.e.

self.directory = directory 

QWidget.__init__(self)
vlayout = QVBoxLayout()
self.setLayout(vlayout)

self.explorer = ProjectExplorerWidget(None, show_all=True)
self.explorer.setup_project(osp.dirname(osp.abspath(__file__)))
self.explorer = ProjectExplorerWidget(parent=self, show_all=True)
if directory:
Copy link
Member

Choose a reason for hiding this comment

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

if direcotory: -> if self.directory is not None:

self.explorer.setup_project(directory)
Copy link
Member

Choose a reason for hiding this comment

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

directory -> self.directory

else:
self.explorer.setup_project(osp.dirname(osp.abspath(__file__)))
vlayout.addWidget(self.explorer)

hlayout1 = QHBoxLayout()
Expand Down
51 changes: 42 additions & 9 deletions spyder/widgets/projects/tests/test_project_explorer.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,59 @@
"""
Tests for explorer.py
"""
# Standard imports
import os
import os.path as osp

# Test library imports
import pytest

# Local imports
from spyder.widgets.projects.explorer import ProjectExplorerTest


@pytest.fixture
def setup_projects_explorer(qtbot):
"""Set up ProjectExplorerWidgetTest."""
project_explorer = ProjectExplorerTest()
def project_explorer(qtbot, request, tmpdir):
"""Setup Project Explorer widget."""
directory = request.node.get_marker('change_directory')
if directory:
project_dir = str(tmpdir.mkdir('project'))
Copy link
Member

Choose a reason for hiding this comment

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

Let's change str here for to_text_string

else:
project_dir = None
project_explorer = ProjectExplorerTest(directory=project_dir)
qtbot.addWidget(project_explorer)
return project_explorer
return (project_explorer, project_dir)
Copy link
Member

Choose a reason for hiding this comment

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

Let's make return only project_explorer here.



@pytest.mark.change_directory
def test_change_directory_in_project_explorer(project_explorer, qtbot):
"""Test changing a file from directory in the Project explorer."""
# Create project
project, project_dir = project_explorer
Copy link
Member

Choose a reason for hiding this comment

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

This needs to be now

project = project_explorer
project_dir = project.directory


# Create a temp project directory and file
project_dir_tmp = osp.join(project_dir, 'tmpá')
project_file = osp.join(project_dir, 'script.py')

# Create an empty file in the project dir
os.mkdir(project_dir_tmp)
open(project_file, 'w').close()

# Move Python file
project.explorer.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'))


def test_project_explorer(qtbot):
def test_project_explorer(project_explorer, qtbot):
"""Run project explorer."""
project_explorer = setup_projects_explorer(qtbot)
project_explorer.resize(250, 480)
project_explorer.show()
assert project_explorer
project_explorer_dlg, project_dir = project_explorer
Copy link
Member

@ccordoba12 ccordoba12 Feb 13, 2018

Choose a reason for hiding this comment

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

This needs to be now

project = project_explorer

and please change below project_explorer_dlg to project.

project_explorer_dlg.resize(250, 480)
project_explorer_dlg.show()
assert project_explorer_dlg


if __name__ == "__main__":
Expand Down