Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: remove the raise Invalid version when instantiating a version 0 #911

Merged
merged 1 commit into from
Jul 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Loading