-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add helper to compare collection versions with prerelease awareness
- Loading branch information
Showing
2 changed files
with
46 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# -*- coding: utf-8 -*- | ||
# (c) 2023 Brian Scholer (@briantist) | ||
|
||
import pytest | ||
from unittest import mock | ||
|
||
from datetime import datetime, timedelta | ||
from types import GeneratorType | ||
import semver | ||
|
||
from galactory.utilities import _latest_collection_version | ||
|
||
|
||
@pytest.mark.parametrize(["ref", "dif", "exp"], [ | ||
("0.0.0-dev0", "0.0.0-dev1", "0.0.0-dev1"), | ||
("0.0.0", "0.0.0-dev1", "0.0.0"), | ||
("1.2.3", "1.2.4", "1.2.4"), | ||
("0.0.0-dev0", "0.0.0-dev1", "0.0.0-dev1"), | ||
("0.0.0", "99.99.99-dev1", "0.0.0"), | ||
]) | ||
@pytest.mark.parametrize("prop", [None, "semver", "other"]) | ||
def test_latest_collection_version(ref, dif, exp, prop): | ||
reference = semver.VersionInfo.parse(ref) | ||
difference = semver.VersionInfo.parse(dif) | ||
expected = ref if exp == ref else dif | ||
|
||
opprop = {} | ||
if prop is None: | ||
expprop = "semver" | ||
else: | ||
opprop["property"] = expprop = prop | ||
|
||
# ensure we didn't mess up the test cases | ||
assert expected in [reference, difference] | ||
|
||
result = _latest_collection_version({expprop: reference}, {expprop: difference}, **opprop) | ||
|
||
assert result[expprop] == expected |