Skip to content

Commit

Permalink
#140 - Apply black format
Browse files Browse the repository at this point in the history
Signed-off-by: Chin Yeung Li <[email protected]>
  • Loading branch information
chinyeungli committed Aug 20, 2024
1 parent a1900af commit 3b3787a
Show file tree
Hide file tree
Showing 10 changed files with 106 additions and 209 deletions.
24 changes: 8 additions & 16 deletions tests/test_conan_version_range.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,21 @@
["<2.0", [[["<", "2.0"]]], ["1.0.1"], ["2.1"]],
[">1 <2.0", [[[">", "1"], ["<", "2.0"]]], ["1.5.1"], ["0.1", "2.1"]],
# tilde
["~2.5", [[[">=", "2.5"], ["<", "2.6-"]]],
["2.5.0", "2.5.3"], ["2.7", "2.6.1"]],
["~2.5.1", [[[">=", "2.5.1"], ["<", "2.6.0-"]]],
["2.5.1", "2.5.3"], ["2.5", "2.6.1"]],
["~2.5", [[[">=", "2.5"], ["<", "2.6-"]]], ["2.5.0", "2.5.3"], ["2.7", "2.6.1"]],
["~2.5.1", [[[">=", "2.5.1"], ["<", "2.6.0-"]]], ["2.5.1", "2.5.3"], ["2.5", "2.6.1"]],
["~1", [[[">=", "1"], ["<", "2-"]]], ["1.3", "1.8.1"], ["0.8", "2.2"]],
# caret
["^1.2", [[[">=", "1.2"], ["<", "2.0-"]]],
["1.2.1", "1.51"], ["1", "2", "2.0.1"]],
["^1.2.3", [[[">=", "1.2.3"], ["<", "2.0.0-"]]],
["1.2.3", "1.2.4"], ["2", "2.1", "2.0.1"]],
["^0.1.2", [[[">=", "0.1.2"], ["<", "0.2.0-"]]],
["0.1.3", "0.1.44"], ["1", "0.3", "0.2.1"]],
["^1.2", [[[">=", "1.2"], ["<", "2.0-"]]], ["1.2.1", "1.51"], ["1", "2", "2.0.1"]],
["^1.2.3", [[[">=", "1.2.3"], ["<", "2.0.0-"]]], ["1.2.3", "1.2.4"], ["2", "2.1", "2.0.1"]],
["^0.1.2", [[[">=", "0.1.2"], ["<", "0.2.0-"]]], ["0.1.3", "0.1.44"], ["1", "0.3", "0.2.1"]],
# Identity
["1.0.0", [[["=", "1.0.0"]]], ["1.0.0"], ["2", "1.0.1"]],
["=1.0.0", [[["=", "1.0.0"]]], ["1.0.0"], ["2", "1.0.1"]],
# Any
["*", [[[">=", "0.0.0"]]], ["1.0", "a.b"], []],
["", [[[">=", "0.0.0"]]], ["1.0", "a.b"], []],
# Unions
["1.0.0 || 2.1.3", [[["=", "1.0.0"]], [["=", "2.1.3"]]],
["1.0.0", "2.1.3"], ["2", "1.0.1"]],
["1.0.0 || 2.1.3", [[["=", "1.0.0"]], [["=", "2.1.3"]]], ["1.0.0", "2.1.3"], ["2", "1.0.1"]],
[
">1 <2.0 || ^3.2 ",
[[[">", "1"], ["<", "2.0"]], [[">=", "3.2"], ["<", "4.0-"]]],
Expand All @@ -53,10 +47,8 @@
["1.5-a1", "3.3"],
["3.3-a1"],
],
["^1.1.2-", [[[">=", "1.1.2"], ["<", "2.0.0-"]]],
["1.2.3", "1.2.0-alpha1"], ["2.0.0-alpha1"]],
["~1.1.2-", [[[">=", "1.1.2"], ["<", "1.2.0-"]]],
["1.1.3", "1.1.3-alpha1"], ["1.2.0-alpha1"]],
["^1.1.2-", [[[">=", "1.1.2"], ["<", "2.0.0-"]]], ["1.2.3", "1.2.0-alpha1"], ["2.0.0-alpha1"]],
["~1.1.2-", [[[">=", "1.1.2"], ["<", "1.2.0-"]]], ["1.1.3", "1.1.3-alpha1"], ["1.2.0-alpha1"]],
]


Expand Down
15 changes: 5 additions & 10 deletions tests/test_debian_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,7 @@ def test_compare_strings(self):
def test_compare_strings_can_sort(self):
# taken from
# http://www.debian.org/doc/debian-policy/ch-controlfields.html#s-f-Version
result = sorted(["a", "", "~", "~~a", "~~"],
key=version.compare_strings_key)
result = sorted(["a", "", "~", "~~a", "~~"], key=version.compare_strings_key)
expected = ["~~", "~~a", "~", "", "a"]
assert expected == result

Expand Down Expand Up @@ -152,10 +151,8 @@ def test_compare_versions(self):
assert compare_versions("9.0.0", "10.0.0") == -1

assert compare_versions("1.2.3-1~deb7u1", "1.2.3-1") == -1
assert compare_versions(
"2.7.4+reloaded2-13ubuntu1", "2.7.4+reloaded2-13+deb9u1") == -1
assert compare_versions("2.7.4+reloaded2-13",
"2.7.4+reloaded2-13+deb9u1") == -1
assert compare_versions("2.7.4+reloaded2-13ubuntu1", "2.7.4+reloaded2-13+deb9u1") == -1
assert compare_versions("2.7.4+reloaded2-13", "2.7.4+reloaded2-13+deb9u1") == -1

# greater than
assert compare_versions("0.0.1-0", "0:0.0.0") == 1
Expand All @@ -166,10 +163,8 @@ def test_compare_versions(self):
assert compare_versions("9.0.0", "1.0.0") == 1

assert compare_versions("1.2.3-1", "1.2.3-1~deb7u1") == 1
assert compare_versions(
"2.7.4+reloaded2-13+deb9u1", "2.7.4+reloaded2-13ubuntu1") == 1
assert compare_versions(
"2.7.4+reloaded2-13+deb9u1", "2.7.4+reloaded2-13") == 1
assert compare_versions("2.7.4+reloaded2-13+deb9u1", "2.7.4+reloaded2-13ubuntu1") == 1
assert compare_versions("2.7.4+reloaded2-13+deb9u1", "2.7.4+reloaded2-13") == 1

# unicode
assert compare_versions("2:0.0.44-1", "2:0.0.44-nobin") == -1
Expand Down
3 changes: 1 addition & 2 deletions tests/test_debian_version_python_deb_pkg_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ def test_version_sorting(self):
# Check version sorting implemented on top of `=' and `<<' comparisons.
expected_order = ["0.1", "0.5", "1.0", "2.0", "3.0", "1:0.4", "2:0.3"]
assert list(sorted(expected_order)) != expected_order
result = [str(v)
for v in sorted(map(Version.from_string, expected_order))]
result = [str(v) for v in sorted(map(Version.from_string, expected_order))]
assert result == expected_order

def test_version_comparison(self):
Expand Down
9 changes: 3 additions & 6 deletions tests/test_gentoo_pkgcore.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,10 @@ def generate_misc_sufs():
suf_nums = list(range(100))
shuffle(suf_nums)

good_sufs = simple_good_sufs + \
[f"{x}{suf_nums.pop()}" for x in simple_good_sufs]
good_sufs = simple_good_sufs + [f"{x}{suf_nums.pop()}" for x in simple_good_sufs]

l = len(good_sufs)
good_sufs = good_sufs + [good_sufs[x] +
good_sufs[l - x - 1] for x in range(l)]
good_sufs = good_sufs + [good_sufs[x] + good_sufs[l - x - 1] for x in range(l)]

bad_sufs = ["_a", "_9", "_"] + [x + " " for x in simple_good_sufs]
return good_sufs, bad_sufs
Expand Down Expand Up @@ -65,8 +63,7 @@ def test_parse_version_and_revisions(self):
v_r = parse_version_and_revision(version)
expected_rev = rev.lstrip("-r")
expected_rev = expected_rev and int(expected_rev) or 0
assert v_r == (
ver, expected_rev), f"Failed to parse: {version}"
assert v_r == (ver, expected_rev), f"Failed to parse: {version}"
except Exception as e:
raise Exception(f"Failed to parse: {version!r}") from e

Expand Down
15 changes: 6 additions & 9 deletions tests/test_maven_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,7 @@ def test_from_string(self):

for test, expected in test_pairs:
v = Version(test)
assert v._parsed == expected, "Version(%s) == %s, want %s" % (
test, v._parsed, expected)
assert v._parsed == expected, "Version(%s) == %s, want %s" % (test, v._parsed, expected)

def test_version_qualifiers(self):
version_qualifiers = (
Expand Down Expand Up @@ -269,7 +268,7 @@ def test_version_qualifiers(self):
"1-123",
)
for idx, low in enumerate(version_qualifiers[:-1]):
for high in version_qualifiers[idx + 1:]:
for high in version_qualifiers[idx + 1 :]:
self._assert_version_order(low, high)

def test_version_numbers(self):
Expand Down Expand Up @@ -301,7 +300,7 @@ def test_version_numbers(self):
"11m",
)
for idx, low in enumerate(version_numbers[:-1]):
for high in version_numbers[idx + 1:]:
for high in version_numbers[idx + 1 :]:
self._assert_version_order(low, high)

unicode_version_numbers = (
Expand Down Expand Up @@ -333,7 +332,7 @@ def test_version_numbers(self):
"11m",
)
for idx, low in enumerate(unicode_version_numbers[:-1]):
for high in unicode_version_numbers[idx + 1:]:
for high in unicode_version_numbers[idx + 1 :]:
self._assert_version_order(low, high)

def test_version_equality(self):
Expand Down Expand Up @@ -623,8 +622,7 @@ def test_compare(self):
def test_str(self):
for inp in ("[1.0,2.0]", "1.0"):
actual = str(VersionRange(inp))
assert inp == actual, "VersionRange(%s) == %s, wanted %s" % (
inp, actual, inp)
assert inp == actual, "VersionRange(%s) == %s, wanted %s" % (inp, actual, inp)

def test_fromversion(self):
v = Version("1.0")
Expand All @@ -633,8 +631,7 @@ def test_fromversion(self):
assert vr.version == v

def test_match_versions(self):
versions = [Version("0.1"), Version("1.0"), Version(
"1.1"), Version("2.0"), Version("2.1")]
versions = [Version("0.1"), Version("1.0"), Version("1.1"), Version("2.0"), Version("2.1")]
vr = VersionRange("(1.0,2.0]")
assert vr.match_version(versions) == "2.0"
assert vr.match_version(versions[:3]) == "1.1"
51 changes: 17 additions & 34 deletions tests/test_maven_version_range.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@ def test_maven_version_range_from_native_with_lower_inclusive():
version_range = MavenVersionRange.from_native("[1.0.0,2.0.0)")
assert version_range == MavenVersionRange(
constraints=(
VersionConstraint(
comparator=">=", version=MavenVersion(string="1.0.0")),
VersionConstraint(
comparator="<", version=MavenVersion(string="2.0.0")),
VersionConstraint(comparator=">=", version=MavenVersion(string="1.0.0")),
VersionConstraint(comparator="<", version=MavenVersion(string="2.0.0")),
)
)

Expand All @@ -25,19 +23,16 @@ def test_maven_version_range_from_native_with_nothing_inclusive():
version_range = MavenVersionRange.from_native(" ( 1.0.0 , 2.1.4 ) ")
assert version_range == MavenVersionRange(
constraints=(
VersionConstraint(
comparator=">", version=MavenVersion(string="1.0.0")),
VersionConstraint(
comparator="<", version=MavenVersion(string="2.1.4")),
VersionConstraint(comparator=">", version=MavenVersion(string="1.0.0")),
VersionConstraint(comparator="<", version=MavenVersion(string="2.1.4")),
)
)


def test_maven_version_range_from_native_for_pinned_version():
version_range = MavenVersionRange.from_native("[1.0.0]")
assert version_range == MavenVersionRange(
constraints=(VersionConstraint(comparator="=",
version=MavenVersion(string="1.0.0")),)
constraints=(VersionConstraint(comparator="=", version=MavenVersion(string="1.0.0")),)
)


Expand All @@ -55,38 +50,26 @@ def test_maven_version_range_from_native_str_representation():


def test_maven_version_range_from_native_for_multiple_version_ranges():
version_range = MavenVersionRange.from_native(
"[2.0,2.3.1] , [2.4.0,2.12.2) , [2.13.0,2.15.0)")
version_range = MavenVersionRange.from_native("[2.0,2.3.1] , [2.4.0,2.12.2) , [2.13.0,2.15.0)")
assert version_range == MavenVersionRange(
constraints=(
VersionConstraint(
comparator=">=", version=MavenVersion(string="2.0")),
VersionConstraint(
comparator="<=", version=MavenVersion(string="2.3.1")),
VersionConstraint(
comparator=">=", version=MavenVersion(string="2.4.0")),
VersionConstraint(
comparator="<", version=MavenVersion(string="2.12.2")),
VersionConstraint(
comparator=">=", version=MavenVersion(string="2.13.0")),
VersionConstraint(
comparator="<", version=MavenVersion(string="2.15.0")),
VersionConstraint(comparator=">=", version=MavenVersion(string="2.0")),
VersionConstraint(comparator="<=", version=MavenVersion(string="2.3.1")),
VersionConstraint(comparator=">=", version=MavenVersion(string="2.4.0")),
VersionConstraint(comparator="<", version=MavenVersion(string="2.12.2")),
VersionConstraint(comparator=">=", version=MavenVersion(string="2.13.0")),
VersionConstraint(comparator="<", version=MavenVersion(string="2.15.0")),
)
)


def test_maven_version_range_from_native_for_multiple_pinned_versions_and_a_range():
version_range = MavenVersionRange.from_native(
"[2.0] , [2.4.0] , [2.13.0,2.15.0)")
version_range = MavenVersionRange.from_native("[2.0] , [2.4.0] , [2.13.0,2.15.0)")
assert version_range == MavenVersionRange(
constraints=(
VersionConstraint(
comparator="=", version=MavenVersion(string="2.0")),
VersionConstraint(
comparator="=", version=MavenVersion(string="2.4.0")),
VersionConstraint(
comparator=">=", version=MavenVersion(string="2.13.0")),
VersionConstraint(
comparator="<", version=MavenVersion(string="2.15.0")),
VersionConstraint(comparator="=", version=MavenVersion(string="2.0")),
VersionConstraint(comparator="=", version=MavenVersion(string="2.4.0")),
VersionConstraint(comparator=">=", version=MavenVersion(string="2.13.0")),
VersionConstraint(comparator="<", version=MavenVersion(string="2.15.0")),
)
)
3 changes: 1 addition & 2 deletions tests/test_openssl_versort.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ def test_openssl_version_sort(self):
results = [OpensslVersion(x.strip()) for x in all_openssl_versions]
results.sort()
results = [version_to_dict(x) for x in results]
expected_file = self.get_test_loc(
"openssl_versort_expected.json", must_exist=False)
expected_file = self.get_test_loc("openssl_versort_expected.json", must_exist=False)
util_tests.check_results_against_json(results, expected_file)


Expand Down
6 changes: 2 additions & 4 deletions tests/test_rpm_vercmp.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,7 @@ def create_test_function(ver1, ver2, expected, name):
def test_rpm_version(self):
ver1_str = str(ver1).encode("utf-8")
ver2_str = str(ver2).encode("utf-8")
print(
f"testing (ver1={ver1_str}, ver2={ver2_str}, expected=expected{expected}")
print(f"testing (ver1={ver1_str}, ver2={ver2_str}, expected=expected{expected}")
result = vercmp.vercmp(ver1, ver2)
if result != expected:
assert result == (expected, ver1, ver2)
Expand All @@ -93,8 +92,7 @@ def get_tests():
test_file = os.path.join(os.path.dirname(__file__), "data", "rpmvercmp.at")

with io.open(test_file, encoding="utf-8") as rpmtests:
tests = list(parse_rpmvercmp_tests(
rpmtests, with_buggy_comparisons=True))
tests = list(parse_rpmvercmp_tests(rpmtests, with_buggy_comparisons=True))
for test_count, (ver1, ver2, expected) in enumerate(tests, 1):
name = f"test_rpm_version_{test_count}"
yield create_test_function(ver1, ver2, expected, name)
Expand Down
Loading

0 comments on commit 3b3787a

Please sign in to comment.