FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
pymanager/tests/test_list.py at main · python/pymanager · GitHub
python
pymanager
Repository navigation
Code
Issues
24
(24)
Pull requests
5
(5)
Actions
Security and quality
1
(1)
Insights
Expand file tree
Breadcrumbs
pymanager
/
tests
/
test_list.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
280 lines (234 loc) · 9.23 KB
Breadcrumbs
pymanager
/
tests
/
test_list.py
Copy path
File metadata and controls
280 lines (234 loc) · 9.23 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
import
pytest
import
re
from
itertools
import
zip_longest
from
manage
import
list_command
from
manage
.
indexutils
import
Index
FAKE_INSTALLS
=
[
{
"company"
:
"Company2"
,
"tag"
:
"1.0"
,
"sort-version"
:
"1.0"
},
{
"company"
:
"Company1"
,
"tag"
:
"2.0"
,
"sort-version"
:
"2.0"
},
{
"company"
:
"Company1"
,
"tag"
:
"1.0"
,
"sort-version"
:
"1.0"
,
"default"
:
True
},
]
FAKE_INDEX
=
{
"versions"
: [
{
**
{
k
:
v
for
k
,
v
in
i
.
items
()
if
k
not
in
(
"default"
,)},
"schema"
:
1
,
"id"
:
f"
{
i
[
'company'
]
}
-
{
i
[
'tag'
]
}
"
,
"install-for"
: [
i
[
"tag"
]],
}
for
i
in
FAKE_INSTALLS
]
}
class
ListCapture
:
def
__init__
(
self
):
self
.
args
=
[]
# Out of order on purpose - list_command should not modify order
self
.
installs
=
FAKE_INSTALLS
self
.
captured
=
[]
self
.
source
=
None
self
.
install_dir
=
"<none>"
self
.
default_platform
=
"-64"
self
.
format
=
"test"
self
.
formatter_callable
=
None
self
.
one
=
False
self
.
unmanaged
=
True
list_command
.
FORMATTERS
[
"test"
]
=
lambda
c
,
i
:
self
.
captured
.
extend
(
i
)
def
__call__
(
self
,
*
filters
,
**
kwargs
):
self
.
args
=
filters
for
k
,
v
in
kwargs
.
items
():
if
not
hasattr
(
self
,
k
):
raise
TypeError
(
f"command has no option
{
k
!r
}
"
)
setattr
(
self
,
k
,
v
)
self
.
captured
.
clear
()
list_command
.
execute
(
self
)
return
[
f"
{
i
[
'company'
]
}
/
{
i
[
'tag'
]
}
"
for
i
in
self
.
captured
]
def
get_installs
(
self
,
include_unmanaged
=
False
):
assert
include_unmanaged
==
self
.
unmanaged
return
self
.
installs
@
pytest
.
fixture
def
list_cmd
():
try
:
yield
ListCapture
()
finally
:
list_command
.
FORMATTERS
.
pop
(
"test"
,
None
)
def
test_list
(
list_cmd
):
# list_command does not sort its entries - get_installs() does that
assert
list_cmd
()
==
[
"Company2/1.0"
,
"Company1/2.0"
,
"Company1/1.0"
,
]
# unmanaged doesn't affect our result (because we shim the function that
# does the check), but it'll at least ensure it gets passed through.
assert
list_cmd
(
unmanaged
=
True
)
def
test_list_filter
(
list_cmd
):
assert
list_cmd
(
"2.0"
)
==
[
"Company1/2.0"
]
assert
list_cmd
(
"1.0"
)
==
[
"Company2/1.0"
,
"Company1/1.0"
]
assert
list_cmd
(
"Company1/"
)
==
[
"Company1/2.0"
,
"Company1/1.0"
]
assert
list_cmd
(
"Company1
\\
"
)
==
[
"Company1/2.0"
,
"Company1/1.0"
]
assert
list_cmd
(
"Company
\\
"
)
==
[
"Company2/1.0"
,
"Company1/2.0"
,
"Company1/1.0"
]
assert
list_cmd
(
">1"
)
==
[
"Company1/2.0"
]
assert
list_cmd
(
">=1"
)
==
[
"Company2/1.0"
,
"Company1/2.0"
,
"Company1/1.0"
]
assert
list_cmd
(
"<=2"
)
==
[
"Company2/1.0"
,
"Company1/2.0"
,
"Company1/1.0"
]
assert
list_cmd
(
"<2"
)
==
[
"Company2/1.0"
,
"Company1/1.0"
]
assert
list_cmd
(
"1"
,
"2"
)
==
[
"Company2/1.0"
,
"Company1/2.0"
,
"Company1/1.0"
]
assert
list_cmd
(
"Company1
\\
1"
,
"Company2
\\
1"
)
==
[
"Company2/1.0"
,
"Company1/1.0"
]
def
test_list_one
(
list_cmd
):
assert
list_cmd
(
"2"
,
one
=
True
)
==
[
"Company1/2.0"
]
# Gets Company1/1.0 because it's marked as default
assert
list_cmd
(
"1"
,
one
=
True
)
==
[
"Company1/1.0"
]
def
from_index
(
*
filters
):
return
[
f"
{
i
[
'company'
]
}
/
{
i
[
'tag'
]
}
"
for
i
in
list_command
.
_get_installs_from_index
([
Index
(
"./index.json"
,
FAKE_INDEX
)],
filters
)
]
def
test_list_online
():
assert
from_index
(
"Company1
\\
2.0"
)
==
[
"Company1/2.0"
]
assert
from_index
(
"Company2
\\
"
,
"Company1
\\
1"
)
==
[
"Company2/1.0"
,
"Company1/1.0"
]
assert
from_index
()
==
[
"Company1/2.0"
,
"Company2/1.0"
,
"Company1/1.0"
]
def
test_format_table
(
assert_log
):
list_command
.
format_table
(
None
,
FAKE_INSTALLS
)
assert_log
(
(
r"!B!Tag\s+Name\s+Managed By\s+Version\s+Alias\s*!W!"
, ()),
(
r"Company2\\1\.0\s+Company2\s+1\.0"
, ()),
(
r"Company1\\2\.0\s+Company1\s+2\.0"
, ()),
(
r"!G!Company1\\1\.0\s+\*\s+Company1\s+1\.0\s*!W!"
, ()),
)
def
test_format_table_aliases
(
assert_log
):
list_command
.
format_table
(
None
, [
{
"company"
:
"COMPANY"
,
"tag"
:
"TAG"
,
"display-name"
:
"DISPLAY"
,
"sort-version"
:
"VER"
,
"alias"
: [
{
"name"
:
"python.exe"
},
{
"name"
:
"pythonw.exe"
},
{
"name"
:
"python3.10.exe"
},
{
"name"
:
"pythonw3.10.exe"
},
],
}
])
assert_log
(
(
r"!B!Tag\s+Name\s+Managed By\s+Version\s+Alias\s*!W!"
, ()),
(
r"COMPANY\\TAG\s+DISPLAY\s+COMPANY\s+VER\s+"
+
re
.
escape
(
"python[w].exe, python[w]3.10.exe"
), ()),
)
def
test_format_table_aliases_default_platform
(
assert_log
):
# https://github.com/python/pymanager/issues/407
# Aliases from the online index, in feed order. Each install lists both
# the bare alias and its platform-specific variant; format_table shows
# only the first occurrence of each name, so the -64 install is left
# with lone "-64" names. Those must still render as optional ("[-64]"),
# mirroring how the Tag column marks the default platform.
import
types
def
online_aliases
(
plat
):
return
[
{
"name"
:
"python3.15.exe"
,
"target"
:
"python.exe"
},
{
"name"
:
f"python3.15
{
plat
}
.exe"
,
"target"
:
"python.exe"
},
{
"name"
:
"python3.exe"
,
"target"
:
"python.exe"
},
{
"name"
:
f"python3
{
plat
}
.exe"
,
"target"
:
"python.exe"
},
{
"name"
:
"pythonw3.15.exe"
,
"target"
:
"pythonw.exe"
,
"windowed"
:
1
},
{
"name"
:
f"pythonw3.15
{
plat
}
.exe"
,
"target"
:
"pythonw.exe"
,
"windowed"
:
1
},
{
"name"
:
"pythonw3.exe"
,
"target"
:
"pythonw.exe"
,
"windowed"
:
1
},
{
"name"
:
f"pythonw3
{
plat
}
.exe"
,
"target"
:
"pythonw.exe"
,
"windowed"
:
1
},
]
def
online_install
(
tag
,
plat
):
return
{
"company"
:
"PythonCore"
,
"tag"
:
tag
,
"display-name"
:
"Python 3.15.0rc2"
,
"sort-version"
:
"3.15.0rc2"
,
"alias"
:
online_aliases
(
plat
),
}
cmd
=
types
.
SimpleNamespace
(
default_platform
=
"-64"
)
list_command
.
format_table
(
cmd
, [
online_install
(
"3.15-dev-32"
,
"-32"
),
online_install
(
"3.15-dev-64"
,
"-64"
),
online_install
(
"3.15-dev-arm64"
,
"-arm64"
),
])
assert_log
(
(
r"!B!Tag\s+Name\s+Managed By\s+Version\s+Alias\s*!W!"
, ()),
(
r"3\.15-dev-32.*"
+
re
.
escape
(
"python[w]3-32.exe, python[w]3.15-32.exe"
), ()),
(
r"3\.15-dev\[-64\].*"
+
re
.
escape
(
"python[w]3[-64].exe, python[w]3.15[-64].exe"
), ()),
(
r"3\.15-dev-arm64.*"
+
re
.
escape
(
"python[w]3-arm64.exe, python[w]3.15-arm64.exe"
), ()),
)
def
test_format_table_truncated
(
assert_log
):
list_command
.
format_table
(
None
, [
{
"company"
:
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
*
4
,
"tag"
:
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
*
4
,
"display-name"
:
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
*
4
,
"sort-version"
:
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
*
4
,
"alias"
: [
{
"name"
:
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
*
4
},
],
}
])
assert_log
(
(
r"!B!Tag\s+Name\s+Managed By\s+Version\s+Alias\s*!W!"
, ()),
(
r"\w{27}\.\.\.\s+\w{57}\.\.\.\s+\w{27}\.\.\.\s+\w{12}\.\.\.\s+\w{47}\.\.\."
, ()),
(
r""
, ()),
(
r".+columns were truncated.+"
, ()),
)
def
test_format_table_empty
(
assert_log
):
list_command
.
format_table
(
None
, [])
assert_log
(
(
r"!B!Tag\s+Name\s+Managed By\s+Version\s+Alias\s*!W!"
, ()),
(
r".+No runtimes.+"
, ()),
)
def
test_format_csv
(
assert_log
):
list_command
.
format_csv
(
None
,
FAKE_INSTALLS
)
# CSV format only contains columns that are present, so this doesn't look
# as complete as for normal installs, but it's fine for the test.
assert_log
(
"company,tag,sort-version,default"
,
"Company2,1.0,1.0,"
,
"Company1,2.0,2.0,"
,
"Company1,1.0,1.0,True"
,
)
def
test_format_csv_complex
(
assert_log
):
data
=
[
{
**
d
,
"alias"
: [
dict
(
name
=
f"n
{
i
}
.
{
j
}
"
,
target
=
f"t
{
i
}
.
{
j
}
"
)
for
j
in
range
(
i
+
1
)]
}
for
i
,
d
in
enumerate
(
FAKE_INSTALLS
)
]
list_command
.
format_csv
(
None
,
data
)
assert_log
(
"company,tag,sort-version,alias.name,alias.target.default"
,
"Company2,1.0,1.0,n0.0,t0.0,"
,
"Company1,2.0,2.0,n1.0,t1.0,"
,
"Company1,2.0,2.0,n1.1,t1.1,"
,
"Company1,1.0,1.0,n2.0,t2.0,True"
,
"Company1,1.0,1.0,n2.1,t2.1,True"
,
"Company1,1.0,1.0,n2.2,t2.2,True"
,
)
def
test_format_csv_empty
(
assert_log
):
list_command
.
format_csv
(
None
, [])
assert_log
(
assert_log
.
end_of_log
())
def
test_csv_exclude
():
result
=
list
(
list_command
.
_csv_filter_and_expand
([
dict
(
a
=
1
,
b
=
2
),
dict
(
a
=
3
,
c
=
4
),
dict
(
a
=
5
,
b
=
6
,
c
=
7
),
],
exclude
=
{
"b"
}))
assert
result
==
[
dict
(
a
=
1
),
dict
(
a
=
3
,
c
=
4
),
dict
(
a
=
5
,
c
=
7
)]
def
test_csv_expand
():
result
=
list
(
list_command
.
_csv_filter_and_expand
([
dict
(
a
=
[
1
,
2
],
b
=
[
3
,
4
]),
dict
(
a
=
[
5
],
b
=
[
6
]),
dict
(
a
=
7
,
b
=
8
),
],
expand
=
{
"a"
}))
assert
result
==
[
dict
(
a
=
1
,
b
=
[
3
,
4
]),
dict
(
a
=
2
,
b
=
[
3
,
4
]),
dict
(
a
=
5
,
b
=
[
6
]),
dict
(
a
=
7
,
b
=
8
),
]
def
test_formats
(
assert_log
):
list_command
.
list_formats
(
None
, [
"fake"
,
"installs"
,
"that"
,
"should"
,
"crash"
,
123
])
assert_log
(
r".*Format\s+Description"
,
r"table\s+Lists.+"
,
# Assume the rest are okay
)
Back
|
FazBrowse Home
|
New Git URL