diff options
author | Raphaël Barrois <raphael.barrois@polytechnique.org> | 2015-09-15 23:18:13 +0200 |
---|---|---|
committer | Raphaël Barrois <raphael.barrois@polytechnique.org> | 2015-09-15 23:40:59 +0200 |
commit | 2ed3d39c291080c61edd9139370939e1fdc3209a (patch) | |
tree | 22a90dfae0e0fc9fd7949ca18e7e47daa8f8aabb /tests/test_parsing.py | |
parent | 4aac5768db2fc158fa87900b54210ecba4dfe6d5 (diff) | |
download | semantic-version-2ed3d39c291080c61edd9139370939e1fdc3209a.tar.gz |
Forbid build metadata ordering (See #18)
SemVer 2.0.0 states that "Build metadata SHOULD be ignored when
determining version precedence".
This means that, when comparing ``0.1.0+1`` to ``0.1.0+bcd``::
>>> Version('0.1.0+1') == Version('0.1.0+bcd')
False
>>> Version('0.1.0+1') != Version('0.1.0+bcd')
True
>>> Version('0.1.0+1') < Version('0.1.0+bcd')
False
>>> Version('0.1.0+1') > Version('0.1.0+bcd')
False
>>> Version('0.1.0+1') <= Version('0.1.0+bcd')
False
>>> Version('0.1.0+1') >= Version('0.1.0+bcd')
False
>>> compare(Version('0.1.0+1'), Version('0.1.0+bcd'))
NotImplemented
This change also has the following effects:
- When including build metadata in a ``Spec``, the only valid options
are ``Spec('==0.1.0+sth')`` and ``Spec('!=0.1.0+sth')``
- The meaning of ``Spec('==0.1.0+')`` is now "Only version 0.1.0 without
build metadata"
- ``Spec('==0.1.0')`` now matches ``Version('0.1.0+anything')``
Diffstat (limited to 'tests/test_parsing.py')
-rwxr-xr-x | tests/test_parsing.py | 35 |
1 files changed, 31 insertions, 4 deletions
diff --git a/tests/test_parsing.py b/tests/test_parsing.py index 5112ca5..c7651d2 100755 --- a/tests/test_parsing.py +++ b/tests/test_parsing.py @@ -3,6 +3,7 @@ # Copyright (c) 2012-2014 The python-semanticversion project # This code is distributed under the two-clause BSD License. +import itertools import unittest import semantic_version @@ -44,12 +45,8 @@ class ComparisonTestCase(unittest.TestCase): '1.0.0-beta.2', '1.0.0-beta.11', '1.0.0-rc.1', - '1.0.0-rc.1+build.1', '1.0.0', - '1.0.0+0.3.7', '1.3.7+build', - '1.3.7+build.2.b8f12d7', - '1.3.7+build.11.e0f985a', ] def test_comparisons(self): @@ -67,6 +64,36 @@ class ComparisonTestCase(unittest.TestCase): cmp_res = -1 if i < j else (1 if i > j else 0) self.assertEqual(cmp_res, semantic_version.compare(first, second)) + unordered = [ + [ + '1.0.0-rc.1', + '1.0.0-rc.1+build.1', + ], + [ + '1.0.0', + '1.0.0+0.3.7', + ], + [ + '1.3.7', + '1.3.7+build', + '1.3.7+build.2.b8f12d7', + '1.3.7+build.11.e0f985a', + ], + ] + + def test_unordered(self): + for group in self.unordered: + for a, b in itertools.combinations(group, 2): + v1 = semantic_version.Version(a) + v2 = semantic_version.Version(b) + self.assertTrue(v1 == v1, "%r != %r" % (v1, v1)) + self.assertFalse(v1 != v1, "%r != %r" % (v1, v1)) + 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.assertFalse(v2 > v1, "%r !> %r" % (v2, v1)) + self.assertFalse(v2 >= v1, "%r !>= %r" % (v2, v1)) if __name__ == '__main__': # pragma: no cover unittest.main() |