From c415ee4cd87915191b1ca8df2d3fbf7e49d4bbbf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Barrois?= Date: Sat, 24 Aug 2019 14:04:55 +0200 Subject: Add `Version.precedence_key`. This will be used in `sort(..., key=lambda v: v.precedence_key)`. Remove previous comparison/ordering implementation. The current implementation relies on a 4-tuple: - major, minor, patch (as integers) - natural order matches precedence rules - a tuple of identifiers for the prerelease component. The identifiers for the prerelease components are based on: - A `NumericIdentifier` class, that compares number using their natural order, and always compares lower than non-numeric identifiers - A `AlphaIdentifier` class for non-numeric identifiers; it compares versions using ASCII ordering. - A `MaxIdentifier` class, that compares higher to any other identifier; used to ensure that a non-prerelease version is greater than any of its prereleases. --- tests/test_base.py | 51 --------------------------------------------------- tests/test_parsing.py | 4 ++-- 2 files changed, 2 insertions(+), 53 deletions(-) (limited to 'tests') diff --git a/tests/test_base.py b/tests/test_base.py index d5794b3..5a6497b 100755 --- a/tests/test_base.py +++ b/tests/test_base.py @@ -10,57 +10,6 @@ import unittest from semantic_version import base -class ComparisonTestCase(unittest.TestCase): - def test_identifier_cmp(self): - cases = [ - # Integers - ('1', '1', 0), - ('1', '2', -1), - ('11', '2', 1), - ('3333', '40', 1), - - # Text - ('aa', 'ab', -1), - ('aa', 'aa', 0), - ('ab', 'aa', 1), - ('aaa', 'ab', -1), - - # Mixed - ('10', '1a', -1), - ('1a', '10', 1), - ('ab1', '42', 1), - ] - - for a, b, expected in cases: - with self.subTest(a=a, b=b): - result = base.identifier_cmp(a, b) - self.assertEqual( - expected, result, - "identifier_cmp(%r, %r) returned %d instead of %d" % ( - a, b, result, expected)) - - def test_identifier_list_cmp(self): - cases = [ - # Same length - (['1', '2', '3'], ['1', '2', '3'], 0), - (['1', '2', '3'], ['1', '3', '2'], -1), - (['1', '2', '4'], ['1', '2', '3'], 1), - - # Mixed lengths - (['1', 'a'], ['1', 'a', '0'], -1), - (['1', 'a', '0'], ['1', 'a'], 1), - (['1', 'b'], ['1', 'a', '1000'], 1), - ] - - for a, b, expected in cases: - with self.subTest(a=a, b=b): - result = base.identifier_list_cmp(a, b) - self.assertEqual( - expected, result, - "identifier_list_cmp(%r, %r) returned %d instead of %d" % ( - a, b, result, expected)) - - class TopLevelTestCase(unittest.TestCase): """Test module-level functions.""" diff --git a/tests/test_parsing.py b/tests/test_parsing.py index 2d612a1..0da679f 100755 --- a/tests/test_parsing.py +++ b/tests/test_parsing.py @@ -120,9 +120,9 @@ class ComparisonTestCase(unittest.TestCase): self.assertFalse(v1 == v2, "%r == %r" % (v1, v2)) self.assertTrue(v1 != v2, "%r !!= %r" % (v1, v2)) self.assertFalse(v1 < v2, "%r !< %r" % (v1, v2)) - self.assertFalse(v1 <= v2, "%r !<= %r" % (v1, v2)) + self.assertTrue(v1 <= v2, "%r !<= %r" % (v1, v2)) self.assertFalse(v2 > v1, "%r !> %r" % (v2, v1)) - self.assertFalse(v2 >= v1, "%r !>= %r" % (v2, v1)) + self.assertTrue(v2 >= v1, "%r !>= %r" % (v2, v1)) if __name__ == '__main__': # pragma: no cover -- cgit v1.2.1