From 3c6099ae06e1febee4017707d55715372148876e Mon Sep 17 00:00:00 2001 From: Bartosz Sokorski Date: Sun, 6 Oct 2024 15:24:46 +0200 Subject: [PATCH] Refactor rules concerning warning vs info in sdists --- src/poetry/core/masonry/builders/sdist.py | 6 ++--- tests/masonry/builders/test_sdist.py | 28 ++++++++++++++++++++++- 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/src/poetry/core/masonry/builders/sdist.py b/src/poetry/core/masonry/builders/sdist.py index eec7e0d3d..05e7b375a 100644 --- a/src/poetry/core/masonry/builders/sdist.py +++ b/src/poetry/core/masonry/builders/sdist.py @@ -425,12 +425,10 @@ def _get_archive_mtime() -> int: try: return int(source_date_epoch) except ValueError: - logger.info( + logger.warning( "SOURCE_DATE_EPOCH environment variable is not an int," " using mtime=0" ) return 0 - logger.info( - "SOURCE_DATE_EPOCH environment variable is not set," " using mtime=0" - ) + logger.info("SOURCE_DATE_EPOCH environment variable is not set, using mtime=0") return 0 diff --git a/tests/masonry/builders/test_sdist.py b/tests/masonry/builders/test_sdist.py index c9a525e10..c19d07b9e 100644 --- a/tests/masonry/builders/test_sdist.py +++ b/tests/masonry/builders/test_sdist.py @@ -25,6 +25,7 @@ if TYPE_CHECKING: + from _pytest.logging import LogCaptureFixture from _pytest.monkeypatch import MonkeyPatch from pytest_mock import MockerFixture @@ -702,7 +703,10 @@ def test_split_source() -> None: assert "" in ns["package_dir"] and "module_b" in ns["package_dir"] -def test_sdist_members_mtime_default() -> None: +def test_sdist_members_mtime_default(caplog: LogCaptureFixture) -> None: + import logging + + caplog.set_level(logging.INFO) poetry = Factory().create_poetry(project("module1")) builder = SdistBuilder(poetry) @@ -716,6 +720,10 @@ def test_sdist_members_mtime_default() -> None: for tarinfo in tar.getmembers(): assert tarinfo.mtime == 0 + assert ( + "SOURCE_DATE_EPOCH environment variable is not set," " using mtime=0" + ) in caplog.messages + def test_sdist_mtime_set_from_envvar(monkeypatch: MonkeyPatch) -> None: monkeypatch.setenv("SOURCE_DATE_EPOCH", "1727883000") @@ -731,3 +739,21 @@ def test_sdist_mtime_set_from_envvar(monkeypatch: MonkeyPatch) -> None: with tarfile.open(str(sdist), "r") as tar: for tarinfo in tar.getmembers(): assert tarinfo.mtime == 1727883000 + + +def test_sdist_mtime_set_from_envvar_not_int( + monkeypatch: MonkeyPatch, caplog: LogCaptureFixture +) -> None: + monkeypatch.setenv("SOURCE_DATE_EPOCH", "october") + poetry = Factory().create_poetry(project("module1")) + + builder = SdistBuilder(poetry) + builder.build() + + sdist = fixtures_dir / "module1" / "dist" / "module1-0.1.tar.gz" + + assert sdist.exists() + + assert ( + "SOURCE_DATE_EPOCH environment variable is not an " "int, using mtime=0" + ) in caplog.messages