From e98f03bb0932e364065f827f804806bacccc436d Mon Sep 17 00:00:00 2001 From: William Woodruff Date: Sat, 30 Nov 2024 16:03:27 -0500 Subject: [PATCH] check: fix handling of non-shell-expanded globs Signed-off-by: William Woodruff --- tests/helpers.py | 9 +++++---- tests/test_check.py | 16 ++++++++++++++++ twine/commands/check.py | 1 + 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/tests/helpers.py b/tests/helpers.py index df1a0cb8..c0b9da8c 100644 --- a/tests/helpers.py +++ b/tests/helpers.py @@ -18,10 +18,11 @@ import pathlib TESTS_DIR = pathlib.Path(__file__).parent -SDIST_FIXTURE = os.path.join(TESTS_DIR, "fixtures/twine-1.5.0.tar.gz") -WHEEL_FIXTURE = os.path.join(TESTS_DIR, "fixtures/twine-1.5.0-py2.py3-none-any.whl") -NEW_SDIST_FIXTURE = os.path.join(TESTS_DIR, "fixtures/twine-1.6.5.tar.gz") -NEW_WHEEL_FIXTURE = os.path.join(TESTS_DIR, "fixtures/twine-1.6.5-py2.py3-none-any.whl") +FIXTURES_DIR = os.path.join(TESTS_DIR, "fixtures") +SDIST_FIXTURE = os.path.join(FIXTURES_DIR, "twine-1.5.0.tar.gz") +WHEEL_FIXTURE = os.path.join(FIXTURES_DIR, "twine-1.5.0-py2.py3-none-any.whl") +NEW_SDIST_FIXTURE = os.path.join(FIXTURES_DIR, "twine-1.6.5.tar.gz") +NEW_WHEEL_FIXTURE = os.path.join(FIXTURES_DIR, "twine-1.6.5-py2.py3-none-any.whl") @contextlib.contextmanager diff --git a/tests/test_check.py b/tests/test_check.py index 2cf1d0be..ca62d2c1 100644 --- a/tests/test_check.py +++ b/tests/test_check.py @@ -18,6 +18,7 @@ import pretend import pytest +from tests import helpers from twine.commands import check @@ -283,6 +284,21 @@ def test_main(monkeypatch): assert check_stub.calls == [pretend.call(["dist/*"], strict=False)] +def test_check_expands_glob(monkeypatch): + """Regression test for #1187.""" + warning_stream = pretend.stub() + warning_stream_cls = pretend.call_recorder(lambda: warning_stream) + monkeypatch.setattr(check, "_WarningStream", warning_stream_cls) + + check_file = pretend.call_recorder(lambda fn, stream: ([], True)) + monkeypatch.setattr(check, "_check_file", check_file) + + assert not check.main([f"{helpers.FIXTURES_DIR}/*"]) + + # check_file is called more than once, indicating the glob has been expanded + assert len(check_file.calls) > 1 + + # TODO: Test print() color output # TODO: Test log formatting diff --git a/twine/commands/check.py b/twine/commands/check.py index 6b0fe5c7..9637651e 100644 --- a/twine/commands/check.py +++ b/twine/commands/check.py @@ -127,6 +127,7 @@ def check( :return: ``True`` if there are rendering errors, otherwise ``False``. """ + dists = commands._find_dists(dists) uploads, _, _ = commands._split_inputs(dists) if not uploads: # Return early, if there are no files to check. logger.error("No files to check.")