FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
pymanager/tests/test_uninstall_command.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_uninstall_command.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
211 lines (164 loc) · 5.83 KB
Breadcrumbs
pymanager
/
tests
/
test_uninstall_command.py
Copy path
File metadata and controls
211 lines (164 loc) · 5.83 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
import
os
import
pytest
import
winreg
from
pathlib
import
Path
from
manage
import
uninstall_command
as
UC
from
manage
.
exceptions
import
ArgumentError
,
FilesInUseError
def
test_purge_global_dir
(
monkeypatch
,
registry
,
tmp_path
):
registry
.
setup
(
Path
=
rf"C:\A;
{
tmp_path
}
\X;
{
tmp_path
}
;C:\B;%PTH%;C:\%D%\E"
)
(
tmp_path
/
"test.txt"
).
write_bytes
(
b""
)
(
tmp_path
/
"test2.txt"
).
write_bytes
(
b""
)
monkeypatch
.
setitem
(
os
.
environ
,
"PTH"
,
str
(
tmp_path
))
UC
.
_do_purge_global_dir
(
tmp_path
,
"SLOW WARNING"
,
hive
=
registry
.
hive
,
subkey
=
registry
.
root
)
assert
registry
.
getvalueandkind
(
""
,
"Path"
)
==
(
rf"C:\A;
{
tmp_path
}
\X;C:\B;%PTH%;C:\%D%\E"
,
winreg
.
REG_SZ
)
assert
not
tmp_path
.
is_dir
()
or
not
list
(
tmp_path
.
iterdir
())
def
test_null_purge
(
fake_config
):
cmd
=
fake_config
cmd
.
args
=
[]
cmd
.
confirm
=
False
cmd
.
purge
=
True
cmd
.
cleanup
=
False
UC
.
execute
(
cmd
)
def
test_purge_unknown_files
(
fake_config
):
cmd
=
fake_config
cmd
.
args
=
[]
cmd
.
confirm
=
False
cmd
.
purge
=
True
cmd
.
cleanup
=
False
unknown_file
=
cmd
.
install_dir
/
"unknown.txt"
unknown_file
.
write_bytes
(
b"unknown"
)
broken_runtime
=
cmd
.
install_dir
/
"broken-runtime"
broken_runtime
.
mkdir
()
(
broken_runtime
/
"__install__.json"
).
write_text
(
"invalid"
)
UC
.
execute
(
cmd
)
assert
not
unknown_file
.
exists
()
assert
not
broken_runtime
.
exists
()
def
test_purge_preserves_runtime_in_use
(
fake_config
,
monkeypatch
):
cmd
=
fake_config
cmd
.
args
=
[]
cmd
.
confirm
=
False
cmd
.
purge
=
True
cmd
.
cleanup
=
False
runtime
=
cmd
.
install_dir
/
"runtime"
runtime
.
mkdir
()
executable
=
runtime
/
"python.exe"
executable
.
write_bytes
(
b"in use"
)
cmd
.
installs
=
[{
"display-name"
:
"Runtime in use"
,
"prefix"
:
runtime
,
}]
unknown_dir
=
cmd
.
install_dir
/
"unknown"
unknown_dir
.
mkdir
()
(
unknown_dir
/
"file.txt"
).
write_bytes
(
b"unknown"
)
rmtree
=
UC
.
rmtree
def
locked_rmtree
(
path
,
*
args
,
**
kwargs
):
if
Path
(
path
)
==
runtime
:
raise
FilesInUseError
([
executable
])
return
rmtree
(
path
,
*
args
,
**
kwargs
)
monkeypatch
.
setattr
(
UC
,
"rmtree"
,
locked_rmtree
)
UC
.
execute
(
cmd
)
assert
executable
.
is_file
()
assert
not
unknown_dir
.
exists
()
def
test_cleanup_preserves_recognized_runtimes
(
fake_config
,
monkeypatch
):
cmd
=
fake_config
cmd
.
args
=
[]
cmd
.
purge
=
False
cmd
.
cleanup
=
True
runtime
=
cmd
.
install_dir
/
"runtime"
runtime
.
mkdir
()
executable
=
runtime
/
"python.exe"
executable
.
write_bytes
(
b"preserve"
)
cmd
.
installs
=
[{
"display-name"
:
"Recognized runtime"
,
"prefix"
:
runtime
,
}]
cmd
.
download_dir
.
mkdir
()
cached_file
=
cmd
.
download_dir
/
"cached.zip"
cached_file
.
write_bytes
(
b"cached"
)
unknown_file
=
cmd
.
install_dir
/
"unknown.txt"
unknown_file
.
write_bytes
(
b"unknown"
)
broken_runtime
=
cmd
.
install_dir
/
"broken-runtime"
broken_runtime
.
mkdir
()
(
broken_runtime
/
"__install__.json"
).
write_text
(
"invalid"
)
prompts
=
[]
cmd
.
ask_yn
=
lambda
prompt
:
prompts
.
append
(
prompt
)
or
True
refreshed
=
[]
monkeypatch
.
setattr
(
UC
,
"update_all_shortcuts"
,
refreshed
.
append
)
UC
.
execute
(
cmd
)
assert
prompts
==
[
"Clean up cached files and unrecognized content? "
"This will preserve recognized runtimes."
]
assert
executable
.
read_bytes
()
==
b"preserve"
assert
not
cmd
.
download_dir
.
exists
()
assert
not
unknown_file
.
exists
()
assert
not
broken_runtime
.
exists
()
assert
refreshed
==
[
cmd
]
def
test_cleanup_shared_download_dir_preserves_recognized_runtimes
(
fake_config
,
monkeypatch
):
cmd
=
fake_config
cmd
.
args
=
[]
cmd
.
purge
=
False
cmd
.
cleanup
=
True
cmd
.
download_dir
=
cmd
.
install_dir
runtime
=
cmd
.
install_dir
/
"runtime"
runtime
.
mkdir
()
executable
=
runtime
/
"python.exe"
executable
.
write_bytes
(
b"preserve"
)
cmd
.
installs
=
[{
"display-name"
:
"Recognized runtime"
,
"prefix"
:
runtime
,
}]
cached_file
=
cmd
.
download_dir
/
"cached.zip"
cached_file
.
write_bytes
(
b"cached"
)
unknown_dir
=
cmd
.
install_dir
/
"unknown"
unknown_dir
.
mkdir
()
cmd
.
ask_yn
=
lambda
prompt
:
True
refreshed
=
[]
monkeypatch
.
setattr
(
UC
,
"update_all_shortcuts"
,
refreshed
.
append
)
UC
.
execute
(
cmd
)
assert
executable
.
read_bytes
()
==
b"preserve"
assert
not
cached_file
.
exists
()
assert
not
unknown_dir
.
exists
()
assert
refreshed
==
[
cmd
]
def
test_cleanup_declined_preserves_all_files
(
fake_config
,
monkeypatch
):
cmd
=
fake_config
cmd
.
args
=
[]
cmd
.
purge
=
False
cmd
.
cleanup
=
True
cmd
.
download_dir
.
mkdir
()
cached_file
=
cmd
.
download_dir
/
"cached.zip"
cached_file
.
write_bytes
(
b"cached"
)
unknown_file
=
cmd
.
install_dir
/
"unknown.txt"
unknown_file
.
write_bytes
(
b"unknown"
)
prompts
=
[]
cmd
.
ask_yn
=
lambda
prompt
:
prompts
.
append
(
prompt
)
or
False
monkeypatch
.
setattr
(
UC
,
"update_all_shortcuts"
,
lambda
cmd
:
pytest
.
fail
(
"shortcuts refreshed after cleanup was declined"
),
)
UC
.
execute
(
cmd
)
assert
prompts
==
[
"Clean up cached files and unrecognized content? "
"This will preserve recognized runtimes."
]
assert
cached_file
.
read_bytes
()
==
b"cached"
assert
unknown_file
.
read_bytes
()
==
b"unknown"
@
pytest
.
mark
.
parametrize
(
"option"
, [
"purge"
,
"cleanup"
])
def
test_global_uninstall_options_reject_tags
(
fake_config
,
option
):
cmd
=
fake_config
cmd
.
args
=
[
"3.14"
]
cmd
.
purge
=
option
==
"purge"
cmd
.
cleanup
=
option
==
"cleanup"
with
pytest
.
raises
(
ArgumentError
,
match
=
"does not accept runtime tags"
):
UC
.
execute
(
cmd
)
def
test_purge_and_cleanup_are_mutually_exclusive
(
fake_config
):
cmd
=
fake_config
cmd
.
args
=
[]
cmd
.
purge
=
True
cmd
.
cleanup
=
True
with
pytest
.
raises
(
ArgumentError
,
match
=
"cannot be combined"
):
UC
.
execute
(
cmd
)
Back
|
FazBrowse Home
|
New Git URL