Skip to content

Commit 48b12b9

Browse files
committed
Adapt tests to the new dist-info implementation
1 parent 8901269 commit 48b12b9

File tree

1 file changed

+27
-3
lines changed

1 file changed

+27
-3
lines changed

setuptools/tests/test_dist_info.py

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@
55
import shutil
66
import subprocess
77
import sys
8+
from email import message_from_string
89
from functools import partial
910

1011
import pytest
1112

1213
import pkg_resources
14+
from setuptools import _reqs
1315
from setuptools.archive_util import unpack_archive
1416
from .textwrap import DALS
1517

@@ -131,7 +133,7 @@ def test_output_dir(self, tmp_path, keep_egg_info):
131133

132134
class TestWheelCompatibility:
133135
"""Make sure the .dist-info directory produced with the ``dist_info`` command
134-
is the same as the one produced by ``bdist_wheel``.
136+
is the same(ish) as the one produced by ``bdist_wheel``.
135137
"""
136138

137139
SETUPCFG = DALS(
@@ -189,8 +191,30 @@ def test_dist_info_is_the_same_as_in_wheel(
189191

190192
assert dist_info.name == wheel_dist_info.name
191193
assert dist_info.name.startswith(f"{name.replace('-', '_')}-{version}{suffix}")
192-
for file in "METADATA", "entry_points.txt":
193-
assert read(dist_info / file) == read(wheel_dist_info / file)
194+
195+
assert (dist_info / "entry_points.txt").read_text(encoding="utf-8") == (
196+
wheel_dist_info / "entry_points.txt"
197+
).read_text(encoding="utf-8")
198+
199+
wheel_metadata = (wheel_dist_info / "METADATA").read_text(encoding="utf-8")
200+
metadata = (dist_info / "METADATA").read_text(encoding="utf-8")
201+
202+
# Compare metadata but normalize requirements formatting
203+
wheel_msg = message_from_string(wheel_metadata)
204+
wheel_deps = set(_reqs.parse(wheel_msg.get_all("Requires-Dist")))
205+
wheel_extras = set(wheel_msg.get_all("Provides-Extra"))
206+
del wheel_msg["Requires-Dist"]
207+
del wheel_msg["Provides-Extra"]
208+
209+
metadata_msg = message_from_string(metadata)
210+
metadata_deps = set(_reqs.parse(metadata_msg.get_all("Requires-Dist")))
211+
metadata_extras = set(metadata_msg.get_all("Provides-Extra"))
212+
del metadata_msg["Requires-Dist"]
213+
del metadata_msg["Provides-Extra"]
214+
215+
assert metadata_msg.as_string() == wheel_msg.as_string()
216+
assert metadata_deps == wheel_deps
217+
assert metadata_extras == wheel_extras
194218

195219

196220
def run_command_inner(*cmd, **kwargs):

0 commit comments

Comments
 (0)