-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Conversation
spyder/app/tests/test_mainwindow.py
Outdated
projects = main_window.projects | ||
|
||
# Create a temp project directory | ||
project_dir = tempfile.mkdtemp() |
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 change this to use the tmpdir
fixture instead.
3a98abc
to
a158168
Compare
spyder/app/tests/test_mainwindow.py
Outdated
projects.treewidget.setCurrentIndex(idx) | ||
|
||
# Set a timer to manipulate the select directory dialog while it's running | ||
QTimer.singleShot(2000, lambda: open_file_in_editor( |
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.
I think this timer is what's making the test to hang on Appveyor.
spyder/app/tests/test_mainwindow.py
Outdated
if isinstance(w, QFileDialog): | ||
if directory is not None: | ||
w.setDirectory(directory) | ||
QTest.keyClick(w, Qt.Key_Enter) |
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.
This auxiliary function is not needed anymore. Please remove it.
spyder/app/tests/test_mainwindow.py
Outdated
@@ -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): |
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.
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
.
6cc6cad
to
8d00a9f
Compare
@@ -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 comment
The reason will be displayed to describe this comment to others. Learn more.
Please change this name to setup_project_explorer
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.
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
https://github.com/spyder-ide/spyder/blob/3.x/spyder/plugins/tests/test_ipythonconsole.py#L94-L97
https://github.com/spyder-ide/spyder/blob/3.x/spyder/plugins/tests/test_ipythonconsole.py#L231
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.
On a second thought, let's rename the fixture to project_explorer
(instead of setup_project_explorer
).
@@ -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): | |||
"""Set up ProjectExplorerWidgetTest.""" |
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 change this docstring to
Setup Project Explorer widget
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 comment
The 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.
98a101d
to
5423e4b
Compare
1e343e8
to
84f79f7
Compare
@@ -169,6 +169,7 @@ def delete(self, fnames=None): | |||
|
|||
class ProjectExplorerWidget(QWidget): | |||
"""Project Explorer""" | |||
redirect_stdio = Signal(bool) |
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.
Is this signal necessary?
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.
Yep, here the reason: https://github.com/spyder-ide/spyder/blob/3.x/spyder/widgets/explorer.py#L703
@@ -261,13 +262,16 @@ def delete_project(self): | |||
# Tests | |||
#============================================================================== | |||
class ProjectExplorerTest(QWidget): | |||
def __init__(self): | |||
def __init__(self, directory=None): |
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.
self.directory = directory
spyder/widgets/projects/explorer.py
Outdated
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: |
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.
if direcotory:
-> if self.directory is not None:
spyder/widgets/projects/explorer.py
Outdated
self.explorer.setup_project(osp.dirname(osp.abspath(__file__))) | ||
self.explorer = ProjectExplorerWidget(parent=self, show_all=True) | ||
if directory: | ||
self.explorer.setup_project(directory) |
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.
directory
-> self.directory
"""Setup Project Explorer widget.""" | ||
directory = request.node.get_marker('change_directory') | ||
if directory: | ||
project_dir = str(tmpdir.mkdir('project')) |
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.
Let's change str
here for to_text_string
qtbot.addWidget(project_explorer) | ||
return project_explorer | ||
return (project_explorer, project_dir) |
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.
Let's make return only project_explorer
here.
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 |
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.
This needs to be now
project = project_explorer
project_dir = project.directory
project_explorer.resize(250, 480) | ||
project_explorer.show() | ||
assert project_explorer | ||
project_explorer_dlg, project_dir = project_explorer |
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.
This needs to be now
project = project_explorer
and please change below project_explorer_dlg
to project
.
Fixes #5601