diff options
Diffstat (limited to 'setuptools/tests/test_dist_info.py')
| -rw-r--r-- | setuptools/tests/test_dist_info.py | 50 |
1 files changed, 32 insertions, 18 deletions
diff --git a/setuptools/tests/test_dist_info.py b/setuptools/tests/test_dist_info.py index 350e6429..45b0d7fb 100644 --- a/setuptools/tests/test_dist_info.py +++ b/setuptools/tests/test_dist_info.py @@ -19,19 +19,18 @@ read = partial(pathlib.Path.read_text, encoding="utf-8") class TestDistInfo: - metadata_base = DALS(""" + metadata_base = DALS( + """ Metadata-Version: 1.2 Requires-Dist: splort (==4) Provides-Extra: baz Requires-Dist: quux (>=1.1); extra == 'baz' - """) + """ + ) @classmethod def build_metadata(cls, **kwargs): - lines = ( - '{key}: {value}\n'.format(**locals()) - for key, value in kwargs.items() - ) + lines = ('{key}: {value}\n'.format(**locals()) for key, value in kwargs.items()) return cls.metadata_base + ''.join(lines) @pytest.fixture @@ -59,8 +58,7 @@ class TestDistInfo: def test_distinfo(self, metadata): dists = dict( - (d.project_name, d) - for d in pkg_resources.find_distributions(metadata) + (d.project_name, d) for d in pkg_resources.find_distributions(metadata) ) assert len(dists) == 2, dists @@ -84,13 +82,16 @@ class TestDistInfo: assert d.extras == ['baz'] def test_invalid_version(self, tmp_path): + """ + Supplying an invalid version crashes dist_info. + """ config = "[metadata]\nname=proj\nversion=42\n[egg_info]\ntag_build=invalid!!!\n" (tmp_path / "setup.cfg").write_text(config, encoding="utf-8") msg = re.compile("invalid version", re.M | re.I) - output = run_command("dist_info", cwd=tmp_path) - assert msg.search(output) - dist_info = next(tmp_path.glob("*.dist-info")) - assert dist_info.name.startswith("proj-42") + proc = run_command_inner("dist_info", cwd=tmp_path, check=False) + assert proc.returncode + assert msg.search(proc.stdout) + assert not list(tmp_path.glob("*.dist-info")) def test_tag_arguments(self, tmp_path): config = """ @@ -116,7 +117,7 @@ class TestDistInfo: def test_output_dir(self, tmp_path, keep_egg_info): config = "[metadata]\nname=proj\nversion=42\n" (tmp_path / "setup.cfg").write_text(config, encoding="utf-8") - out = (tmp_path / "__out") + out = tmp_path / "__out" out.mkdir() opts = ["--keep-egg-info"] if keep_egg_info else [] run_command("dist_info", "--output-dir", out, *opts, cwd=tmp_path) @@ -133,7 +134,9 @@ class TestWheelCompatibility: """Make sure the .dist-info directory produced with the ``dist_info`` command is the same as the one produced by ``bdist_wheel``. """ - SETUPCFG = DALS(""" + + SETUPCFG = DALS( + """ [metadata] name = {name} version = {version} @@ -149,7 +152,8 @@ class TestWheelCompatibility: executable-name = my_package.module:function discover = myproj = my_package.other_module:function - """) + """ + ) EGG_INFO_OPTS = [ # Related: #3088 #2872 @@ -189,7 +193,17 @@ class TestWheelCompatibility: assert read(dist_info / file) == read(wheel_dist_info / file) -def run_command(*cmd, **kwargs): - opts = {"stderr": subprocess.STDOUT, "text": True, **kwargs} +def run_command_inner(*cmd, **kwargs): + opts = { + "stderr": subprocess.STDOUT, + "stdout": subprocess.PIPE, + "text": True, + 'check': True, + **kwargs, + } cmd = [sys.executable, "-c", "__import__('setuptools').setup()", *map(str, cmd)] - return subprocess.check_output(cmd, **opts) + return subprocess.run(cmd, **opts) + + +def run_command(*args, **kwargs): + return run_command_inner(*args, **kwargs).stdout |
