-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathtest_exclusive_paths.py
212 lines (174 loc) · 4.28 KB
/
test_exclusive_paths.py
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
#!/usr/bin/env python3
# I hate this but i don't want to make it a pip package, its a script.
import sys
from typing import List, Optional, Tuple
from dataclasses import dataclass
sys.path.append('scripts/')
from path_utils import get_exclusive_paths, Pane
@dataclass
class FakePane:
pane_current_path: str | None
def _fake_pane(path: str, program: Optional[str]):
return Pane(FakePane(path), program)
def _check(expected: List[Tuple[str, Optional[str], str]]):
"""check expected displayed paths
Args:
expected (List[Tuple[str, Optional[str], str]]): list of (full_path, program, expected_display)
E.g:
_check([
('a/dir', 'p1', 'dir'), # Program p1 in a/dir will display dir (will be formated to p1:dir)
('b/dir', None, 'b/dir'), # Shell in b/dir will display b/dir
('c/dir', None', 'c/dir'), # Shell in c/dir will display c/dir
])
"""
panes = [_fake_pane(full, program) for full, program, _ in expected]
exclusive_panes = get_exclusive_paths(panes)
for (full, _, expected_display), (_, display) in zip(expected, exclusive_panes):
assert str(display) == expected_display
def test_not_intersect():
_check(
[
('a/a_dir', None, 'a_dir'),
('b/b_dir', None, 'b_dir'),
]
)
_check(
[
('a', None, 'a'),
('b', None, 'b'),
]
)
_check(
[
('a', None, 'a'),
('b', None, 'b'),
('c', None, 'c'),
]
)
def test_basic_intersect():
_check(
[
('a/dir', None, 'a/dir'),
('b/dir', None, 'b/dir'),
]
)
def test_not_same_length():
_check(
[
('a/b/dir', None, 'a/b/dir'),
('b/dir', None, 'b/dir'),
]
)
def test_reacurring_dir():
_check(
[
('a/dir', None, 'a/dir'),
('b/dir', None, 'b/dir'),
('c/dir', None, 'c/dir'),
]
)
def test_same_path_twice_dir():
_check(
[
('a/dir', None, 'a/dir'),
('a/dir', None, 'a/dir'),
('b/dir', None, 'b/dir'),
]
)
_check(
[
('a/dir', None, 'a/dir'),
('b/dir', None, 'b/dir'),
('a/dir', None, 'a/dir'),
]
)
_check(
[
('a/dir', None, 'a/dir'),
('b/dir', None, 'b/dir'),
('b/dir', None, 'b/dir'),
('a/dir', None, 'a/dir'),
]
)
_check(
[
('a/dir', None, 'a/dir'),
('b/dir', None, 'b/dir'),
('a/dir', None, 'a/dir'),
('b/dir', None, 'b/dir'),
]
)
_check(
[
('a/dir', None, 'a/dir'),
('b/dir', None, 'b/dir'),
('c/dir', None, 'c/dir'),
('a/dir', None, 'a/dir'),
('b/dir', None, 'b/dir'),
('c/dir', None, 'c/dir'),
]
)
def test_mixed_basic():
_check(
[
('a/dir', None, 'a/dir'),
('b/dir', None, 'b/dir'),
('c/c_dir', None, 'c_dir'),
]
)
_check(
[
('a/b/c/d', None, 'a/b/c/d'),
('b/c/d', None, 'b/c/d'),
('dirrr', None, 'dirrr'),
]
)
def test_program_basic():
_check(
[
('a/dir', 'p1', 'dir'),
('b/dir', None, 'dir'),
]
)
_check(
[
('a/dir', 'p1', 'dir'),
('b/dir', 'p2', 'dir'),
]
)
_check(
[
('a/dir', 'p1', 'a/dir'),
('b/dir', 'p1', 'b/dir'),
]
)
_check(
[
('a/dir', 'p1', 'dir'),
('b/dir', 'p2', 'dir'),
]
)
def test_program_mixed():
_check(
[
('a/dir', 'p1', 'dir'),
('b/dir', None, 'dir'),
('c/dir', 'p2', 'dir'),
]
)
_check(
[
('a/dir', 'p1', 'dir'),
('b/dir', None, 'dir'),
('a/dir', 'p1', 'dir'),
('c/dir', 'p2', 'dir'),
]
)
_check(
[
('a/dir', 'p1', 'a/dir'),
('b/dir', 'p1', 'b/dir'),
('a/dir', 'p1', 'a/dir'),
('c/dir', 'p2', 'dir'),
]
)