14
14
import gc
15
15
import os
16
16
import os .path as osp
17
+ from pathlib import Path
17
18
import random
18
19
import re
19
20
import shutil
@@ -2535,8 +2536,9 @@ def example_def_2():
2535
2536
2536
2537
2537
2538
@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."""
2540
2542
# Disable pytest stdin capture to make calls to fzf work. Idea taken from:
2541
2543
# https://github.com/pytest-dev/pytest/issues/2189#issuecomment-449512764
2542
2544
capmanager = pytestconfig .pluginmanager .getplugin ('capturemanager' )
@@ -2558,16 +2560,22 @@ def test_switcher_project_files(main_window, pytestconfig, qtbot, tmp_path):
2558
2560
project_dir = tmp_path / 'test-projects-switcher'
2559
2561
project_dir .mkdir ()
2560
2562
2561
- # Create project
2562
- with qtbot .waitSignal (projects .sig_project_loaded ):
2563
- projects .create_project (str (project_dir ))
2564
-
2565
2563
# Create some empty files in the project dir
2566
2564
n_files_project = 3
2567
2565
for i in range (n_files_project ):
2568
2566
fpath = project_dir / f"test_file{ i } .py"
2569
2567
fpath .touch ()
2570
2568
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
+
2571
2579
# Check that the switcher has been populated in Projects
2572
2580
qtbot .waitUntil (
2573
2581
lambda : projects .get_widget ()._default_switcher_paths != [],
@@ -2599,28 +2607,54 @@ def test_switcher_project_files(main_window, pytestconfig, qtbot, tmp_path):
2599
2607
assert switcher .count () == 1
2600
2608
switcher .on_close ()
2601
2609
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
+
2602
2624
# Remove project file and check the switcher is updated
2603
2625
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' ))
2606
2627
qtbot .wait (500 )
2628
+ switcher .open_switcher ()
2607
2629
assert switcher .count () == n_files_open + n_files_project
2608
2630
switcher .on_close ()
2609
2631
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
2611
2634
idx = projects .get_widget ().treewidget .get_index (
2612
- osp . join ( str (project_dir ), 'test_file0.py' )
2635
+ str (project_dir / 'test_file0.py' )
2613
2636
)
2614
2637
projects .get_widget ().treewidget .setCurrentIndex (idx )
2615
-
2616
- # Press Enter there
2617
2638
qtbot .keyClick (projects .get_widget ().treewidget , Qt .Key_Enter )
2618
2639
2619
2640
switcher .open_switcher ()
2620
2641
n_files_open = editorstack .get_stack_count ()
2621
2642
assert switcher .count () == n_files_open + n_files_project - 1
2622
2643
switcher .on_close ()
2623
2644
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
+
2624
2658
# Resume capturing
2625
2659
capmanager .resume_global_capture ()
2626
2660
0 commit comments