18
18
import unittest
19
19
import zipfile
20
20
21
+ from python .runfiles import runfiles
22
+
21
23
22
24
class WheelTest (unittest .TestCase ):
23
25
maxDiff = None
24
26
27
+ def setUp (self ):
28
+ super ().setUp ()
29
+ self .runfiles = runfiles .Create ()
30
+
31
+ def _get_path (self , filename ):
32
+ runfiles_path = os .path .join ("rules_python/examples/wheel" , filename )
33
+ path = self .runfiles .Rlocation (runfiles_path )
34
+ # The runfiles API can return None if the path doesn't exist or
35
+ # can't be resolved.
36
+ if not path :
37
+ raise AssertionError (f"Runfiles failed to resolve { runfiles_path } " )
38
+ elif not os .path .exists (path ):
39
+ # A non-None value doesn't mean the file actually exists, though
40
+ raise AssertionError (
41
+ f"Path { path } does not exist (from runfiles path { runfiles_path } "
42
+ )
43
+ else :
44
+ return path
45
+
25
46
def test_py_library_wheel (self ):
26
- filename = os .path .join (
27
- os .environ ["TEST_SRCDIR" ],
28
- "rules_python" ,
29
- "examples" ,
30
- "wheel" ,
31
- "example_minimal_library-0.0.1-py3-none-any.whl" ,
32
- )
47
+ filename = self ._get_path ("example_minimal_library-0.0.1-py3-none-any.whl" )
33
48
with zipfile .ZipFile (filename ) as zf :
34
49
self .assertEqual (
35
50
zf .namelist (),
@@ -43,11 +58,7 @@ def test_py_library_wheel(self):
43
58
)
44
59
45
60
def test_py_package_wheel (self ):
46
- filename = os .path .join (
47
- os .environ ["TEST_SRCDIR" ],
48
- "rules_python" ,
49
- "examples" ,
50
- "wheel" ,
61
+ filename = self ._get_path (
51
62
"example_minimal_package-0.0.1-py3-none-any.whl" ,
52
63
)
53
64
with zipfile .ZipFile (filename ) as zf :
@@ -65,11 +76,7 @@ def test_py_package_wheel(self):
65
76
)
66
77
67
78
def test_customized_wheel (self ):
68
- filename = os .path .join (
69
- os .environ ["TEST_SRCDIR" ],
70
- "rules_python" ,
71
- "examples" ,
72
- "wheel" ,
79
+ filename = self ._get_path (
73
80
"example_customized-0.0.1-py3-none-any.whl" ,
74
81
)
75
82
with zipfile .ZipFile (filename ) as zf :
@@ -154,31 +161,27 @@ def test_customized_wheel(self):
154
161
)
155
162
156
163
def test_legacy_filename_escaping (self ):
157
- filename = os .path .join (
158
- os .environ ['TEST_SRCDIR' ],
159
- 'rules_python' ,
160
- 'examples' ,
161
- 'wheel' ,
162
- 'file_name_escaping-0.0.1_r7-py3-none-any.whl' ,
164
+ filename = self ._get_path (
165
+ "file_name_escaping-0.0.1_r7-py3-none-any.whl" ,
163
166
)
164
167
with zipfile .ZipFile (filename ) as zf :
165
168
self .assertEquals (
166
169
zf .namelist (),
167
170
[
168
- ' examples/wheel/lib/data.txt' ,
169
- ' examples/wheel/lib/module_with_data.py' ,
170
- ' examples/wheel/lib/simple_module.py' ,
171
- ' examples/wheel/main.py' ,
171
+ " examples/wheel/lib/data.txt" ,
172
+ " examples/wheel/lib/module_with_data.py" ,
173
+ " examples/wheel/lib/simple_module.py" ,
174
+ " examples/wheel/main.py" ,
172
175
# PEP calls for replacing only in the archive filename.
173
176
# Alas setuptools also escapes in the dist-info directory
174
177
# name, so let's be compatible.
175
- ' file_name_escaping-0.0.1_r7.dist-info/WHEEL' ,
176
- ' file_name_escaping-0.0.1_r7.dist-info/METADATA' ,
177
- ' file_name_escaping-0.0.1_r7.dist-info/RECORD' ,
178
+ " file_name_escaping-0.0.1_r7.dist-info/WHEEL" ,
179
+ " file_name_escaping-0.0.1_r7.dist-info/METADATA" ,
180
+ " file_name_escaping-0.0.1_r7.dist-info/RECORD" ,
178
181
],
179
182
)
180
183
metadata_contents = zf .read (
181
- ' file_name_escaping-0.0.1_r7.dist-info/METADATA'
184
+ " file_name_escaping-0.0.1_r7.dist-info/METADATA"
182
185
)
183
186
self .assertEquals (
184
187
metadata_contents ,
@@ -192,11 +195,7 @@ def test_legacy_filename_escaping(self):
192
195
)
193
196
194
197
def test_filename_escaping (self ):
195
- filename = os .path .join (
196
- os .environ ["TEST_SRCDIR" ],
197
- "rules_python" ,
198
- "examples" ,
199
- "wheel" ,
198
+ filename = self ._get_path (
200
199
"file_name_escaping-0.0.1rc1+ubuntu.r7-py3-none-any.whl" ,
201
200
)
202
201
with zipfile .ZipFile (filename ) as zf :
@@ -230,11 +229,7 @@ def test_filename_escaping(self):
230
229
)
231
230
232
231
def test_custom_package_root_wheel (self ):
233
- filename = os .path .join (
234
- os .environ ["TEST_SRCDIR" ],
235
- "rules_python" ,
236
- "examples" ,
237
- "wheel" ,
232
+ filename = self ._get_path (
238
233
"examples_custom_package_root-0.0.1-py3-none-any.whl" ,
239
234
)
240
235
@@ -262,11 +257,7 @@ def test_custom_package_root_wheel(self):
262
257
self .assertFalse (line .startswith ("/" ))
263
258
264
259
def test_custom_package_root_multi_prefix_wheel (self ):
265
- filename = os .path .join (
266
- os .environ ["TEST_SRCDIR" ],
267
- "rules_python" ,
268
- "examples" ,
269
- "wheel" ,
260
+ filename = self ._get_path (
270
261
"example_custom_package_root_multi_prefix-0.0.1-py3-none-any.whl" ,
271
262
)
272
263
@@ -293,11 +284,7 @@ def test_custom_package_root_multi_prefix_wheel(self):
293
284
self .assertFalse (line .startswith ("/" ))
294
285
295
286
def test_custom_package_root_multi_prefix_reverse_order_wheel (self ):
296
- filename = os .path .join (
297
- os .environ ["TEST_SRCDIR" ],
298
- "rules_python" ,
299
- "examples" ,
300
- "wheel" ,
287
+ filename = self ._get_path (
301
288
"example_custom_package_root_multi_prefix_reverse_order-0.0.1-py3-none-any.whl" ,
302
289
)
303
290
@@ -324,11 +311,7 @@ def test_custom_package_root_multi_prefix_reverse_order_wheel(self):
324
311
self .assertFalse (line .startswith ("/" ))
325
312
326
313
def test_python_requires_wheel (self ):
327
- filename = os .path .join (
328
- os .environ ["TEST_SRCDIR" ],
329
- "rules_python" ,
330
- "examples" ,
331
- "wheel" ,
314
+ filename = self ._get_path (
332
315
"example_python_requires_in_a_package-0.0.1-py3-none-any.whl" ,
333
316
)
334
317
with zipfile .ZipFile (filename ) as zf :
@@ -359,11 +342,7 @@ def test_python_abi3_binary_wheel(self):
359
342
"Windows" : "win" ,
360
343
}
361
344
os_string = os_strings [platform .system ()]
362
- filename = os .path .join (
363
- os .environ ["TEST_SRCDIR" ],
364
- "rules_python" ,
365
- "examples" ,
366
- "wheel" ,
345
+ filename = self ._get_path (
367
346
f"example_python_abi3_binary_wheel-0.0.1-cp38-abi3-{ os_string } _{ arch } .whl" ,
368
347
)
369
348
with zipfile .ZipFile (filename ) as zf :
@@ -396,11 +375,7 @@ def test_python_abi3_binary_wheel(self):
396
375
)
397
376
398
377
def test_rule_creates_directory_and_is_included_in_wheel (self ):
399
- filename = os .path .join (
400
- os .environ ["TEST_SRCDIR" ],
401
- "rules_python" ,
402
- "examples" ,
403
- "wheel" ,
378
+ filename = self ._get_path (
404
379
"use_rule_with_dir_in_outs-0.0.1-py3-none-any.whl" ,
405
380
)
406
381
@@ -417,12 +392,8 @@ def test_rule_creates_directory_and_is_included_in_wheel(self):
417
392
)
418
393
419
394
def test_rule_expands_workspace_status_keys_in_wheel_metadata (self ):
420
- filename = os .path .join (
421
- os .environ ["TEST_SRCDIR" ],
422
- "rules_python" ,
423
- "examples" ,
424
- "wheel" ,
425
- "example_minimal_library_BUILD_USER_-0.1._BUILD_TIMESTAMP_-py3-none-any.whl" ,
395
+ filename = self ._get_path (
396
+ "example_minimal_library_BUILD_USER_-0.1._BUILD_TIMESTAMP_-py3-none-any.whl"
426
397
)
427
398
428
399
with zipfile .ZipFile (filename ) as zf :
0 commit comments