3
3
import pytest
4
4
from pytest_pyodide import run_in_pyodide , spawn_web_server
5
5
from conftest import SNOWBALL_WHEEL , TEST_WHEEL_DIR
6
- from packaging .utils import parse_wheel_filename
6
+ from packaging .utils import parse_wheel_filename , canonicalize_name
7
7
8
8
TEST_PACKAGE_NAME = "test_wheel_uninstall"
9
+ TEST_PACKAGE_NAME_NORMALIZED = canonicalize_name (TEST_PACKAGE_NAME )
9
10
10
11
11
12
@pytest .fixture (scope = "module" )
@@ -19,15 +20,15 @@ def test_wheel_url(test_wheel_path):
19
20
20
21
def test_basic (selenium_standalone_micropip , test_wheel_url ):
21
22
@run_in_pyodide ()
22
- async def run (selenium , pkg_name , wheel_url ):
23
+ async def run (selenium , pkg_name , pkg_name_normalized , wheel_url ):
23
24
import importlib .metadata
24
25
import sys
25
26
26
27
import micropip
27
28
28
29
await micropip .install (wheel_url )
29
30
30
- assert pkg_name in micropip .list ()
31
+ assert pkg_name_normalized in micropip .list ()
31
32
assert pkg_name not in sys .modules
32
33
33
34
__import__ (pkg_name )
@@ -52,7 +53,12 @@ async def run(selenium, pkg_name, wheel_url):
52
53
# 3. Check that the module is not available with micropip.list()
53
54
assert pkg_name not in micropip .list ()
54
55
55
- run (selenium_standalone_micropip , TEST_PACKAGE_NAME , test_wheel_url )
56
+ run (
57
+ selenium_standalone_micropip ,
58
+ TEST_PACKAGE_NAME ,
59
+ TEST_PACKAGE_NAME_NORMALIZED ,
60
+ test_wheel_url ,
61
+ )
56
62
57
63
58
64
def test_files (selenium_standalone_micropip , test_wheel_url ):
@@ -61,13 +67,13 @@ def test_files(selenium_standalone_micropip, test_wheel_url):
61
67
"""
62
68
63
69
@run_in_pyodide ()
64
- async def run (selenium , pkg_name , wheel_url ):
70
+ async def run (selenium , pkg_name , pkg_name_normalized , wheel_url ):
65
71
import importlib .metadata
66
72
67
73
import micropip
68
74
69
75
await micropip .install (wheel_url )
70
- assert pkg_name in micropip .list ()
76
+ assert pkg_name_normalized in micropip .list ()
71
77
72
78
dist = importlib .metadata .distribution (pkg_name )
73
79
files = dist .files
@@ -86,7 +92,12 @@ async def run(selenium, pkg_name, wheel_url):
86
92
87
93
assert not dist ._path .is_dir (), f"{ dist ._path } still exists after removal"
88
94
89
- run (selenium_standalone_micropip , TEST_PACKAGE_NAME , test_wheel_url )
95
+ run (
96
+ selenium_standalone_micropip ,
97
+ TEST_PACKAGE_NAME ,
98
+ TEST_PACKAGE_NAME_NORMALIZED ,
99
+ test_wheel_url ,
100
+ )
90
101
91
102
92
103
def test_install_again (selenium_standalone_micropip , test_wheel_url ):
@@ -95,20 +106,20 @@ def test_install_again(selenium_standalone_micropip, test_wheel_url):
95
106
"""
96
107
97
108
@run_in_pyodide ()
98
- async def run (selenium , pkg_name , wheel_url ):
109
+ async def run (selenium , pkg_name , pkg_name_normalized , wheel_url ):
99
110
import sys
100
111
101
112
import micropip
102
113
103
114
await micropip .install (wheel_url )
104
115
105
- assert pkg_name in micropip .list ()
116
+ assert pkg_name_normalized in micropip .list ()
106
117
107
118
__import__ (pkg_name )
108
119
109
120
micropip .uninstall (pkg_name )
110
121
111
- assert pkg_name not in micropip .list ()
122
+ assert pkg_name_normalized not in micropip .list ()
112
123
113
124
del sys .modules [pkg_name ]
114
125
@@ -121,10 +132,15 @@ async def run(selenium, pkg_name, wheel_url):
121
132
122
133
await micropip .install (wheel_url )
123
134
124
- assert pkg_name in micropip .list ()
135
+ assert pkg_name_normalized in micropip .list ()
125
136
__import__ (pkg_name )
126
137
127
- run (selenium_standalone_micropip , TEST_PACKAGE_NAME , test_wheel_url )
138
+ run (
139
+ selenium_standalone_micropip ,
140
+ TEST_PACKAGE_NAME ,
141
+ TEST_PACKAGE_NAME_NORMALIZED ,
142
+ test_wheel_url ,
143
+ )
128
144
129
145
130
146
def test_warning_not_installed (selenium_standalone_micropip ):
@@ -156,7 +172,7 @@ def test_warning_file_removed(selenium_standalone_micropip, test_wheel_url):
156
172
"""
157
173
158
174
@run_in_pyodide ()
159
- async def run (selenium , pkg_name , wheel_url ):
175
+ async def run (selenium , pkg_name , pkg_name_normalized , wheel_url ):
160
176
from importlib .metadata import distribution
161
177
import micropip
162
178
import contextlib
@@ -165,17 +181,17 @@ async def run(selenium, pkg_name, wheel_url):
165
181
with io .StringIO () as buf , contextlib .redirect_stdout (buf ):
166
182
await micropip .install (wheel_url )
167
183
168
- assert pkg_name in micropip .list ()
184
+ assert pkg_name_normalized in micropip .list ()
169
185
170
- dist = distribution (pkg_name )
186
+ dist = distribution (pkg_name_normalized )
171
187
files = dist .files
172
188
file1 = files [0 ]
173
189
file2 = files [1 ]
174
190
175
191
file1 .locate ().unlink ()
176
192
file2 .locate ().unlink ()
177
193
178
- micropip .uninstall (pkg_name )
194
+ micropip .uninstall (pkg_name_normalized )
179
195
180
196
captured = buf .getvalue ()
181
197
logs = captured .strip ().split ("\n " )
@@ -184,7 +200,12 @@ async def run(selenium, pkg_name, wheel_url):
184
200
assert "does not exist" in logs [- 1 ]
185
201
assert "does not exist" in logs [- 2 ]
186
202
187
- run (selenium_standalone_micropip , TEST_PACKAGE_NAME , test_wheel_url )
203
+ run (
204
+ selenium_standalone_micropip ,
205
+ TEST_PACKAGE_NAME ,
206
+ TEST_PACKAGE_NAME_NORMALIZED ,
207
+ test_wheel_url ,
208
+ )
188
209
189
210
190
211
def test_warning_remaining_file (selenium_standalone_micropip , test_wheel_url ):
@@ -193,28 +214,33 @@ def test_warning_remaining_file(selenium_standalone_micropip, test_wheel_url):
193
214
"""
194
215
195
216
@run_in_pyodide ()
196
- async def run (selenium , pkg_name , wheel_url ):
217
+ async def run (selenium , pkg_name , pkg_name_normalized , wheel_url ):
197
218
from importlib .metadata import distribution
198
219
import micropip
199
220
import contextlib
200
221
import io
201
222
202
223
with io .StringIO () as buf , contextlib .redirect_stdout (buf ):
203
224
await micropip .install (wheel_url )
204
- assert pkg_name in micropip .list ()
225
+ assert pkg_name_normalized in micropip .list ()
205
226
206
- pkg_dir = distribution (pkg_name )._path .parent / "deep"
227
+ pkg_dir = distribution (pkg_name_normalized )._path .parent / "deep"
207
228
(pkg_dir / "extra-file.txt" ).touch ()
208
229
209
- micropip .uninstall (pkg_name )
230
+ micropip .uninstall (pkg_name_normalized )
210
231
211
232
captured = buf .getvalue ()
212
233
logs = captured .strip ().split ("\n " )
213
234
214
235
assert len (logs ) == 1
215
236
assert "is not empty after uninstallation" in logs [0 ]
216
237
217
- run (selenium_standalone_micropip , TEST_PACKAGE_NAME , test_wheel_url )
238
+ run (
239
+ selenium_standalone_micropip ,
240
+ TEST_PACKAGE_NAME ,
241
+ TEST_PACKAGE_NAME_NORMALIZED ,
242
+ test_wheel_url ,
243
+ )
218
244
219
245
220
246
def test_pyodide_repodata (selenium_standalone_micropip ):
0 commit comments