Skip to content

Commit

Permalink
Fix code formatting
Browse files Browse the repository at this point in the history
Signed-off-by: Keshav Priyadarshi <[email protected]>
  • Loading branch information
keshav-space committed Jan 3, 2024
1 parent 7757ea0 commit bb7a7fd
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 39 deletions.
19 changes: 11 additions & 8 deletions src/univers/version_range.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,9 +223,9 @@ def __contains__(self, version):

def __eq__(self, other):
return (
self.scheme == other.scheme
and self.version_class == other.version_class
and self.constraints == other.constraints
self.scheme == other.scheme
and self.version_class == other.version_class
and self.constraints == other.constraints
)


Expand Down Expand Up @@ -355,9 +355,9 @@ def from_native(cls, string):
)
else:
if (
constraint.endswith(".x")
or constraint.startswith("~")
or constraint.startswith("^")
constraint.endswith(".x")
or constraint.startswith("~")
or constraint.startswith("^")
):
constraints.extend(
get_npm_version_constraints_from_semver_npm_spec(
Expand Down Expand Up @@ -949,7 +949,8 @@ def from_native(cls, string):
if "*" in version:
if "*" in version and not version.endswith("*") or constraints:
raise InvalidVersionRange(
f"Unsupported star in the middle of a version: it should be a trailing star only: {string}")
f"Unsupported star in the middle of a version: it should be a trailing star only: {string}"
)

if version.endswith(".*.*"):
version = version.replace(".*.*", ".*")
Expand Down Expand Up @@ -999,7 +1000,9 @@ def from_native(cls, string):

else:
comparator, version = VersionConstraint.split(version)
constraint = VersionConstraint(comparator=comparator, version=cls.version_class(version))
constraint = VersionConstraint(
comparator=comparator, version=cls.version_class(version)
)
constraints.append(constraint)

return cls(constraints=tuple(constraints))
Expand Down
47 changes: 16 additions & 31 deletions tests/test_cargo_version_range.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,95 +11,80 @@
# tilde
["~1.2.3", [[">=", "1.2.3"], ["<", "1.3.0"]], ["1.2.4"], ["2.0.1"]],
["~1.2", [[">=", "1.2.0"], ["<", "1.3.0"]], ["1.2.5"], ["1.3.1"]],
["~1", [[">=", "1.0.0"], ["<", "2.0.0"]], ["1.3.0", "1.8.1"], ["2.1.0", "2.2"]], # tilde increment the major
[
"~1",
[[">=", "1.0.0"], ["<", "2.0.0"]],
["1.3.0", "1.8.1"],
["2.1.0", "2.2"],
], # tilde increment the major
# wildcard
["*", [[">=", "0.0.0"]], ["1.0.0", "2.0.0"], []],
["1.*", [], ["1.0.0"], ["2"]],
["1.2.*", [[">=", "1.2.0"], ["<", "1.3.0"]], ["1.2", "1.2.1"], ["2.1.0", "2.2"]],

# https://github.com/dtolnay/semver/blob/master/tests/test_version_req.rs :

# test_basic
# ["^1.0.0", [[]], ["1.0.0", "1.1.0", "1.0.1"], ["0.9.9", "0.10.0", "0.1.0", "1.0.0-pre", "1.0.1-pre"]],

# test_exact
["=1.0.0", [["=", "1.0.0"]], ["1.0.0"], ["1.0.1", "0.9.9", "0.10.0", "0.1.0", "1.0.0-pre"]],
["=0.9.0", [["=", "0.9.0"]], ["0.9.0"], ["0.9.1", "1.9.0", "0.0.9", "0.9.0-pre"]],
["=0.0.2", [["=", "0.0.2"]], ["0.0.2"], ["0.0.1", "0.0.3", "0.0.2-pre"]],
["=0.1.0-beta2.a", [["=", "0.1.0-beta2.a"]], ["0.1.0-beta2.a"], ["0.9.1", "0.1.0", "0.1.1-beta2.a", "0.1.0-beta2"]],
[
"=0.1.0-beta2.a",
[["=", "0.1.0-beta2.a"]],
["0.1.0-beta2.a"],
["0.9.1", "0.1.0", "0.1.1-beta2.a", "0.1.0-beta2"],
],
# https://github.com/dtolnay/semver/blob/master/tests/test_version_req.rs#L73
# ["=0.1.0+meta", [["=", "0.1.0+meta"]], ["0.1.0", "0.1.0+meta", "0.1.0+any"], []],

# test_greater_than
# [">= 1.0.0", [[]], ["1.0.0", "2.0.0"], ["0.1.0", "0.0.1", "1.0.0-pre", "2.0.0-pre"]],
# [">= 2.1.0-alpha2", [[]], ["2.1.0-alpha2", "2.1.0-alpha3", "2.1.0", "3.0.0"], ["2.0.0", "2.1.0-alpha1", "2.0.0-alpha2", "3.0.0-alpha2"]],

# test_less_than
# ["<1.0.0", [[]], ["0.1.0", "0.0.1"], ["1.0.0", "1.0.0-beta", "1.0.1", "0.9.9-alpha"]],
# ["<= 2.1.0-alpha2", [[]], ["2.1.0-alpha2", "2.1.0-alpha1", "2.0.0", "1.0.0"], ["2.1.0", "2.2.0-alpha1", "2.0.0-alpha2", "1.0.0-alpha2"]],
# [">1.0.0-alpha, <1.0.0", [[">", "2.1.0-alpha2"], ["<", "1.0.0"]], ["1.0.0-beta"], []],
# [">1.0.0-alpha, <1.0", [[">", "1.0.0-alpha"], ["<", "1.0"]]], ["1.0.0-beta"], []],
[">1.0.0-alpha, <1", [[">", "1.0.0-alpha"], ["<", "1"]], ["1.0.0-beta"], []],

# test_multiple
["> 0.0.9, <= 2.5.3", [[]], ["0.0.10", "1.0.0", "2.5.3"], ["0.0.8", "2.5.4"]],
# ["^0.3.0, ^0.4.0", [[]], [], ["0.0.8", "0.3.0", "0.4.0"]],
# ["<=0.2.0, >=0.5.0", [[]], [], ["0.0.8", "0.3.0", "0.5.1"]],
# ["^0.1.0, ^0.1.4, ^0.1.6", [[]], ["0.1.6", "0.1.9"], ["0.1.0", "0.1.4", "0.2.0"]],
# [">=0.5.1-alpha3, <0.6", [[[">", "0.5.1-alpha3"], ["=", "0.5.1-alpha3"], ["<", "0.6"]]], ["0.5.1-alpha3", "0.5.1-alpha4", "0.5.1-beta", "0.5.1", "0.5.5"], ["0.5.1-alpha1", "0.5.2-alpha3", "0.5.5-pre", "0.5.0-pre"]],

# test_tilde
["~1", [[]], ["1.0.0", "1.0.1", "1.1.1"], ["0.9.1", "2.9.0", "0.0.9"]],
["~1.2", [[]], ["1.2.0", "1.2.1"], ["1.1.1", "1.3.0", "0.0.9"]],
["~1.2.2", [[]], ["1.2.2", "1.2.4"], ["1.2.1", "1.9.0", "1.0.9", "2.0.1", "0.1.3"]],
# ["~1.2.3-beta.2", [[]], ["1.2.3", "1.2.4", "1.2.3-beta.2", "1.2.3-beta.4"],
# ["1.3.3", "1.1.4", "1.2.3-beta.1", "1.2.4-beta.2"]],

# test_caret
# ["^1", [[]], ["1.1.2", "1.1.0", "1.2.1", "1.0.1"],
# ["0.9.1", "2.9.0", "0.1.4", "1.0.0-beta1", "0.1.0-alpha", "1.0.1-pre"]],

["^1.1", [[]], ["1.1.2", "1.1.0", "1.2.1"],
["0.9.1", "2.9.0", "1.0.1", "0.1.4"]],

["^1.1", [[]], ["1.1.2", "1.1.0", "1.2.1"], ["0.9.1", "2.9.0", "1.0.1", "0.1.4"]],
# ["^1.1.2", [[]], ["1.1.2", "1.1.4", "1.2.1"],
# ["0.9.1", "2.9.0", "1.1.1", "0.0.1", "1.1.2-alpha1", "1.1.3-alpha1", "2.9.0-alpha1"]],

# ["^0.1.2", [[]], ["0.1.2", "0.1.4"],
# ["0.9.1", "2.9.0", "1.1.1", "0.0.1", "0.1.2-beta", "0.1.3-alpha", "0.2.0-pre"]],

# ["^0.5.1-alpha3", [[]], ["0.5.1-alpha3", "0.5.1-alpha4", "0.5.1-beta", "0.5.1", "0.5.5", ],
# ["0.5.1-alpha1", "0.5.2-alpha3", "0.5.5-pre", "0.5.0-pre", "0.6.0"]],

["^0.0.2", [[]], ["0.0.2"],
["0.9.1", "2.9.0", "1.1.1", "0.0.1", "0.1.4"]],

["^0.0.2", [[]], ["0.0.2"], ["0.9.1", "2.9.0", "1.1.1", "0.0.1", "0.1.4"]],
# ["^0.0", [[]], ["0.0.2", "0.0.0"],
# ["0.9.1", "2.9.0", "1.1.1", "0.0.1", "0.1.4"]],

["^0", [[]], ["0.9.1", "0.0.2", "0.0.0"],
["2.9.0", "1.1.1"]],

["^0", [[]], ["0.9.1", "0.0.2", "0.0.0"], ["2.9.0", "1.1.1"]],
# ["^1.4.2-beta.5", [[]], ["1.4.2", "1.4.3", "1.4.2-beta.5", "1.4.2-beta.6", "1.4.2-c"],
# ["0.9.9", "2.0.0", "1.4.2-alpha", "1.4.2-beta.4", "1.4.3-beta.5"]],

# test_wildcard
# https://github.com/dtolnay/semver/blob/master/tests/test_version_req.rs#L272
# ["*", [[]], ["0.9.1", "2.9.0", "0.0.9", "1.0.1", "1.1.1"],
# ["1.0.0-pre"]],

# ["1.*", [[]], ["1.2.0", "1.2.1", "1.1.1", "1.3.0"],
# ["0.0.9", "1.2.0-pre"]],

# ["1.2.*", [[]], ["1.2.0", "1.2.2", "1.2.4"],
# ["1.9.0", "1.0.9", "2.0.1", "0.1.3", "1.2.2-pre"]],

# test_pre
# ["=2.1.1-really.0", [[]], ["2.1.1-really.0"], []]

# test_cargo3202
["0.*.*", [[]], ["0.5.0"], []]

["0.*.*", [[]], ["0.5.0"], []],
]


Expand Down

0 comments on commit bb7a7fd

Please sign in to comment.