Skip to content

Commit

Permalink
Merge pull request Aiven-Open#911 from Aiven-Open/eliax1996/fix-versi…
Browse files Browse the repository at this point in the history
…on-0-is-invalid

fix: remove the raise Invalid version when instantiating a version 0
  • Loading branch information
nosahama authored Jul 2, 2024
2 parents 6b44a63 + 74587f4 commit c6a0948
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion karapace/typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class Version:
def __init__(self, version: int) -> None:
if not isinstance(version, int):
raise InvalidVersion(f"Invalid version {version}")
if (version < Version.MINUS_1_VERSION_TAG) or (version == 0):
if version < Version.MINUS_1_VERSION_TAG:
raise InvalidVersion(f"Invalid version {version}")
self._value = version

Expand Down
10 changes: 9 additions & 1 deletion tests/unit/test_schema_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ def test_invalid_version(self, invalid_version: VersionTag):
def test_is_latest(self, version: Version, is_latest: bool):
assert version.is_latest is is_latest

def version_0_its_constructable(self) -> None:
version_0 = Version(0)
assert version_0.value == 0

def test_text_formating(self, version: Version):
assert f"{version}" == "1"
assert f"{version!r}" == "Version(1)"
Expand Down Expand Up @@ -159,7 +163,11 @@ def test_factory_V(self, tag: VersionTag, resolved: int):
def test_validate(self, tag: VersionTag):
Versioner.validate_tag(tag=tag)

@pytest.mark.parametrize("tag", ["invalid_version", 0, -20, "0"])
@pytest.mark.parametrize("tag", ["invalid_version", "0", -20])
def test_validate_invalid(self, tag: VersionTag):
"""
Tagger should still keep invalid version 0, we are only backwards compatible, and we should
avoid generating 0 as a new tag for any schema.
"""
with pytest.raises(InvalidVersion):
Versioner.validate_tag(tag=tag)

0 comments on commit c6a0948

Please sign in to comment.