Skip to content

Commit

Permalink
Nightly version glob (#2062)
Browse files Browse the repository at this point in the history
* add nightly+beta glob version tests

* add a nightly version test

* test_compare

* flip_eq

* either_eq

* fix docstring
  • Loading branch information
escapewindow authored Jun 16, 2021
1 parent bae8b92 commit ea71cb4
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 2 deletions.
24 changes: 22 additions & 2 deletions src/auslib/util/comparison.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,29 @@ def has_operator(value):
return value.startswith(("<", ">"))


def either_eq(value, operand):
"""The order of eq matters with GlobVersion; test both orders.
Nightly: because StrictVersion also compares self.prerelease,
StrictVersion("70.0a1") != GlobVersion("70.*"), but
GlobVersion("70.*") == StrictVersion("70.0a1")
dot-0: because StrictVersion can drop the trailing .0,
GlobVersion("80.0.*") != StrictVersion("80.0.0"), but
StrictVersion("80.0.0") == GlobVersion("80.0.*")
Because of this, let's test eq in both directions.
"""
return operator.eq(value, operand) or operator.eq(operand, value)


def get_op(pattern):
# only alphanumeric or glob characters means no operator
if re.match(r"[\w\*]+", pattern):
# ending with a glob means either_eq
if pattern.endswith("*"):
return either_eq, pattern
# only alphanumeric characters means no operator
if re.match(r"\w+", pattern):
return operator.eq, pattern
for op in operators:
m = re.match(r"(%s)([\.\w]+)" % op, pattern)
Expand Down
21 changes: 21 additions & 0 deletions tests/util/test_compare.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import pytest

from auslib.util.comparison import version_compare


@pytest.mark.parametrize(
"version, glob, expected",
(
("80.0.0", "80.0.*", True),
("80.0.1", "80.0.*", True),
("800.0.1", "80.0.*", False),
("80.1.90", "80.1.*", True),
("80.10.0", "80.1.*", False),
("80.1.0", "80.*", True),
("80.9.89", "80.*", True),
("80.0a1", "80.*", True),
("89.89.0", "80.*", False),
),
)
def test_glob_version(version, glob, expected):
assert version_compare(version, glob) is expected
2 changes: 2 additions & 0 deletions tests/util/test_versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,5 @@ def test_glob(self):
self.assertNotEqual(version.version, MozillaVersion("78.80.0").version)
self.assertEqual(version.prerelease, None)
self.assertEqual(str(version), "78.8.*")
version2 = MozillaVersion("78.*")
self.assertEqual(version2.version, MozillaVersion("78.0a1").version)

0 comments on commit ea71cb4

Please sign in to comment.