Skip to content

Commit 907395c

Browse files
committed
Testing: Expand test that checks Switcher/Projects integration
This includes new cases for binary and nonexistent files, and missing fzf.
1 parent a36cc6f commit 907395c

File tree

1 file changed

+46
-12
lines changed

1 file changed

+46
-12
lines changed

spyder/app/tests/test_mainwindow.py

+46-12
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import gc
1515
import os
1616
import os.path as osp
17+
from pathlib import Path
1718
import random
1819
import re
1920
import shutil
@@ -2535,8 +2536,9 @@ def example_def_2():
25352536

25362537

25372538
@flaky(max_runs=3)
2538-
def test_switcher_project_files(main_window, pytestconfig, qtbot, tmp_path):
2539-
"""Test the number of items in the switcher when a project is active."""
2539+
def test_switcher_projects_integration(main_window, pytestconfig, qtbot,
2540+
tmp_path):
2541+
"""Test integration between the Switcher and Projects plugins."""
25402542
# Disable pytest stdin capture to make calls to fzf work. Idea taken from:
25412543
# https://github.com/pytest-dev/pytest/issues/2189#issuecomment-449512764
25422544
capmanager = pytestconfig.pluginmanager.getplugin('capturemanager')
@@ -2558,16 +2560,22 @@ def test_switcher_project_files(main_window, pytestconfig, qtbot, tmp_path):
25582560
project_dir = tmp_path / 'test-projects-switcher'
25592561
project_dir.mkdir()
25602562

2561-
# Create project
2562-
with qtbot.waitSignal(projects.sig_project_loaded):
2563-
projects.create_project(str(project_dir))
2564-
25652563
# Create some empty files in the project dir
25662564
n_files_project = 3
25672565
for i in range(n_files_project):
25682566
fpath = project_dir / f"test_file{i}.py"
25692567
fpath.touch()
25702568

2569+
# Copy binary file from our source tree to the project to check it's not
2570+
# displayed in the switcher.
2571+
binary_file = Path(LOCATION).parents[1] / 'images' / 'windows_app_icon.ico'
2572+
binary_file_copy = project_dir / 'windows.ico'
2573+
shutil.copyfile(binary_file, binary_file_copy)
2574+
2575+
# Create project
2576+
with qtbot.waitSignal(projects.sig_project_loaded):
2577+
projects.create_project(str(project_dir))
2578+
25712579
# Check that the switcher has been populated in Projects
25722580
qtbot.waitUntil(
25732581
lambda: projects.get_widget()._default_switcher_paths != [],
@@ -2599,28 +2607,54 @@ def test_switcher_project_files(main_window, pytestconfig, qtbot, tmp_path):
25992607
assert switcher.count() == 1
26002608
switcher.on_close()
26012609

2610+
# Assert searching for a non-existent file leaves the switcher empty
2611+
switcher.open_switcher()
2612+
switcher.set_search_text('foo')
2613+
qtbot.wait(500)
2614+
assert switcher.count() == 0
2615+
switcher.on_close()
2616+
2617+
# Assert searching for a binary file leaves the switcher empty
2618+
switcher.open_switcher()
2619+
switcher.set_search_text('windows')
2620+
qtbot.wait(500)
2621+
assert switcher.count() == 0
2622+
switcher.on_close()
2623+
26022624
# Remove project file and check the switcher is updated
26032625
n_files_project -= 1
2604-
os.remove(osp.join(str(project_dir), 'test_file1.py'))
2605-
switcher.open_switcher()
2626+
os.remove(str(project_dir / 'test_file1.py'))
26062627
qtbot.wait(500)
2628+
switcher.open_switcher()
26072629
assert switcher.count() == n_files_open + n_files_project
26082630
switcher.on_close()
26092631

2610-
# Select file in the project explorer
2632+
# Check that a project file opened in the editor is not shown twice in the
2633+
# switcher
26112634
idx = projects.get_widget().treewidget.get_index(
2612-
osp.join(str(project_dir), 'test_file0.py')
2635+
str(project_dir / 'test_file0.py')
26132636
)
26142637
projects.get_widget().treewidget.setCurrentIndex(idx)
2615-
2616-
# Press Enter there
26172638
qtbot.keyClick(projects.get_widget().treewidget, Qt.Key_Enter)
26182639

26192640
switcher.open_switcher()
26202641
n_files_open = editorstack.get_stack_count()
26212642
assert switcher.count() == n_files_open + n_files_project - 1
26222643
switcher.on_close()
26232644

2645+
# Check the switcher works without fzf
2646+
fzf = projects.get_widget()._fzf
2647+
projects.get_widget()._fzf = None
2648+
projects.get_widget()._default_switcher_paths = []
2649+
2650+
switcher.open_switcher()
2651+
switcher.set_search_text('0')
2652+
qtbot.wait(500)
2653+
assert switcher.count() == 1
2654+
switcher.on_close()
2655+
2656+
projects.get_widget()._fzf = fzf
2657+
26242658
# Resume capturing
26252659
capmanager.resume_global_capture()
26262660

0 commit comments

Comments
 (0)