Skip to content

Commit f357a32

Browse files
committed
add tests from the page
1 parent fe0ca65 commit f357a32

File tree

2 files changed

+37
-23
lines changed

2 files changed

+37
-23
lines changed

python/private/py_wheel_normalize_pep440.bzl

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -569,8 +569,8 @@ def _version_lt(left, right):
569569
return True
570570

571571
# the release is equal, check for pre version
572-
if right.pre:
573-
if left.pre != None:
572+
if right.pre != None:
573+
if left.pre == None:
574574
# PEP440: The exclusive ordered comparison <V MUST NOT allow a pre-release of
575575
# the specified version unless the specified version is itself a pre-release.
576576
return False
@@ -579,7 +579,20 @@ def _version_lt(left, right):
579579
return False
580580
elif left.pre < right.pre:
581581
return True
582-
elif left.pre:
582+
elif left.pre != None:
583+
return True
584+
585+
if right.dev != None:
586+
if left.dev == None:
587+
# PEP440: The exclusive ordered comparison <V MUST NOT allow a pre-release of
588+
# the specified version unless the specified version is itself a pre-release.
589+
return False
590+
591+
if left.dev > right.dev:
592+
return False
593+
elif left.dev < right.dev:
594+
return True
595+
elif left.dev != None:
583596
return True
584597

585598
return False

tests/pypi/pep508/evaluate_tests.bzl

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -302,26 +302,27 @@ _tests.append(_misc_expressions)
302302

303303
def _test_ordering(env):
304304
want = [
305-
# The items are sorted from lowest to highest version
306-
"0.0.1",
307-
"0.1.0-rc",
308-
"0.1.0",
309-
"0.9.11",
310-
"0.9.12.dev",
311-
"0.9.12",
312-
"1.0.0-alpha",
313-
"1.0.0-alpha1",
314-
"1.0.0-beta",
315-
"1.0.0-beta.dev",
316-
"1.0.0-beta2",
317-
"1.0.0-beta11",
318-
"1.0.0-rc1",
319-
"1.0.0-rc2.dev",
320-
"1.0.0-rc2",
321-
"1.0.0",
322-
# Also handle missing minor and patch version strings
323-
"2.0",
324-
"3",
305+
# Taken from https://peps.python.org/pep-0440/#summary-of-permitted-suffixes-and-relative-ordering
306+
"1.dev0",
307+
"1.0.dev456",
308+
"1.0a1",
309+
"1.0a2.dev456",
310+
"1.0a12.dev456",
311+
"1.0a12",
312+
"1.0b1.dev456",
313+
"1.0b2",
314+
"1.0b2.post345.dev456",
315+
"1.0b2.post345",
316+
"1.0rc1.dev456",
317+
"1.0rc1",
318+
"1.0",
319+
"1.0+abc.5",
320+
"1.0+abc.7",
321+
"1.0+5",
322+
"1.0.post456.dev34",
323+
"1.0.post456",
324+
"1.0.15",
325+
"1.1.dev1",
325326
]
326327

327328
for lower, higher in zip(want[:-1], want[1:]):

0 commit comments

Comments
 (0)