62 lines
2.1 KiB
Python
62 lines
2.1 KiB
Python
"""Tests for the classification of recipe version strings."""
|
|
|
|
import os
|
|
import sys
|
|
|
|
import pytest
|
|
|
|
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
|
|
|
from alakazam import classify_version, is_hash, is_version
|
|
|
|
# a coop cloud version is '<recipe-version>+<upstream-tag>'
|
|
COOP_CLOUD_VERSION = "1.2.3+4.5.6-fpm"
|
|
|
|
|
|
class TestIsHash:
|
|
@pytest.mark.parametrize("value", ["deadbeef", "DEADBEEF", "1234", "a" * 64])
|
|
def test_hashes(self, value):
|
|
assert is_hash(value)
|
|
|
|
@pytest.mark.parametrize("value", ["1.2.3", COOP_CLOUD_VERSION, "chaos", "latest", None, "", "abc", "g" * 8, "a" * 65])
|
|
def test_non_hashes(self, value):
|
|
assert not is_hash(value)
|
|
|
|
|
|
class TestIsVersion:
|
|
@pytest.mark.parametrize("value", ["1.2.3", COOP_CLOUD_VERSION, "1234"])
|
|
def test_versions(self, value):
|
|
assert is_version(value)
|
|
|
|
@pytest.mark.parametrize("value", ["chaos", "latest", None, "", "deadbeef"])
|
|
def test_non_versions(self, value):
|
|
"""None must not raise, packaging answers it with a TypeError rather than InvalidVersion."""
|
|
assert not is_version(value)
|
|
|
|
|
|
class TestClassifyVersion:
|
|
@pytest.mark.parametrize(
|
|
"value,expected",
|
|
[
|
|
("1.2.3", "version"),
|
|
(COOP_CLOUD_VERSION, "version"),
|
|
("chaos", "chaos"),
|
|
("latest", "chaos"),
|
|
(None, "chaos"),
|
|
("deadbeef", "hash"),
|
|
("", "unknown"),
|
|
("no version at all", "unknown"),
|
|
],
|
|
)
|
|
def test_classification(self, value, expected):
|
|
assert classify_version(value) == expected
|
|
|
|
def test_hash_takes_precedence_over_version(self):
|
|
"""A purely numeric commit hash must not be mistaken for a release."""
|
|
assert is_version("1234") and is_hash("1234")
|
|
assert classify_version("1234") == "hash"
|
|
|
|
def test_upstream_tag_does_not_change_the_class(self):
|
|
"""packaging treats everything after '+' as build metadata, the full string still classifies."""
|
|
assert classify_version("1.2.3") == classify_version(COOP_CLOUD_VERSION)
|