Skip to content

Commit aff2962

Browse files
committed
Add tests to document counter-intuitive version comparison
As discussed in #774, falling back to lexicographic string comparison when using greater/less-than operators can result in counter-intuitive behaviour on version-like numeric strings.
1 parent 69a86c6 commit aff2962

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

tests/test_markers.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,15 @@ def test_environment_with_extra_none(self):
322322
("extra == 'v8-dev'", {"extra": "v8-dev.0"}, True),
323323
# LHS and RHS are not valid versions, so equality is str comparison
324324
("extra == 'v8-foo'", {"extra": "v8-foo.0"}, False),
325+
#
326+
# When using order comparisons, fallback to str when one or both are
327+
# not valid versions can have counter-intuitive results.
328+
#
329+
# The gentoo value is not a valid version, lexicographic str
330+
# comparison applies. This is True because '6' >= '2'.
331+
("platform_release >= '20'", {"platform_release": "6.7.0-gentoo"}, True),
332+
# Whereas this is False because the gentoo value IS a valid version
333+
("platform_release >= '20'", {"platform_release": "6.7.0+gentoo"}, False),
325334
],
326335
)
327336
def test_evaluates(self, marker_string, environment, expected):

0 commit comments

Comments
 (0)