Skip to content

Commit 8d00a9f

Browse files
committed
Testing.
1 parent a33c150 commit 8d00a9f

File tree

3 files changed

+37
-38
lines changed

3 files changed

+37
-38
lines changed

Diff for: spyder/app/tests/test_mainwindow.py

-34
Original file line numberDiff line numberDiff line change
@@ -205,40 +205,6 @@ def test_calltip(main_window, qtbot):
205205
main_window.editor.close_file()
206206

207207

208-
@pytest.mark.slow
209-
@flaky(max_runs=3)
210-
def test_change_directory_in_project_explorer(main_window, qtbot, tmpdir):
211-
"""Test changing a file from directory in the Project explorer."""
212-
projects = main_window.projects
213-
214-
# Create a temp project directory
215-
project_dir = str(tmpdir.mkdir('project'))
216-
project_dir_tmp = osp.join(project_dir, 'tmpá')
217-
218-
# Create an empty file in the project dir
219-
project_file = osp.join(LOCATION, 'script.py')
220-
shutil.copy(project_file, osp.join(project_dir, 'script.py'))
221-
os.mkdir(project_dir_tmp)
222-
223-
# Create project
224-
with qtbot.waitSignal(projects.sig_project_loaded):
225-
projects._create_project(project_dir)
226-
227-
# Select file in the project explorer
228-
idx = projects.treewidget.get_index('script.py')
229-
projects.treewidget.setCurrentIndex(idx)
230-
231-
# Move Python file
232-
projects.treewidget.move(fnames=[osp.join(project_dir, 'script.py')],
233-
directory=project_dir_tmp)
234-
235-
# Assert content was moved
236-
assert osp.isfile(osp.join(project_dir_tmp, 'script.py'))
237-
238-
# Close project
239-
projects.close_project()
240-
241-
242208
@pytest.mark.slow
243209
@pytest.mark.single_instance
244210
def test_single_instance_and_edit_magic(main_window, qtbot, tmpdir):

Diff for: spyder/widgets/projects/explorer.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -261,13 +261,16 @@ def delete_project(self):
261261
# Tests
262262
#==============================================================================
263263
class ProjectExplorerTest(QWidget):
264-
def __init__(self):
264+
def __init__(self, directory=None):
265265
QWidget.__init__(self)
266266
vlayout = QVBoxLayout()
267267
self.setLayout(vlayout)
268268

269269
self.explorer = ProjectExplorerWidget(None, show_all=True)
270-
self.explorer.setup_project(osp.dirname(osp.abspath(__file__)))
270+
if directory:
271+
self.explorer.setup_project(directory)
272+
else:
273+
self.explorer.setup_project(osp.dirname(osp.abspath(__file__)))
271274
vlayout.addWidget(self.explorer)
272275

273276
hlayout1 = QHBoxLayout()

Diff for: spyder/widgets/projects/tests/test_project_explorer.py

+32-2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
"""
88
Tests for explorer.py
99
"""
10+
# Standard imports
11+
import os
12+
import os.path as osp
13+
import shutil
1014

1115
# Test library imports
1216
import pytest
@@ -15,12 +19,38 @@
1519
from spyder.widgets.projects.explorer import ProjectExplorerTest
1620

1721
@pytest.fixture
18-
def setup_projects_explorer(qtbot):
22+
def setup_projects_explorer(qtbot, directory=None):
1923
"""Set up ProjectExplorerWidgetTest."""
20-
project_explorer = ProjectExplorerTest()
24+
project_explorer = ProjectExplorerTest(directory=directory)
2125
qtbot.addWidget(project_explorer)
2226
return project_explorer
2327

28+
29+
def test_change_directory_in_project_explorer(qtbot, tmpdir):
30+
"""Test changing a file from directory in the Project explorer."""
31+
# Create a temp project directory
32+
project_dir = str(tmpdir.mkdir('project'))
33+
project_dir_tmp = osp.join(project_dir, 'tmpá')
34+
project_file = osp.join(project_dir, 'script.py')
35+
36+
# Create an empty file in the project dir
37+
os.mkdir(project_dir_tmp)
38+
open(project_file, 'w').close()
39+
40+
# Create project
41+
projects = setup_projects_explorer(qtbot, directory=project_dir)
42+
43+
# Move Python file
44+
projects.treewidget.move(fnames=[osp.join(project_dir, 'script.py')],
45+
directory=project_dir_tmp)
46+
47+
# Assert content was moved
48+
assert osp.isfile(osp.join(project_dir_tmp, 'script.py'))
49+
50+
# Close project
51+
projects.close_project()
52+
53+
2454
def test_project_explorer(qtbot):
2555
"""Run project explorer."""
2656
project_explorer = setup_projects_explorer(qtbot)

0 commit comments

Comments
 (0)