|
1 | 1 | from __future__ import annotations
|
2 | 2 |
|
| 3 | +import csv |
3 | 4 | import os
|
4 | 5 | import platform
|
5 | 6 | import re
|
@@ -47,7 +48,7 @@ def clear_samples_dist() -> None:
|
47 | 48 | or platform.python_implementation().lower() == "pypy",
|
48 | 49 | reason="Disable test on Windows for Python <=3.6 and for PyPy",
|
49 | 50 | )
|
50 |
| -def test_wheel_c_extension() -> None: |
| 51 | +def test_wheel_c_extension() -> None: # NOSONAR |
51 | 52 | module_path = fixtures_dir / "extended"
|
52 | 53 | builder = Builder(Factory().create_poetry(module_path))
|
53 | 54 | builder.build(fmt="all")
|
@@ -89,20 +90,27 @@ def test_wheel_c_extension() -> None:
|
89 | 90 | is not None
|
90 | 91 | )
|
91 | 92 |
|
92 |
| - records = zip.read("extended-0.1.dist-info/RECORD").decode() |
| 93 | + record = zip.read("extended-0.1.dist-info/RECORD").decode() |
| 94 | + records = csv.reader(record.splitlines()) |
| 95 | + record_files = [row[0] for row in records] |
93 | 96 |
|
94 |
| - assert re.search(r"\s+extended/extended.*\.(so|pyd)", records) is not None |
| 97 | + assert re.search(r"\s+extended/extended.*\.(so|pyd)", record) is not None |
95 | 98 | finally:
|
96 | 99 | zip.close()
|
97 | 100 |
|
| 101 | + # Files in RECORD should match files in wheel. |
| 102 | + zip_files = sorted(zip.namelist()) |
| 103 | + assert zip_files == sorted(record_files) |
| 104 | + assert len(set(record_files)) == len(record_files) |
| 105 | + |
98 | 106 |
|
99 | 107 | @pytest.mark.skipif(
|
100 | 108 | sys.platform == "win32"
|
101 | 109 | and sys.version_info <= (3, 6)
|
102 | 110 | or platform.python_implementation().lower() == "pypy",
|
103 | 111 | reason="Disable test on Windows for Python <=3.6 and for PyPy",
|
104 | 112 | )
|
105 |
| -def test_wheel_c_extension_with_no_setup() -> None: |
| 113 | +def test_wheel_c_extension_with_no_setup() -> None: # NOSONAR |
106 | 114 | module_path = fixtures_dir / "extended_with_no_setup"
|
107 | 115 | builder = Builder(Factory().create_poetry(module_path))
|
108 | 116 | builder.build(fmt="all")
|
@@ -144,20 +152,27 @@ def test_wheel_c_extension_with_no_setup() -> None:
|
144 | 152 | is not None
|
145 | 153 | )
|
146 | 154 |
|
147 |
| - records = zip.read("extended-0.1.dist-info/RECORD").decode() |
| 155 | + record = zip.read("extended-0.1.dist-info/RECORD").decode() |
| 156 | + records = csv.reader(record.splitlines()) |
| 157 | + record_files = [row[0] for row in records] |
148 | 158 |
|
149 |
| - assert re.search(r"\s+extended/extended.*\.(so|pyd)", records) is not None |
| 159 | + assert re.search(r"\s+extended/extended.*\.(so|pyd)", record) is not None |
150 | 160 | finally:
|
151 | 161 | zip.close()
|
152 | 162 |
|
| 163 | + # Files in RECORD should match files in wheel. |
| 164 | + zip_files = sorted(zip.namelist()) |
| 165 | + assert zip_files == sorted(record_files) |
| 166 | + assert len(set(record_files)) == len(record_files) |
| 167 | + |
153 | 168 |
|
154 | 169 | @pytest.mark.skipif(
|
155 | 170 | sys.platform == "win32"
|
156 | 171 | and sys.version_info <= (3, 6)
|
157 | 172 | or platform.python_implementation().lower() == "pypy",
|
158 | 173 | reason="Disable test on Windows for Python <=3.6 and for PyPy",
|
159 | 174 | )
|
160 |
| -def test_wheel_c_extension_src_layout() -> None: |
| 175 | +def test_wheel_c_extension_src_layout() -> None: # NOSONAR |
161 | 176 | module_path = fixtures_dir / "src_extended"
|
162 | 177 | builder = Builder(Factory().create_poetry(module_path))
|
163 | 178 | builder.build(fmt="all")
|
@@ -199,12 +214,19 @@ def test_wheel_c_extension_src_layout() -> None:
|
199 | 214 | is not None
|
200 | 215 | )
|
201 | 216 |
|
202 |
| - records = zip.read("extended-0.1.dist-info/RECORD").decode() |
| 217 | + record = zip.read("extended-0.1.dist-info/RECORD").decode() |
| 218 | + records = csv.reader(record.splitlines()) |
| 219 | + record_files = [row[0] for row in records] |
203 | 220 |
|
204 |
| - assert re.search(r"\s+extended/extended.*\.(so|pyd)", records) is not None |
| 221 | + assert re.search(r"\s+extended/extended.*\.(so|pyd)", record) is not None |
205 | 222 | finally:
|
206 | 223 | zip.close()
|
207 | 224 |
|
| 225 | + # Files in RECORD should match files in wheel. |
| 226 | + zip_files = sorted(zip.namelist()) |
| 227 | + assert zip_files == sorted(record_files) |
| 228 | + assert len(set(record_files)) == len(record_files) |
| 229 | + |
208 | 230 |
|
209 | 231 | def test_complete() -> None:
|
210 | 232 | module_path = fixtures_dir / "complete"
|
@@ -297,20 +319,23 @@ def test_complete() -> None:
|
297 | 319 | # vary per operating systems and Python versions.
|
298 | 320 | # So instead of 1:1 assertion, let's do a bit clunkier one:
|
299 | 321 |
|
300 |
| - expected_records = [ |
| 322 | + actual_files = [row[0] for row in csv.reader(actual_records.splitlines())] |
| 323 | + expected_files = [ |
| 324 | + "my_package-1.2.3.data/scripts/script.sh", |
| 325 | + "my_package-1.2.3.dist-info/LICENSE", |
| 326 | + "my_package-1.2.3.dist-info/METADATA", |
| 327 | + "my_package-1.2.3.dist-info/RECORD", |
| 328 | + "my_package-1.2.3.dist-info/WHEEL", |
| 329 | + "my_package-1.2.3.dist-info/entry_points.txt", |
301 | 330 | "my_package/__init__.py",
|
302 | 331 | "my_package/data1/test.json",
|
303 | 332 | "my_package/sub_pkg1/__init__.py",
|
304 | 333 | "my_package/sub_pkg2/__init__.py",
|
305 | 334 | "my_package/sub_pkg2/data2/data.json",
|
306 |
| - "my_package-1.2.3.dist-info/entry_points.txt", |
307 |
| - "my_package-1.2.3.dist-info/LICENSE", |
308 |
| - "my_package-1.2.3.dist-info/WHEEL", |
309 |
| - "my_package-1.2.3.dist-info/METADATA", |
| 335 | + "my_package/sub_pkg3/foo.py", |
310 | 336 | ]
|
311 | 337 |
|
312 |
| - for expected_record in expected_records: |
313 |
| - assert expected_record in actual_records |
| 338 | + assert sorted(expected_files) == sorted(actual_files) |
314 | 339 |
|
315 | 340 | finally:
|
316 | 341 | zip.close()
|
|
0 commit comments