Skip to content

Commit

Permalink
Correct use of the fixture in project explorer tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
dalthviz committed Feb 13, 2018
1 parent 8d00a9f commit 84f79f7
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 22 deletions.
3 changes: 2 additions & 1 deletion 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)
sig_option_changed = Signal(str, object)
sig_open_file = Signal(str)

Expand Down Expand Up @@ -266,7 +267,7 @@ def __init__(self, directory=None):
vlayout = QVBoxLayout()
self.setLayout(vlayout)

self.explorer = ProjectExplorerWidget(None, show_all=True)
self.explorer = ProjectExplorerWidget(parent=self, show_all=True)
if directory:
self.explorer.setup_project(directory)
else:
Expand Down
45 changes: 24 additions & 21 deletions spyder/widgets/projects/tests/test_project_explorer.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,53 +10,56 @@
# Standard imports
import os
import os.path as osp
import shutil

# Test library imports
import pytest

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


@pytest.fixture
def setup_projects_explorer(qtbot, directory=None):
"""Set up ProjectExplorerWidgetTest."""
project_explorer = ProjectExplorerTest(directory=directory)
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'))
else:
project_dir = None
project_explorer = ProjectExplorerTest(directory=project_dir)
qtbot.addWidget(project_explorer)
return project_explorer
return (project_explorer, project_dir)


def test_change_directory_in_project_explorer(qtbot, tmpdir):
@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 a temp project directory
project_dir = str(tmpdir.mkdir('project'))
# Create project
project, project_dir = project_explorer

# 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()

# 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)
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'))

# Close project
projects.close_project()


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
project_explorer_dlg.resize(250, 480)
project_explorer_dlg.show()
assert project_explorer_dlg


if __name__ == "__main__":
Expand Down

0 comments on commit 84f79f7

Please sign in to comment.