diff options
Diffstat (limited to 'tests')
-rwxr-xr-x | tests/test_base.py | 44 | ||||
-rw-r--r-- | tests/test_django.py | 39 | ||||
-rwxr-xr-x | tests/test_match.py | 32 | ||||
-rwxr-xr-x | tests/test_parsing.py | 35 | ||||
-rw-r--r-- | tests/test_spec.py | 7 |
5 files changed, 118 insertions, 39 deletions
diff --git a/tests/test_base.py b/tests/test_base.py index 00c1216..6707cef 100755 --- a/tests/test_base.py +++ b/tests/test_base.py @@ -64,7 +64,7 @@ class TopLevelTestCase(unittest.TestCase): ('0.1.1', '0.1.1', 0), ('0.1.1', '0.1.0', 1), ('0.1.0-alpha', '0.1.0', -1), - ('0.1.0-alpha+2', '0.1.0-alpha', 1), + ('0.1.0-alpha+2', '0.1.0-alpha', NotImplemented), ) def test_compare(self): @@ -179,7 +179,6 @@ class VersionTestCase(unittest.TestCase): '1.1.2': (1, 1, 2, None, None), '1.1.3-rc4.5': (1, 1, 3, ('rc4', '5'), None), '1.0.0-': (1, 0, 0, (), None), - '1.0.0+': (1, 0, 0, (), ()), '1.0.0-rc.1+build.1': (1, 0, 0, ('rc', '1'), ('build', '1')), '1.0.0+0.3.7': (1, 0, 0, (), ('0', '3', '7')), '1.3.7+build': (1, 3, 7, (), ('build',)), @@ -396,18 +395,29 @@ class VersionTestCase(unittest.TestCase): class SpecItemTestCase(unittest.TestCase): + invalids = [ + '<=0.1.1+build3', + '<=0.1.1+', + '>0.2.3-rc2+', + ] + + def test_invalids(self): + for invalid in self.invalids: + with self.assertRaises(ValueError, msg="SpecItem(%r) should be invalid" % invalid): + _v = base.SpecItem(invalid) + components = { '==0.1.0': (base.SpecItem.KIND_EQUAL, 0, 1, 0, None, None), '==0.1.2-rc3': (base.SpecItem.KIND_EQUAL, 0, 1, 2, ('rc3',), None), '==0.1.2+build3.14': (base.SpecItem.KIND_EQUAL, 0, 1, 2, (), ('build3', '14')), - '<=0.1.1+': (base.SpecItem.KIND_LTE, 0, 1, 1, (), ()), + '<=0.1.1': (base.SpecItem.KIND_LTE, 0, 1, 1, None, None), '<0.1.1': (base.SpecItem.KIND_LT, 0, 1, 1, None, None), '<=0.1.1': (base.SpecItem.KIND_LTE, 0, 1, 1, None, None), + '!=0.1.1+': (base.SpecItem.KIND_NEQ, 0, 1, 1, (), ()), '<=0.1.1-': (base.SpecItem.KIND_LTE, 0, 1, 1, (), None), '>=0.2.3-rc2': (base.SpecItem.KIND_GTE, 0, 2, 3, ('rc2',), None), - '>0.2.3-rc2+': (base.SpecItem.KIND_GT, 0, 2, 3, ('rc2',), ()), '>=2.0.0': (base.SpecItem.KIND_GTE, 2, 0, 0, None, None), - '!=0.1.1+': (base.SpecItem.KIND_NEQ, 0, 1, 1, (), ()), + '!=0.1.1+rc3': (base.SpecItem.KIND_NEQ, 0, 1, 1, (), ('rc3',)), '!=0.3.0': (base.SpecItem.KIND_NEQ, 0, 3, 0, None, None), } @@ -459,13 +469,17 @@ class SpecItemTestCase(unittest.TestCase): ['0.2.3-rc3', '0.2.3', '0.2.3+1', '0.2.3-rc2', '0.2.3-rc2+1'], ['0.2.3-rc1', '0.2.2'], ), - '>0.2.3-rc2+': ( - ['0.2.3-rc3', '0.2.3', '0.2.3-rc2+1'], - ['0.2.3-rc1', '0.2.2', '0.2.3-rc2'], + '==0.2.3+': ( + ['0.2.3'], + ['0.2.3+rc1', '0.2.4', '0.2.3-rc2'], + ), + '!=0.2.3-rc2+12': ( + ['0.2.3-rc3', '0.2.3', '0.2.3-rc2+1', '0.2.4', '0.2.3-rc3+12'], + ['0.2.3-rc2+12'], ), - '>2.0.0+': ( - ['2.1.1', '2.0.0+b1', '3.1.4'], - ['1.9.9', '1.9.9999', '2.0.0', '2.0.0-rc4'], + '==2.0.0+b1': ( + ['2.0.0+b1'], + ['2.1.1', '1.9.9', '1.9.9999', '2.0.0', '2.0.0-rc4'], ), '!=0.1.1': ( ['0.1.2', '0.1.0', '1.4.2'], @@ -564,13 +578,17 @@ class SpecTestCase(unittest.TestCase): self.assertTrue(repr(base.SpecItem(spec_text)) in repr(spec_list)) matches = { + # At least 0.1.1 including pre-releases, less than 0.1.2 excluding pre-releases '>=0.1.1,<0.1.2': ( ['0.1.1', '0.1.1+4', '0.1.1-alpha'], ['0.1.2-alpha', '0.1.2', '1.3.4'], ), - '>=0.1.0+,!=0.1.3-rc1,<0.1.4': ( + # At least 0.1.0 without pre-releases, less than 0.1.4 excluding pre-releases, + # neither 0.1.3-rc1 nor any build of that version, + # not 0.1.0+b3 precisely + '>=0.1.0-,!=0.1.3-rc1,!=0.1.0+b3,<0.1.4': ( ['0.1.1', '0.1.0+b4', '0.1.2', '0.1.3-rc2'], - ['0.0.1', '0.1.4', '0.1.4-alpha', '0.1.3-rc1+4', + ['0.0.1', '0.1.0+b3', '0.1.4', '0.1.4-alpha', '0.1.3-rc1+4', '0.1.0-alpha', '0.2.2', '0.1.4-rc1'], ), } diff --git a/tests/test_django.py b/tests/test_django.py index 94e2420..959b19c 100644 --- a/tests/test_django.py +++ b/tests/test_django.py @@ -30,6 +30,13 @@ if django_loaded and django.VERSION < (1, 7): # pragma: no cover except ImportError: pass +# the refresh_from_db method only came in with 1.8, so in order to make this +# work will all supported versions we have our own function. +def save_and_refresh(obj): + """Saves an object, and refreshes from the database.""" + obj.save() + obj = obj.__class__.objects.get(id=obj.id) + @unittest.skipIf(not django_loaded, "Django not installed") class DjangoFieldTestCase(unittest.TestCase): @@ -48,6 +55,38 @@ class DjangoFieldTestCase(unittest.TestCase): obj.full_clean() + def test_version_save(self): + """Test saving object with a VersionField.""" + # first test with a null value + obj = models.PartialVersionModel() + self.assertIsNone(obj.id) + self.assertIsNone(obj.optional) + save_and_refresh(obj) + self.assertIsNotNone(obj.id) + self.assertIsNone(obj.optional_spec) + + # now set to something that is not null + spec = semantic_version.Spec('==0,!=0.2') + obj.optional_spec = spec + save_and_refresh(obj) + self.assertEqual(obj.optional_spec, spec) + + def test_spec_save(self): + """Test saving object with a SpecField.""" + # first test with a null value + obj = models.PartialVersionModel() + self.assertIsNone(obj.id) + self.assertIsNone(obj.optional_spec) + save_and_refresh(obj) + self.assertIsNotNone(obj.id) + self.assertIsNone(obj.optional_spec) + + # now set to something that is not null + spec = semantic_version.Spec('==0,!=0.2') + obj.optional_spec = spec + save_and_refresh(obj) + self.assertEqual(obj.optional_spec, spec) + def test_partial_spec(self): obj = models.VersionModel(version='0.1.1', spec='==0,!=0.2') self.assertEqual(semantic_version.Version('0.1.1'), obj.version) diff --git a/tests/test_match.py b/tests/test_match.py index 155a612..6926e0a 100755 --- a/tests/test_match.py +++ b/tests/test_match.py @@ -15,6 +15,7 @@ class MatchTestCase(unittest.TestCase): '<=0.1.4a', '>0.1.1.1', '~0.1.2-rc23,1', + '<0.1.2-rc1.3-14.15+build.2012-01-01.11h34', ] valid_specs = [ @@ -25,7 +26,7 @@ class MatchTestCase(unittest.TestCase): '>0.1.2-rc1', '>=0.1.2-rc1.3.4', '==0.1.2+build42-12.2012-01-01.12h23', - '<0.1.2-rc1.3-14.15+build.2012-01-01.11h34', + '!=0.1.2-rc1.3-14.15+build.2012-01-01.11h34', ] matches = { @@ -53,11 +54,19 @@ class MatchTestCase(unittest.TestCase): '0.1.2', '0.1.2+build4', ], - '<0.1.2+': [ + '!=0.1.2+': [ + '0.1.2+1', + '0.1.2-rc1', + ], + '!=0.1.2-': [ '0.1.1', '0.1.2-rc1', - '0.1.2-rc1.3.4', - '0.1.2-rc1+build4.5', + ], + '!=0.1.2+345': [ + '0.1.1', + '0.1.2-rc1+345', + '0.1.2+346', + '0.2.3+345', ], '>=0.1.1': [ '0.1.1', @@ -72,12 +81,6 @@ class MatchTestCase(unittest.TestCase): '0.2.0', '1.0.0', ], - '>0.1.1+': [ - '0.1.1+b2', - '0.1.2-rc1', - '1.1.1', - '2.0.4', - ], '<0.1.1-': [ '0.1.1-alpha', '0.1.1-rc4', @@ -87,7 +90,8 @@ class MatchTestCase(unittest.TestCase): def test_invalid(self): for invalid in self.invalid_specs: - self.assertRaises(ValueError, semantic_version.Spec, invalid) + with self.assertRaises(ValueError, msg="Spec(%r) should be invalid" % invalid): + semantic_version.Spec(invalid) def test_simple(self): for valid in self.valid_specs: @@ -122,11 +126,9 @@ class MatchTestCase(unittest.TestCase): self.assertFalse(version in strict_spec, "%r should not be in %r" % (version, strict_spec)) def test_build_check(self): - strict_spec = semantic_version.Spec('<=0.1.1-rc1+') - lax_spec = semantic_version.Spec('<=0.1.1-rc1') + spec = semantic_version.Spec('<=0.1.1-rc1') version = semantic_version.Version('0.1.1-rc1+4.2') - self.assertTrue(version in lax_spec, "%r should be in %r" % (version, lax_spec)) - self.assertFalse(version in strict_spec, "%r should not be in %r" % (version, strict_spec)) + self.assertTrue(version in spec, "%r should be in %r" % (version, spec)) if __name__ == '__main__': # pragma: no cover 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() diff --git a/tests/test_spec.py b/tests/test_spec.py index 7a645f9..a13cb0b 100644 --- a/tests/test_spec.py +++ b/tests/test_spec.py @@ -154,10 +154,3 @@ class FormatTests(unittest.TestCase): self.assertLess(Version('1.0.0-beta.2'), Version('1.0.0-beta.11')) self.assertLess(Version('1.0.0-beta.11'), Version('1.0.0-rc.1')) self.assertLess(Version('1.0.0-rc.1'), Version('1.0.0')) - - - -class PrecedenceTestCase(unittest.TestCase): - pass - - |