Skip to content

Commit

Permalink
chore: add test cases to version tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kiendang committed Oct 17, 2023
1 parent 75a1d7d commit aae0b10
Showing 1 changed file with 64 additions and 10 deletions.
74 changes: 64 additions & 10 deletions tests/test_version.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,71 @@
from typing import Any, Tuple

import packaging
import pytest
from packaging.version import Version

from graphql_server.version import version, version_info

RELEASE_LEVEL = {"alpha": "a", "beta": "b", "rc": "rc", "final": None}
from graphql_server.version import (
version as VERSION,
version_info as VERSION_INFO,
)

VersionInfoType = Tuple[int, int, int, str, int]

parsed_version = Version(version)

RELEASE_LEVEL = {"alpha": "a", "beta": "b", "rc": "rc", "final": None}

def test_valid_version() -> None:
VERSION_AND_VERSION_INFO = [
(
"1.2.3",
(1, 2, 3, "final", 0),
),
(
"1.2.3a4",
(1, 2, 3, "alpha", 4),
),
(
"1.2.3b4",
(1, 2, 3, "beta", 4),
),
(
"12.34.56rc789",
(12, 34, 56, "rc", 789),
),
(
VERSION,
VERSION_INFO,
),
]


@pytest.fixture(params=VERSION_AND_VERSION_INFO)
def version_and_version_info(
request: pytest.FixtureRequest,
) -> Tuple[str, VersionInfoType]:
return request.param


@pytest.fixture
def version(version_and_version_info: Tuple[str, VersionInfoType]) -> str:
return version_and_version_info[0]


@pytest.fixture
def version_info(
version_and_version_info: Tuple[str, VersionInfoType]
) -> VersionInfoType:
return version_and_version_info[1]


@pytest.fixture
def parsed_version(version: str) -> Version:
return Version(version)


def test_valid_version(version: str) -> None:
packaging.version.parse(version)


def test_valid_version_info() -> None:
def test_valid_version_info(version_info: Any) -> None:
"""version_info has to be a tuple[int, int, int, str, int]"""
assert isinstance(version_info, tuple)
assert len(version_info) == 5
Expand All @@ -26,17 +78,19 @@ def test_valid_version_info() -> None:
assert isinstance(serial, int)


def test_valid_version_release_level() -> None:
def test_valid_version_release_level(parsed_version: Version) -> None:
if parsed_version.pre is not None:
valid_release_levels = {v for v in RELEASE_LEVEL.values() if v is not None}
assert parsed_version.pre[0] in valid_release_levels


def test_valid_version_info_release_level() -> None:
def test_valid_version_info_release_level(version_info: VersionInfoType) -> None:
assert version_info[3] in RELEASE_LEVEL.keys()


def test_version_same_as_version_info() -> None:
def test_version_same_as_version_info(
parsed_version: Version, version_info: VersionInfoType
) -> None:
assert (
parsed_version.major,
parsed_version.minor,
Expand Down

0 comments on commit aae0b10

Please sign in to comment.