Update LL version stringification and make parsing stricter (#6334)

This commit is contained in:
Jakub Kuczys
2024-03-31 23:26:36 +02:00
committed by GitHub
parent 48d74712bc
commit e71312ede0
2 changed files with 152 additions and 41 deletions

View File

@@ -1,4 +1,5 @@
import itertools
from typing import Optional
import pytest
@@ -43,30 +44,88 @@ def test_old_ll_version_parsing(
raw_version: str, raw_build_number: str, expected: LavalinkOldVersion
) -> None:
line = b"Version: %b\nBuild: %b" % (raw_version.encode(), raw_build_number.encode())
assert LavalinkOldVersion.from_version_output(line)
actual = LavalinkOldVersion.from_version_output(line)
assert actual == expected
assert str(actual) == f"{raw_version}_{raw_build_number}"
def _generate_ll_version_line(raw_version: str) -> bytes:
return b"Version: " + raw_version.encode()
@pytest.mark.parametrize(
"raw_version,expected",
"raw_version,expected_str,expected",
(
# older version format that allowed stripped `.0` and no dot in `rc.4`, used until LL 3.6
("3.5-rc4", LavalinkVersion(3, 5, rc=4)),
("3.5", LavalinkVersion(3, 5)),
("3.5-rc4", "3.5.0-rc.4", LavalinkVersion(3, 5, rc=4)),
("3.5", "3.5.0", LavalinkVersion(3, 5)),
# newer version format
("3.6.0-rc.1", LavalinkVersion(3, 6, 0, rc=1)),
("3.6.0-rc.1", None, LavalinkVersion(3, 6, 0, rc=1)),
# downstream RC version with `+red.N` suffix
("3.7.5-rc.1+red.1", LavalinkVersion(3, 7, 5, rc=1, red=1)),
("3.7.5-rc.1+red.123", LavalinkVersion(3, 7, 5, rc=1, red=123)),
("3.7.5-rc.1+red.1", None, LavalinkVersion(3, 7, 5, rc=1, red=1)),
("3.7.5-rc.1+red.123", None, LavalinkVersion(3, 7, 5, rc=1, red=123)),
# upstream stable version
("3.7.5", LavalinkVersion(3, 7, 5)),
("3.7.5", None, LavalinkVersion(3, 7, 5)),
# downstream stable version with `+red.N` suffix
("3.7.5+red.1", LavalinkVersion(3, 7, 5, red=1)),
("3.7.5+red.123", LavalinkVersion(3, 7, 5, red=123)),
("3.7.5+red.1", None, LavalinkVersion(3, 7, 5, red=1)),
("3.7.5+red.123", None, LavalinkVersion(3, 7, 5, red=123)),
),
)
def test_ll_version_parsing(raw_version: str, expected: LavalinkVersion) -> None:
line = b"Version: " + raw_version.encode()
assert LavalinkVersion.from_version_output(line)
def test_ll_version_parsing(
raw_version: str, expected_str: Optional[str], expected: LavalinkVersion
) -> None:
line = _generate_ll_version_line(raw_version)
actual = LavalinkVersion.from_version_output(line)
expected_str = expected_str or raw_version
assert actual == expected
assert str(actual) == expected_str
@pytest.mark.parametrize(
"raw_version",
(
# 3.5.0-rc4 is first version to not have build number
# 3.5 stripped `.0` from version number
"3.5",
# RC version don't need a dot for RC versions...
"3.5-rc4",
# ...but that doesn't mean they can't
"3.5-rc.5",
# regular 3.5.x version
"3.5.5",
# one more RC version with non-zero patch version
"3.5.5-rc1",
),
)
def test_ll_version_accepts_less_strict_below_3_6(raw_version: str) -> None:
line = _generate_ll_version_line(raw_version)
# check that the version can be parsed
LavalinkVersion.from_version_output(line)
@pytest.mark.parametrize(
"raw_version",
(
# `.0` releases <3.6 had their `.0` stripped so this is not valid:
"3.5.0-rc4",
# 3.6 is first to require stricter format
"3.6.0-rc4",
"3.6",
# another single digit minor version newer than 3.6
"3.7",
# double digit minor version
"3.11.3-rc1",
# newer major version
"4.0.0-rc5",
# double digit major version
"11.0.0-rc5",
),
)
def test_ll_version_rejects_less_strict_on_3_6_and_above(raw_version: str) -> None:
line = _generate_ll_version_line(raw_version)
with pytest.raises(ValueError):
LavalinkVersion.from_version_output(line)
def test_ll_version_comparison() -> None: