Repository: spyder-ide/spyder

Issue:
A file switcher test is failing on master
`pytest spyder/app/tests/test_mainwindow.py::test_switcher --run-slow`

```bash
____________________________________________________ test_switcher ____________________________________________________

main_window = <spyder.app.mainwindow.MainWindow object at 0x000001D13D94B3A8>
qtbot = <pytestqt.qtbot.QtBot object at 0x000001D13D7E29B0>
tmpdir = local('C:\\Users\\user\\AppData\\Local\\Temp\\pytest-of-user\\pytest-7\\test_switcher0')

    @pytest.mark.slow
    def test_switcher(main_window, qtbot, tmpdir):
        """Test the use of shorten paths when necessary in the switcher."""
        switcher = main_window.switcher

        # Assert that the full path of a file is shown in the switcher
        file_a = tmpdir.join('test_file_a.py')
        file_a.write('''
    def example_def():
        pass

    def example_def_2():
        pass
    ''')
        main_window.editor.load(str(file_a))

        main_window.open_switcher()
        switcher_paths = [switcher.model.item(item_idx).get_description()
                          for item_idx in range(switcher.model.rowCount())]
        print(switcher_paths)
        print(osp.dirname(str(file_a)))
>       assert osp.dirname(str(file_a)) in switcher_paths or len(str(file_a)) > 90
E       AssertionError: assert ('C:\\Users\\user\\AppData\\Local\\Temp\\pytest-of-user\\pytest-7\\test_switcher0' in ['c:\\users\\user\\appdata\\local\\temp\\pytest-spyder\\.spyder-py3-dev', '...c:\\...\\temp\\pytest-of-user...\\test_switcher0'] or 86 > 90)
E        +  where 'C:\\Users\\user\\AppData\\Local\\Temp\\pytest-of-user\\pytest-7\\test_switcher0' = <function dirname at 0x000001D1335448C8>('C:\\Users\\user\\AppData\\Local\\Temp\\pytest-of-user\\pytest-7\\test_switcher0\\test_file_a.py')
E        +    where <function dirname at 0x000001D1335448C8> = osp.dirname
E        +    and   'C:\\Users\\user\\AppData\\Local\\Temp\\pytest-of-user\\pytest-7\\test_switcher0\\test_file_a.py' = str(local('C:\\Users\\user\\AppData\\Local\\Temp\\pytest-of-user\\pytest-7\\test_switcher0\\test_file_a.py'))
E        +  and   86 = len('C:\\Users\\user\\AppData\\Local\\Temp\\pytest-of-user\\pytest-7\\test_switcher0\\test_file_a.py')
E        +    where 'C:\\Users\\user\\AppData\\Local\\Temp\\pytest-of-user\\pytest-7\\test_switcher0\\test_file_a.py' = str(local('C:\\Users\\user\\AppData\\Local\\Temp\\pytest-of-user\\pytest-7\\test_switcher0\\test_file_a.py'))

develop\spyder\spyder\app\tests\test_mainwindow.py:1662: AssertionError
```


Discussion:

Resolving patch:
diff --git a/spyder/utils/switcher.py b/spyder/utils/switcher.py
--- a/spyder/utils/switcher.py
+++ b/spyder/utils/switcher.py
@@ -119,9 +119,13 @@ def recurse_level(level_idx):
     recurse_level({i: pl for i, pl in enumerate(path_list) if pl})
 
     if common_prefix:
-        result_paths = ["...{}".format(
-                        path.rstrip(os.sep).split(common_prefix)[-1])
-                        for path in new_path_list]
+        result_paths = []
+        for path in new_path_list:
+            path_elements = path.rstrip(os.sep).split(common_prefix)
+            if len(path_elements) > 1:
+                result_paths.append("...{}".format(path_elements[-1]))
+            else:
+                result_paths.append(path)
     else:
         result_paths = [path.rstrip(os.sep) for path in new_path_list]
 


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
@@ -1657,7 +1657,7 @@ def example_def_2():
     main_window.open_switcher()
     switcher_paths = [switcher.model.item(item_idx).get_description()
                       for item_idx in range(switcher.model.rowCount())]
-    assert osp.dirname(str(file_a)) in switcher_paths or len(str(file_a)) > 90
+    assert osp.dirname(str(file_a)) in switcher_paths or len(str(file_a)) > 75
     switcher.close()
 
     # Assert that long paths are shortened in the switcher