Skip to content

Commit 79d6e46

Browse files
committed
Add regression test for issue 4853
1 parent 56c055b commit 79d6e46

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

pkg_resources/tests/test_pkg_resources.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import builtins
44
import datetime
5+
import inspect
56
import os
67
import plistlib
78
import stat
@@ -425,3 +426,56 @@ def test_normalize_path_backslash_sep(self, unnormalized, expected):
425426
"""Ensure path seps are cleaned on backslash path sep systems."""
426427
result = pkg_resources.normalize_path(unnormalized)
427428
assert result.endswith(expected)
429+
430+
431+
class TestWorkdirRequire:
432+
def fake_site_packages(self, tmp_path, monkeypatch, dist_files):
433+
site_packages = tmp_path / "site-packages"
434+
site_packages.mkdir()
435+
for file, content in self.FILES.items():
436+
path = site_packages / file
437+
path.parent.mkdir(exist_ok=True, parents=True)
438+
path.write_text(inspect.cleandoc(content), encoding="utf-8")
439+
440+
monkeypatch.setattr(sys, "path", [site_packages])
441+
return os.fspath(site_packages)
442+
443+
FILES = {
444+
"pkg1_mod-1.2.3.dist-info/METADATA": """
445+
Metadata-Version: 2.4
446+
Name: pkg1.mod
447+
Version: 1.2.3
448+
""",
449+
"pkg2.mod-0.42.dist-info/METADATA": """
450+
Metadata-Version: 2.1
451+
Name: pkg2.mod
452+
Version: 0.42
453+
""",
454+
"pkg3_mod.egg-info/PKG-INFO": """
455+
Name: pkg3.mod
456+
Version: 1.2.3
457+
""",
458+
"pkg4.mod.egg-info/PKG-INFO": """
459+
Name: pkg4.mod
460+
Version: 0.42
461+
""",
462+
}
463+
464+
@pytest.mark.parametrize(
465+
("name", "version", "req"),
466+
[
467+
("pkg1.mod", "1.2.3", "pkg1.mod>=1"),
468+
("pkg2.mod", "0.42", "pkg2.mod>=0.4"),
469+
("pkg3.mod", "1.2.3", "pkg3.mod<=2"),
470+
("pkg4.mod", "0.42", "pkg4.mod>0.2,<1"),
471+
],
472+
)
473+
def test_require_normalised_name(self, tmp_path, monkeypatch, name, version, req):
474+
# https://github.com/pypa/setuptools/issues/4853
475+
site_packages = self.fake_site_packages(tmp_path, monkeypatch, self.FILES)
476+
ws = pkg_resources.WorkingSet([site_packages])
477+
478+
[dist] = ws.require(req)
479+
assert dist.version == version
480+
assert dist.project_name == name
481+
assert os.path.commonpath([dist.location, site_packages]) == site_packages

0 commit comments

Comments
 (0)