forked from jorio/gitfourchette
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_pathutils.py
More file actions
61 lines (54 loc) · 1.88 KB
/
Copy pathtest_pathutils.py
File metadata and controls
61 lines (54 loc) · 1.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# -----------------------------------------------------------------------------
# Copyright (C) 2026 Iliyas Jorio.
# This file is part of GitFourchette, distributed under the GNU GPL v3.
# For full terms, see the included LICENSE file.
# -----------------------------------------------------------------------------
import os
from pathlib import Path
import pytest
from gitfourchette.toolbox.pathutils import HOME, disambiguateTabTitlesByPath
def _tabLabel(*parts: str) -> str:
if len(parts) == 2:
return str(Path(*parts))
return str(Path(parts[0], "…", parts[-1]))
@pytest.mark.parametrize(
"workdirs, labels",
[
pytest.param(
["/work/a/app", "/work/b/app"],
[("a", "app"), ("b", "app")],
id="adjacent-parent",
),
pytest.param(
["/w/a/app", "/w/b/app", "/w/c/app"],
[("a", "app"), ("b", "app"), ("c", "app")],
id="three-tabs",
),
pytest.param(
["/a/x/y/repo", "/b/x/y/repo"],
[("a", "…", "repo"), ("b", "…", "repo")],
id="middle-ellipsis",
),
pytest.param(
[
os.path.join(HOME, "nested", "app"),
os.path.abspath("/work/nested/app"),
],
[("~", "…", "app"), ("work", "…", "app")],
id="home-vs-absolute",
),
pytest.param(
["/a/foo/app", "/b/foo/app"],
[("a", "…", "app"), ("b", "…", "app")],
id="shared-intermediate",
),
pytest.param(
["/x/foo/v1/app", "/x/bar/v1/app"],
[("foo", "…", "app"), ("bar", "…", "app")],
id="deeper-disambiguator",
),
],
)
def testDisambiguateTabTitlesByPath(workdirs, labels):
expected = [_tabLabel(*parts) for parts in labels]
assert disambiguateTabTitlesByPath(workdirs) == expected