-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
PR: Add test for file directory change in the Project Explorer. #6413
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
Changes from 5 commits
b5842ac
a158168
80c5ab1
a33c150
8d00a9f
84f79f7
1c7153e
f6983b2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -261,13 +261,16 @@ def delete_project(self): | |
# Tests | ||
#============================================================================== | ||
class ProjectExplorerTest(QWidget): | ||
def __init__(self): | ||
def __init__(self, directory=None): | ||
QWidget.__init__(self) | ||
vlayout = QVBoxLayout() | ||
self.setLayout(vlayout) | ||
|
||
self.explorer = ProjectExplorerWidget(None, show_all=True) | ||
self.explorer.setup_project(osp.dirname(osp.abspath(__file__))) | ||
if directory: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
self.explorer.setup_project(directory) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
else: | ||
self.explorer.setup_project(osp.dirname(osp.abspath(__file__))) | ||
vlayout.addWidget(self.explorer) | ||
|
||
hlayout1 = QHBoxLayout() | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,10 @@ | |
""" | ||
Tests for explorer.py | ||
""" | ||
# Standard imports | ||
import os | ||
import os.path as osp | ||
import shutil | ||
|
||
# Test library imports | ||
import pytest | ||
|
@@ -15,12 +19,38 @@ | |
from spyder.widgets.projects.explorer import ProjectExplorerTest | ||
|
||
@pytest.fixture | ||
def setup_projects_explorer(qtbot): | ||
def setup_projects_explorer(qtbot, directory=None): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please change this name to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And the right way to achieve what you want is by using a marker to modify the fixture's result. See for example: https://github.com/spyder-ide/spyder/blob/3.x/spyder/plugins/tests/test_ipythonconsole.py#L75-L79 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On a second thought, let's rename the fixture to |
||
"""Set up ProjectExplorerWidgetTest.""" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please change this docstring to
|
||
project_explorer = ProjectExplorerTest() | ||
project_explorer = ProjectExplorerTest(directory=directory) | ||
qtbot.addWidget(project_explorer) | ||
return project_explorer | ||
|
||
|
||
def test_change_directory_in_project_explorer(qtbot, tmpdir): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You need to pass the fixture as an argument to the test, else it can't be initialized correctly. |
||
"""Test changing a file from directory in the Project explorer.""" | ||
# Create a temp project directory | ||
project_dir = str(tmpdir.mkdir('project')) | ||
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() | ||
|
||
# Create project | ||
projects = setup_projects_explorer(qtbot, directory=project_dir) | ||
|
||
# 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() | ||
|
||
|
||
def test_project_explorer(qtbot): | ||
"""Run project explorer.""" | ||
project_explorer = setup_projects_explorer(qtbot) | ||
|
There was a problem hiding this comment.
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.