Repository: spyder-ide/spyder

Issue:
Search is broken in file switcher and produces exception due to indentation error
<!--- **PLEASE READ:** When submitting here, please ensure you've completed the following checklist and checked the boxes to confirm. Issue reports without it may be closed. Thanks! --->

## Problem Description

Search doesn't work in the File Switcher. The cause appears to be a simple indentation error.

### What steps reproduce the problem?

1. Open fileswitcher (``Ctrl-P`` by default)
2. Type some text that should match
3. Search only matches certain letters, then fails completely with an exception



### Paste Traceback/Error Below (if applicable)
<!--- Copy from error dialog or View > Panes > Internal Console --->

```python-traceback
Traceback (most recent call last):
  File "C:\Users\C. A. M. Gerlach\Documents\dev\SpyderDev\spyder\spyder\widgets\fileswitcher.py", line 903, in setup
    self.setup_file_list(filter_text, current_path)
  File "C:\Users\C. A. M. Gerlach\Documents\dev\SpyderDev\spyder\spyder\widgets\fileswitcher.py", line 761, in setup_file_list
    width=self._MIN_WIDTH, height=self._HEIGHT, title=fileName,
UnboundLocalError: local variable 'fileName' referenced before assignment
```

## Versions
<!--- You can get this information from Help > About Spyder...
or (if Spyder won't launch) the "conda list" command
from the Anaconda Prompt/Terminal/command line. --->

* Spyder version: master ``01720a8563``
* Python version: 3.7
* Qt version: 5.9.7
* PyQt version: 5.9.2
* Operating System name/version: Windows 8.1 x64


Discussion:

Resolving patch:
diff --git a/spyder/widgets/fileswitcher.py b/spyder/widgets/fileswitcher.py
--- a/spyder/widgets/fileswitcher.py
+++ b/spyder/widgets/fileswitcher.py
@@ -757,14 +757,14 @@ def setup_file_list(self, filter_text, current_path):
                 title = self.widgets[index][1].get_plugin_title().split(
                     ' - ')[0]
 
-            text_item = self._TEMPLATE.format(
-                width=self._MIN_WIDTH, height=self._HEIGHT, title=fileName,
-                section=title, description=path, padding=self._PADDING,
-                shortcut=linecount, **self._STYLES)
-
-            if (trying_for_line_number and self.line_count[index] != 0 or
-                    not trying_for_line_number):
-                results.append((score_value, index, text_item))
+                text_item = self._TEMPLATE.format(
+                    width=self._MIN_WIDTH, height=self._HEIGHT, title=fileName,
+                    section=title, description=path, padding=self._PADDING,
+                    shortcut=linecount, **self._STYLES)
+
+                if ((trying_for_line_number and self.line_count[index] != 0)
+                        or not trying_for_line_number):
+                    results.append((score_value, index, text_item))
 
         # Sort the obtained scores and populate the list widget
         self.filtered_path = []


Test patch:
diff --git a/spyder/app/tests/test_mainwindow.py b/spyder/app/tests/test_mainwindow.py
--- a/spyder/app/tests/test_mainwindow.py
+++ b/spyder/app/tests/test_mainwindow.py
@@ -1629,31 +1629,47 @@ def test_tight_layout_option_for_inline_plot(main_window, qtbot, tmpdir):
 
 
 @pytest.mark.slow
-@pytest.mark.skipif(not sys.platform.startswith('linux'),
-                    reason="Doesn't run correctly on Windows and macOS")
 def test_fileswitcher(main_window, qtbot, tmpdir):
     """Test the use of shorten paths when necessary in the fileswitcher."""
+    fileswitcher = main_window.fileswitcher
+
     # Assert that the full path of a file is shown in the fileswitcher
-    file_a = tmpdir.join("a.py")
-    file_a.write('foo')
+    file_a = tmpdir.join('test_file_a.py')
+    file_a.write('foo\n')
     main_window.editor.load(str(file_a))
 
     main_window.open_fileswitcher()
-    item_text = main_window.fileswitcher.list.currentItem().text()
-    assert str(file_a) in item_text
+    fileswitcher_paths = fileswitcher.paths
+    assert file_a in fileswitcher_paths
+    fileswitcher.close()
 
     # Assert that long paths are shortened in the fileswitcher
     dir_b = tmpdir
     for _ in range(3):
         dir_b = dir_b.mkdir(str(uuid.uuid4()))
-    file_b = dir_b.join("b.py")
-    file_b.write('bar')
+    file_b = dir_b.join('test_file_b.py')
+    file_b.write('bar\n')
     main_window.editor.load(str(file_b))
 
-    main_window.fileswitcher.close()
     main_window.open_fileswitcher()
-    item_text = main_window.fileswitcher.list.currentItem().text()
-    assert '...' in item_text
+    file_b_text = fileswitcher.list.item(
+        fileswitcher.list.count() - 1).text()
+    assert '...' in file_b_text
+    fileswitcher.close()
+
+    # Assert search works correctly
+    search_texts = ['test_file_a', 'file_b', 'foo_spam']
+    expected_paths = [file_a, file_b, None]
+    for search_text, expected_path in zip(search_texts, expected_paths):
+        main_window.open_fileswitcher()
+        qtbot.keyClicks(fileswitcher.edit, search_text)
+        qtbot.wait(200)
+        assert fileswitcher.count() == 2 * bool(expected_path)
+        if expected_path:
+            assert fileswitcher.filtered_path[0] == expected_path
+        else:
+            assert not fileswitcher.filtered_path
+        fileswitcher.close()
 
 
 @pytest.mark.slow