diff options
| author | Jason R. Coombs <jaraco@jaraco.com> | 2022-11-13 14:37:35 -0500 |
|---|---|---|
| committer | Jason R. Coombs <jaraco@jaraco.com> | 2022-11-13 14:37:35 -0500 |
| commit | 9b8a6ef60b2b490bcf60b9dd7f0d43d46f49e489 (patch) | |
| tree | 56b90c20f19ca92c8d9c26e782c5969a7b872c48 /setuptools/_distutils/tests/test_sdist.py | |
| parent | a0e8e53cecc238e3bce2247308fe7dd94114ef35 (diff) | |
| parent | e0787fad7c03d8defbbaaaf2888130cc2a171537 (diff) | |
| download | python-setuptools-git-9b8a6ef60b2b490bcf60b9dd7f0d43d46f49e489.tar.gz | |
Merge https://github.com/pypa/distutils into distutils-e0787fa
Diffstat (limited to 'setuptools/_distutils/tests/test_sdist.py')
| -rw-r--r-- | setuptools/_distutils/tests/test_sdist.py | 44 |
1 files changed, 19 insertions, 25 deletions
diff --git a/setuptools/_distutils/tests/test_sdist.py b/setuptools/_distutils/tests/test_sdist.py index b11fe7c4..97504722 100644 --- a/setuptools/_distutils/tests/test_sdist.py +++ b/setuptools/_distutils/tests/test_sdist.py @@ -5,7 +5,6 @@ import warnings import zipfile from os.path import join from textwrap import dedent -from test.support import captured_stdout from .unix_compat import require_unix_id, require_uid_0, pwd, grp import pytest @@ -19,7 +18,6 @@ from distutils.core import Distribution from distutils.tests.test_config import BasePyPIRCCommandTestCase from distutils.errors import DistutilsOptionError from distutils.spawn import find_executable # noqa: F401 -from distutils.log import WARN from distutils.filelist import FileList from distutils.archive_util import ARCHIVE_FORMATS @@ -252,8 +250,12 @@ class TestSDist(BasePyPIRCCommandTestCase): f.close() assert manifest == MANIFEST % {'sep': os.sep} + @staticmethod + def warnings(messages, prefix='warning: '): + return [msg for msg in messages if msg.startswith(prefix)] + @pytest.mark.usefixtures('needs_zlib') - def test_metadata_check_option(self): + def test_metadata_check_option(self, caplog): # testing the `medata-check` option dist, cmd = self.get_cmd(metadata={}) @@ -261,21 +263,15 @@ class TestSDist(BasePyPIRCCommandTestCase): # with the `check` subcommand cmd.ensure_finalized() cmd.run() - warnings = [ - msg for msg in self.get_logs(WARN) if msg.startswith('warning: check:') - ] - assert len(warnings) == 1 + assert len(self.warnings(caplog.messages, 'warning: check: ')) == 1 # trying with a complete set of metadata - self.clear_logs() + caplog.clear() dist, cmd = self.get_cmd() cmd.ensure_finalized() cmd.metadata_check = 0 cmd.run() - warnings = [ - msg for msg in self.get_logs(WARN) if msg.startswith('warning: check:') - ] - assert len(warnings) == 0 + assert len(self.warnings(caplog.messages, 'warning: check: ')) == 0 def test_check_metadata_deprecated(self): # makes sure make_metadata is deprecated @@ -285,15 +281,14 @@ class TestSDist(BasePyPIRCCommandTestCase): cmd.check_metadata() assert len(w.warnings) == 1 - def test_show_formats(self): - with captured_stdout() as stdout: - show_formats() + def test_show_formats(self, capsys): + show_formats() # the output should be a header line + one line per format num_formats = len(ARCHIVE_FORMATS.keys()) output = [ line - for line in stdout.getvalue().split('\n') + for line in capsys.readouterr().out.split('\n') if line.strip().startswith('--formats=') ] assert len(output) == num_formats @@ -323,28 +318,27 @@ class TestSDist(BasePyPIRCCommandTestCase): # the following tests make sure there is a nice error message instead # of a traceback when parsing an invalid manifest template - def _check_template(self, content): + def _check_template(self, content, caplog): dist, cmd = self.get_cmd() os.chdir(self.tmp_dir) self.write_file('MANIFEST.in', content) cmd.ensure_finalized() cmd.filelist = FileList() cmd.read_template() - warnings = self.get_logs(WARN) - assert len(warnings) == 1 + assert len(self.warnings(caplog.messages)) == 1 - def test_invalid_template_unknown_command(self): - self._check_template('taunt knights *') + def test_invalid_template_unknown_command(self, caplog): + self._check_template('taunt knights *', caplog) - def test_invalid_template_wrong_arguments(self): + def test_invalid_template_wrong_arguments(self, caplog): # this manifest command takes one argument - self._check_template('prune') + self._check_template('prune', caplog) @pytest.mark.skipif("platform.system() != 'Windows'") - def test_invalid_template_wrong_path(self): + def test_invalid_template_wrong_path(self, caplog): # on Windows, trailing slashes are not allowed # this used to crash instead of raising a warning: #8286 - self._check_template('include examples/') + self._check_template('include examples/', caplog) @pytest.mark.usefixtures('needs_zlib') def test_get_file_list(self): |
