Skip to content

Commit

Permalink
Add regression test for issue 4853
Browse files Browse the repository at this point in the history
  • Loading branch information
abravalheri committed Feb 26, 2025
1 parent 56c055b commit 79d6e46
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions pkg_resources/tests/test_pkg_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import builtins
import datetime
import inspect
import os
import plistlib
import stat
Expand Down Expand Up @@ -425,3 +426,56 @@ def test_normalize_path_backslash_sep(self, unnormalized, expected):
"""Ensure path seps are cleaned on backslash path sep systems."""
result = pkg_resources.normalize_path(unnormalized)
assert result.endswith(expected)


class TestWorkdirRequire:
def fake_site_packages(self, tmp_path, monkeypatch, dist_files):
site_packages = tmp_path / "site-packages"
site_packages.mkdir()
for file, content in self.FILES.items():
path = site_packages / file
path.parent.mkdir(exist_ok=True, parents=True)
path.write_text(inspect.cleandoc(content), encoding="utf-8")

monkeypatch.setattr(sys, "path", [site_packages])
return os.fspath(site_packages)

FILES = {
"pkg1_mod-1.2.3.dist-info/METADATA": """
Metadata-Version: 2.4
Name: pkg1.mod
Version: 1.2.3
""",
"pkg2.mod-0.42.dist-info/METADATA": """
Metadata-Version: 2.1
Name: pkg2.mod
Version: 0.42
""",
"pkg3_mod.egg-info/PKG-INFO": """
Name: pkg3.mod
Version: 1.2.3
""",
"pkg4.mod.egg-info/PKG-INFO": """
Name: pkg4.mod
Version: 0.42
""",
}

@pytest.mark.parametrize(
("name", "version", "req"),
[
("pkg1.mod", "1.2.3", "pkg1.mod>=1"),
("pkg2.mod", "0.42", "pkg2.mod>=0.4"),
("pkg3.mod", "1.2.3", "pkg3.mod<=2"),
("pkg4.mod", "0.42", "pkg4.mod>0.2,<1"),
],
)
def test_require_normalised_name(self, tmp_path, monkeypatch, name, version, req):
# https://github.com/pypa/setuptools/issues/4853
site_packages = self.fake_site_packages(tmp_path, monkeypatch, self.FILES)
ws = pkg_resources.WorkingSet([site_packages])

[dist] = ws.require(req)
assert dist.version == version
assert dist.project_name == name
assert os.path.commonpath([dist.location, site_packages]) == site_packages

0 comments on commit 79d6e46

Please sign in to comment.