diff options
| author | Anderson Bravalheri <andersonbravalheri@gmail.com> | 2022-03-29 03:00:32 +0100 |
|---|---|---|
| committer | Anderson Bravalheri <andersonbravalheri@gmail.com> | 2022-03-29 03:00:32 +0100 |
| commit | 16c3f1f69f6ea005c24b056f33bcd75259d976e5 (patch) | |
| tree | fcee9cdd2f393a4cef410dd6829ef4236857dbf2 /setuptools | |
| parent | 0ec53b228800300992ba1c53c2f089a435d4970c (diff) | |
| download | python-setuptools-git-16c3f1f69f6ea005c24b056f33bcd75259d976e5.tar.gz | |
Test dist_info creates similar dir to bdist_wheel
Diffstat (limited to 'setuptools')
| -rw-r--r-- | setuptools/tests/test_dist_info.py | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/setuptools/tests/test_dist_info.py b/setuptools/tests/test_dist_info.py index 29fbd09d..7f0e01cc 100644 --- a/setuptools/tests/test_dist_info.py +++ b/setuptools/tests/test_dist_info.py @@ -1,12 +1,21 @@ """Test .dist-info style distributions. """ +import pathlib +import subprocess +import sys +from functools import partial +from unittest.mock import patch import pytest import pkg_resources +from setuptools.archive_util import unpack_archive from .textwrap import DALS +read = partial(pathlib.Path.read_text, encoding="utf-8") + + class TestDistInfo: metadata_base = DALS(""" @@ -72,3 +81,64 @@ class TestDistInfo: pkg_resources.Requirement.parse('quux>=1.1;extra=="baz"'), ] assert d.extras == ['baz'] + + +class TestWheelCompatibility: + SETUPCFG = DALS(""" + [metadata] + name = proj + version = 42 + + [options] + install_requires = foo>=12; sys_platform != "linux" + + [options.extras_require] + test = pytest + + [options.entry_points] + console_scripts = + executable-name = my_package.module:function + discover = + myproj = my_package.other_module:function + """) + + FROZEN_TIME = "20220329" + EGG_INFO_OPTS = [ + # Related: #3077 #2872 + ("", ""), + (".post", "[egg_info]\ntag_build = post\n"), + (".post", "[egg_info]\ntag_build = .post\n"), + (f".post{FROZEN_TIME}", "[egg_info]\ntag_build = post\ntag_date = 1\n"), + (".dev", "[egg_info]\ntag_build = .dev\n"), + (f".dev{FROZEN_TIME}", "[egg_info]\ntag_build = .dev\ntag_date = 1\n"), + ("a1", "[egg_info]\ntag_build = .a1\n"), + ("+local", "[egg_info]\ntag_build = +local\n"), + ] + + @pytest.mark.parametrize("suffix,cfg", EGG_INFO_OPTS) + @patch("setuptools.command.egg_info.time.strftime", FROZEN_TIME) + def test_dist_info_is_the_same_as_in_wheel(self, tmp_path, suffix, cfg): + config = self.SETUPCFG + cfg + + for i in "dir_wheel", "dir_dist": + (tmp_path / i).mkdir() + (tmp_path / i / "setup.cfg").write_text(config, encoding="utf-8") + + run_command("bdist_wheel", cwd=tmp_path / "dir_wheel") + wheel = next(tmp_path.glob("dir_wheel/dist/*.whl")) + unpack_archive(wheel, tmp_path / "unpack") + wheel_dist_info = next(tmp_path.glob("unpack/*.dist-info")) + + run_command("dist_info", cwd=tmp_path / "dir_dist") + dist_info = next(tmp_path.glob("dir_dist/*.dist-info")) + + assert dist_info.name == wheel_dist_info.name + assert dist_info.name.startswith(f"proj-42{suffix}") + for file in "METADATA", "entry_points.txt": + assert read(dist_info / file) == read(wheel_dist_info / file) + + +def run_command(*cmd, **kwargs): + opts = {"stderr": subprocess.STDOUT, "text": True, **kwargs} + cmd = [sys.executable, "-c", "__import__('setuptools').setup()", *cmd] + return subprocess.check_output(cmd, **opts) |
