Skip to content

Commit 3b3787a

Browse files
committed
#140 - Apply black format
Signed-off-by: Chin Yeung Li <tli@nexb.com>
1 parent a1900af commit 3b3787a

10 files changed

Lines changed: 106 additions & 209 deletions

tests/test_conan_version_range.py

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,27 +15,21 @@
1515
["<2.0", [[["<", "2.0"]]], ["1.0.1"], ["2.1"]],
1616
[">1 <2.0", [[[">", "1"], ["<", "2.0"]]], ["1.5.1"], ["0.1", "2.1"]],
1717
# tilde
18-
["~2.5", [[[">=", "2.5"], ["<", "2.6-"]]],
19-
["2.5.0", "2.5.3"], ["2.7", "2.6.1"]],
20-
["~2.5.1", [[[">=", "2.5.1"], ["<", "2.6.0-"]]],
21-
["2.5.1", "2.5.3"], ["2.5", "2.6.1"]],
18+
["~2.5", [[[">=", "2.5"], ["<", "2.6-"]]], ["2.5.0", "2.5.3"], ["2.7", "2.6.1"]],
19+
["~2.5.1", [[[">=", "2.5.1"], ["<", "2.6.0-"]]], ["2.5.1", "2.5.3"], ["2.5", "2.6.1"]],
2220
["~1", [[[">=", "1"], ["<", "2-"]]], ["1.3", "1.8.1"], ["0.8", "2.2"]],
2321
# caret
24-
["^1.2", [[[">=", "1.2"], ["<", "2.0-"]]],
25-
["1.2.1", "1.51"], ["1", "2", "2.0.1"]],
26-
["^1.2.3", [[[">=", "1.2.3"], ["<", "2.0.0-"]]],
27-
["1.2.3", "1.2.4"], ["2", "2.1", "2.0.1"]],
28-
["^0.1.2", [[[">=", "0.1.2"], ["<", "0.2.0-"]]],
29-
["0.1.3", "0.1.44"], ["1", "0.3", "0.2.1"]],
22+
["^1.2", [[[">=", "1.2"], ["<", "2.0-"]]], ["1.2.1", "1.51"], ["1", "2", "2.0.1"]],
23+
["^1.2.3", [[[">=", "1.2.3"], ["<", "2.0.0-"]]], ["1.2.3", "1.2.4"], ["2", "2.1", "2.0.1"]],
24+
["^0.1.2", [[[">=", "0.1.2"], ["<", "0.2.0-"]]], ["0.1.3", "0.1.44"], ["1", "0.3", "0.2.1"]],
3025
# Identity
3126
["1.0.0", [[["=", "1.0.0"]]], ["1.0.0"], ["2", "1.0.1"]],
3227
["=1.0.0", [[["=", "1.0.0"]]], ["1.0.0"], ["2", "1.0.1"]],
3328
# Any
3429
["*", [[[">=", "0.0.0"]]], ["1.0", "a.b"], []],
3530
["", [[[">=", "0.0.0"]]], ["1.0", "a.b"], []],
3631
# Unions
37-
["1.0.0 || 2.1.3", [[["=", "1.0.0"]], [["=", "2.1.3"]]],
38-
["1.0.0", "2.1.3"], ["2", "1.0.1"]],
32+
["1.0.0 || 2.1.3", [[["=", "1.0.0"]], [["=", "2.1.3"]]], ["1.0.0", "2.1.3"], ["2", "1.0.1"]],
3933
[
4034
">1 <2.0 || ^3.2 ",
4135
[[[">", "1"], ["<", "2.0"]], [[">=", "3.2"], ["<", "4.0-"]]],
@@ -53,10 +47,8 @@
5347
["1.5-a1", "3.3"],
5448
["3.3-a1"],
5549
],
56-
["^1.1.2-", [[[">=", "1.1.2"], ["<", "2.0.0-"]]],
57-
["1.2.3", "1.2.0-alpha1"], ["2.0.0-alpha1"]],
58-
["~1.1.2-", [[[">=", "1.1.2"], ["<", "1.2.0-"]]],
59-
["1.1.3", "1.1.3-alpha1"], ["1.2.0-alpha1"]],
50+
["^1.1.2-", [[[">=", "1.1.2"], ["<", "2.0.0-"]]], ["1.2.3", "1.2.0-alpha1"], ["2.0.0-alpha1"]],
51+
["~1.1.2-", [[[">=", "1.1.2"], ["<", "1.2.0-"]]], ["1.1.3", "1.1.3-alpha1"], ["1.2.0-alpha1"]],
6052
]
6153

6254

tests/test_debian_version.py

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,7 @@ def test_compare_strings(self):
9191
def test_compare_strings_can_sort(self):
9292
# taken from
9393
# http://www.debian.org/doc/debian-policy/ch-controlfields.html#s-f-Version
94-
result = sorted(["a", "", "~", "~~a", "~~"],
95-
key=version.compare_strings_key)
94+
result = sorted(["a", "", "~", "~~a", "~~"], key=version.compare_strings_key)
9695
expected = ["~~", "~~a", "~", "", "a"]
9796
assert expected == result
9897

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

154153
assert compare_versions("1.2.3-1~deb7u1", "1.2.3-1") == -1
155-
assert compare_versions(
156-
"2.7.4+reloaded2-13ubuntu1", "2.7.4+reloaded2-13+deb9u1") == -1
157-
assert compare_versions("2.7.4+reloaded2-13",
158-
"2.7.4+reloaded2-13+deb9u1") == -1
154+
assert compare_versions("2.7.4+reloaded2-13ubuntu1", "2.7.4+reloaded2-13+deb9u1") == -1
155+
assert compare_versions("2.7.4+reloaded2-13", "2.7.4+reloaded2-13+deb9u1") == -1
159156

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

168165
assert compare_versions("1.2.3-1", "1.2.3-1~deb7u1") == 1
169-
assert compare_versions(
170-
"2.7.4+reloaded2-13+deb9u1", "2.7.4+reloaded2-13ubuntu1") == 1
171-
assert compare_versions(
172-
"2.7.4+reloaded2-13+deb9u1", "2.7.4+reloaded2-13") == 1
166+
assert compare_versions("2.7.4+reloaded2-13+deb9u1", "2.7.4+reloaded2-13ubuntu1") == 1
167+
assert compare_versions("2.7.4+reloaded2-13+deb9u1", "2.7.4+reloaded2-13") == 1
173168

174169
# unicode
175170
assert compare_versions("2:0.0.44-1", "2:0.0.44-nobin") == -1

tests/test_debian_version_python_deb_pkg_tools.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ def test_version_sorting(self):
1616
# Check version sorting implemented on top of `=' and `<<' comparisons.
1717
expected_order = ["0.1", "0.5", "1.0", "2.0", "3.0", "1:0.4", "2:0.3"]
1818
assert list(sorted(expected_order)) != expected_order
19-
result = [str(v)
20-
for v in sorted(map(Version.from_string, expected_order))]
19+
result = [str(v) for v in sorted(map(Version.from_string, expected_order))]
2120
assert result == expected_order
2221

2322
def test_version_comparison(self):

tests/test_gentoo_pkgcore.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,10 @@ def generate_misc_sufs():
1616
suf_nums = list(range(100))
1717
shuffle(suf_nums)
1818

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

2221
l = len(good_sufs)
23-
good_sufs = good_sufs + [good_sufs[x] +
24-
good_sufs[l - x - 1] for x in range(l)]
22+
good_sufs = good_sufs + [good_sufs[x] + good_sufs[l - x - 1] for x in range(l)]
2523

2624
bad_sufs = ["_a", "_9", "_"] + [x + " " for x in simple_good_sufs]
2725
return good_sufs, bad_sufs
@@ -65,8 +63,7 @@ def test_parse_version_and_revisions(self):
6563
v_r = parse_version_and_revision(version)
6664
expected_rev = rev.lstrip("-r")
6765
expected_rev = expected_rev and int(expected_rev) or 0
68-
assert v_r == (
69-
ver, expected_rev), f"Failed to parse: {version}"
66+
assert v_r == (ver, expected_rev), f"Failed to parse: {version}"
7067
except Exception as e:
7168
raise Exception(f"Failed to parse: {version!r}") from e
7269

tests/test_maven_version.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -240,8 +240,7 @@ def test_from_string(self):
240240

241241
for test, expected in test_pairs:
242242
v = Version(test)
243-
assert v._parsed == expected, "Version(%s) == %s, want %s" % (
244-
test, v._parsed, expected)
243+
assert v._parsed == expected, "Version(%s) == %s, want %s" % (test, v._parsed, expected)
245244

246245
def test_version_qualifiers(self):
247246
version_qualifiers = (
@@ -269,7 +268,7 @@ def test_version_qualifiers(self):
269268
"1-123",
270269
)
271270
for idx, low in enumerate(version_qualifiers[:-1]):
272-
for high in version_qualifiers[idx + 1:]:
271+
for high in version_qualifiers[idx + 1 :]:
273272
self._assert_version_order(low, high)
274273

275274
def test_version_numbers(self):
@@ -301,7 +300,7 @@ def test_version_numbers(self):
301300
"11m",
302301
)
303302
for idx, low in enumerate(version_numbers[:-1]):
304-
for high in version_numbers[idx + 1:]:
303+
for high in version_numbers[idx + 1 :]:
305304
self._assert_version_order(low, high)
306305

307306
unicode_version_numbers = (
@@ -333,7 +332,7 @@ def test_version_numbers(self):
333332
"11m",
334333
)
335334
for idx, low in enumerate(unicode_version_numbers[:-1]):
336-
for high in unicode_version_numbers[idx + 1:]:
335+
for high in unicode_version_numbers[idx + 1 :]:
337336
self._assert_version_order(low, high)
338337

339338
def test_version_equality(self):
@@ -623,8 +622,7 @@ def test_compare(self):
623622
def test_str(self):
624623
for inp in ("[1.0,2.0]", "1.0"):
625624
actual = str(VersionRange(inp))
626-
assert inp == actual, "VersionRange(%s) == %s, wanted %s" % (
627-
inp, actual, inp)
625+
assert inp == actual, "VersionRange(%s) == %s, wanted %s" % (inp, actual, inp)
628626

629627
def test_fromversion(self):
630628
v = Version("1.0")
@@ -633,8 +631,7 @@ def test_fromversion(self):
633631
assert vr.version == v
634632

635633
def test_match_versions(self):
636-
versions = [Version("0.1"), Version("1.0"), Version(
637-
"1.1"), Version("2.0"), Version("2.1")]
634+
versions = [Version("0.1"), Version("1.0"), Version("1.1"), Version("2.0"), Version("2.1")]
638635
vr = VersionRange("(1.0,2.0]")
639636
assert vr.match_version(versions) == "2.0"
640637
assert vr.match_version(versions[:3]) == "1.1"

tests/test_maven_version_range.py

Lines changed: 17 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,8 @@ def test_maven_version_range_from_native_with_lower_inclusive():
1313
version_range = MavenVersionRange.from_native("[1.0.0,2.0.0)")
1414
assert version_range == MavenVersionRange(
1515
constraints=(
16-
VersionConstraint(
17-
comparator=">=", version=MavenVersion(string="1.0.0")),
18-
VersionConstraint(
19-
comparator="<", version=MavenVersion(string="2.0.0")),
16+
VersionConstraint(comparator=">=", version=MavenVersion(string="1.0.0")),
17+
VersionConstraint(comparator="<", version=MavenVersion(string="2.0.0")),
2018
)
2119
)
2220

@@ -25,19 +23,16 @@ def test_maven_version_range_from_native_with_nothing_inclusive():
2523
version_range = MavenVersionRange.from_native(" ( 1.0.0 , 2.1.4 ) ")
2624
assert version_range == MavenVersionRange(
2725
constraints=(
28-
VersionConstraint(
29-
comparator=">", version=MavenVersion(string="1.0.0")),
30-
VersionConstraint(
31-
comparator="<", version=MavenVersion(string="2.1.4")),
26+
VersionConstraint(comparator=">", version=MavenVersion(string="1.0.0")),
27+
VersionConstraint(comparator="<", version=MavenVersion(string="2.1.4")),
3228
)
3329
)
3430

3531

3632
def test_maven_version_range_from_native_for_pinned_version():
3733
version_range = MavenVersionRange.from_native("[1.0.0]")
3834
assert version_range == MavenVersionRange(
39-
constraints=(VersionConstraint(comparator="=",
40-
version=MavenVersion(string="1.0.0")),)
35+
constraints=(VersionConstraint(comparator="=", version=MavenVersion(string="1.0.0")),)
4136
)
4237

4338

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

5651

5752
def test_maven_version_range_from_native_for_multiple_version_ranges():
58-
version_range = MavenVersionRange.from_native(
59-
"[2.0,2.3.1] , [2.4.0,2.12.2) , [2.13.0,2.15.0)")
53+
version_range = MavenVersionRange.from_native("[2.0,2.3.1] , [2.4.0,2.12.2) , [2.13.0,2.15.0)")
6054
assert version_range == MavenVersionRange(
6155
constraints=(
62-
VersionConstraint(
63-
comparator=">=", version=MavenVersion(string="2.0")),
64-
VersionConstraint(
65-
comparator="<=", version=MavenVersion(string="2.3.1")),
66-
VersionConstraint(
67-
comparator=">=", version=MavenVersion(string="2.4.0")),
68-
VersionConstraint(
69-
comparator="<", version=MavenVersion(string="2.12.2")),
70-
VersionConstraint(
71-
comparator=">=", version=MavenVersion(string="2.13.0")),
72-
VersionConstraint(
73-
comparator="<", version=MavenVersion(string="2.15.0")),
56+
VersionConstraint(comparator=">=", version=MavenVersion(string="2.0")),
57+
VersionConstraint(comparator="<=", version=MavenVersion(string="2.3.1")),
58+
VersionConstraint(comparator=">=", version=MavenVersion(string="2.4.0")),
59+
VersionConstraint(comparator="<", version=MavenVersion(string="2.12.2")),
60+
VersionConstraint(comparator=">=", version=MavenVersion(string="2.13.0")),
61+
VersionConstraint(comparator="<", version=MavenVersion(string="2.15.0")),
7462
)
7563
)
7664

7765

7866
def test_maven_version_range_from_native_for_multiple_pinned_versions_and_a_range():
79-
version_range = MavenVersionRange.from_native(
80-
"[2.0] , [2.4.0] , [2.13.0,2.15.0)")
67+
version_range = MavenVersionRange.from_native("[2.0] , [2.4.0] , [2.13.0,2.15.0)")
8168
assert version_range == MavenVersionRange(
8269
constraints=(
83-
VersionConstraint(
84-
comparator="=", version=MavenVersion(string="2.0")),
85-
VersionConstraint(
86-
comparator="=", version=MavenVersion(string="2.4.0")),
87-
VersionConstraint(
88-
comparator=">=", version=MavenVersion(string="2.13.0")),
89-
VersionConstraint(
90-
comparator="<", version=MavenVersion(string="2.15.0")),
70+
VersionConstraint(comparator="=", version=MavenVersion(string="2.0")),
71+
VersionConstraint(comparator="=", version=MavenVersion(string="2.4.0")),
72+
VersionConstraint(comparator=">=", version=MavenVersion(string="2.13.0")),
73+
VersionConstraint(comparator="<", version=MavenVersion(string="2.15.0")),
9174
)
9275
)

tests/test_openssl_versort.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@ def test_openssl_version_sort(self):
2222
results = [OpensslVersion(x.strip()) for x in all_openssl_versions]
2323
results.sort()
2424
results = [version_to_dict(x) for x in results]
25-
expected_file = self.get_test_loc(
26-
"openssl_versort_expected.json", must_exist=False)
25+
expected_file = self.get_test_loc("openssl_versort_expected.json", must_exist=False)
2726
util_tests.check_results_against_json(results, expected_file)
2827

2928

tests/test_rpm_vercmp.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,7 @@ def create_test_function(ver1, ver2, expected, name):
7676
def test_rpm_version(self):
7777
ver1_str = str(ver1).encode("utf-8")
7878
ver2_str = str(ver2).encode("utf-8")
79-
print(
80-
f"testing (ver1={ver1_str}, ver2={ver2_str}, expected=expected{expected}")
79+
print(f"testing (ver1={ver1_str}, ver2={ver2_str}, expected=expected{expected}")
8180
result = vercmp.vercmp(ver1, ver2)
8281
if result != expected:
8382
assert result == (expected, ver1, ver2)
@@ -93,8 +92,7 @@ def get_tests():
9392
test_file = os.path.join(os.path.dirname(__file__), "data", "rpmvercmp.at")
9493

9594
with io.open(test_file, encoding="utf-8") as rpmtests:
96-
tests = list(parse_rpmvercmp_tests(
97-
rpmtests, with_buggy_comparisons=True))
95+
tests = list(parse_rpmvercmp_tests(rpmtests, with_buggy_comparisons=True))
9896
for test_count, (ver1, ver2, expected) in enumerate(tests, 1):
9997
name = f"test_rpm_version_{test_count}"
10098
yield create_test_function(ver1, ver2, expected, name)

0 commit comments

Comments
 (0)