Skip to content

Commit 642ba6d

Browse files
committed
Add failing test for marker eval on versions
This commit adds test cases to cover version-to-version and non-version-to-version marker evaluation, according to PEP 508, Environment Markers. https://peps.python.org/pep-0508/#environment-markers Marker evaluation currently throws an InvalidVersion error when the rhs is a valid version but the lhs is not. For example, consider the dependency: > Requires-Dist: typing-extensions (>=4,<5) ; extra == "v8" The extra name "v8" is both a valid version and extra name. During evaluation of this requirement, the LHS of the marker can take on the value "", or some other extra name, which are not valid versions. When this situation occurs, the comparison fails by throwing InvalidVersion, rather then returning False. This is causing pip to crash when attempting to install a package with such a requirement. Currently, just one of these added cases is failing - the "quux" == "v8" case. I've also added two cases to document the (perhaps surprising) behaviour that is a result of the PEP 508 spec requiring normalized version comparison to apply to extras when both sides are valid versions.
1 parent 71f38d8 commit 642ba6d

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

tests/test_markers.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,14 @@ def test_environment_with_extra_none(self):
314314
{"extra": "different__punctuation_is_EQUAL"},
315315
True,
316316
),
317+
# extra name that is also a valid version - version comparison applies
318+
# if both sides are valid versions
319+
("extra == 'v8'", {"extra": "quux"}, False),
320+
("extra == 'v8'", {"extra": "v8"}, True),
321+
# LHS and RHS are valid versions, so equality uses normalized version
322+
("extra == 'v8-dev'", {"extra": "v8-dev.0"}, True),
323+
# Only one side is a valid version, so values are not normalized as versions
324+
("extra == 'v-8-dev'", {"extra": "v-8-dev.0"}, False),
317325
],
318326
)
319327
def test_evaluates(self, marker_string, environment, expected):

0 commit comments

Comments
 (0)