From e582270550bcfba2a914407dff938954a44830a6 Mon Sep 17 00:00:00 2001 From: Nathan McDougall Date: Thu, 25 Jul 2024 18:29:08 +1200 Subject: [PATCH 1/2] Fix off-by-one error in version parsing function msg. --- pins/tests/test_versions.py | 15 +++++++++++++++ pins/versions.py | 2 +- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/pins/tests/test_versions.py b/pins/tests/test_versions.py index defc844..4dcaebe 100644 --- a/pins/tests/test_versions.py +++ b/pins/tests/test_versions.py @@ -4,6 +4,7 @@ import pytest import xxhash +from pins.errors import PinsVersionError from pins.versions import Version EXAMPLE_DATE = datetime(2021, 1, 2, 13, 58, 59) @@ -20,6 +21,20 @@ def test_version_from_string(): assert version.hash == "baf3f" +def test_version_from_string_too_many_hyphens(): + with pytest.raises( + PinsVersionError, match="version string can only have 1 '-', but contains 2" + ): + Version.from_string("20220209T220116Z-baf3f-") + + +def test_version_from_string_too_few_hyphens(): + with pytest.raises( + PinsVersionError, match="version string can only have 1 '-', but contains 0" + ): + Version.from_string("20220209T220116Zbaf3f") + + def test_version_hash_file(bytes_): f_bytes, digest = bytes_ assert Version.hash_file(f_bytes) == digest diff --git a/pins/versions.py b/pins/versions.py index 3208c2b..e5dc39d 100644 --- a/pins/versions.py +++ b/pins/versions.py @@ -69,7 +69,7 @@ def from_string(cls, version: str) -> "Version": if len(parts) != 2: raise PinsVersionError( - "version string can only have 1 '-', but contains %s" % len(parts) + f"version string can only have 1 '-', but contains {len(parts) - 1}" ) dt_string, hash_ = parts From 8b88b59d03089910d901f19b9599838d9eb76b2a Mon Sep 17 00:00:00 2001 From: Isabel Zimmerman <54685329+isabelizimm@users.noreply.github.com> Date: Tue, 6 Aug 2024 17:29:21 -0400 Subject: [PATCH 2/2] Update pins/tests/test_versions.py --- pins/tests/test_versions.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pins/tests/test_versions.py b/pins/tests/test_versions.py index 7af0934..6432108 100644 --- a/pins/tests/test_versions.py +++ b/pins/tests/test_versions.py @@ -33,6 +33,8 @@ def test_version_from_string_too_few_hyphens(): PinsVersionError, match="version string can only have 1 '-', but contains 0" ): Version.from_string("20220209T220116Zbaf3f") + + def test_version_from_string_baddate(): with pytest.raises(PinsVersionError, match="Invalid date part of version: bug"): Version.from_string("bug-baf3f")