-
-
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
Changes from 6 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 |
---|---|---|
|
@@ -169,6 +169,7 @@ def delete(self, fnames=None): | |
|
||
class ProjectExplorerWidget(QWidget): | ||
"""Project Explorer""" | ||
redirect_stdio = Signal(bool) | ||
sig_option_changed = Signal(str, object) | ||
sig_open_file = Signal(str) | ||
|
||
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. Please make
|
||
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: | ||
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,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')) | ||
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. Let's change |
||
else: | ||
project_dir = None | ||
project_explorer = ProjectExplorerTest(directory=project_dir) | ||
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 commentThe reason will be displayed to describe this comment to others. Learn more. Let's make return only |
||
|
||
|
||
@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 | ||
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. This needs to be now
|
||
|
||
# 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 | ||
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. This needs to be now
and please change below |
||
project_explorer_dlg.resize(250, 480) | ||
project_explorer_dlg.show() | ||
assert project_explorer_dlg | ||
|
||
|
||
if __name__ == "__main__": | ||
|
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