test_spec.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 # -*- coding: utf-8 -*-
00003 # Copyright (c) 2012-2013 Raphaël Barrois
00004 # This code is distributed under the two-clause BSD License.
00005 
00006 """Test conformance to the specs."""
00007 
00008 from .compat import unittest, is_python2
00009 
00010 import rocon_semantic_version as semantic_version
00011 
00012 # shortcut
00013 Version = semantic_version.Version
00014 
00015 
00016 class FormatTests(unittest.TestCase):
00017     """Tests proper version validation."""
00018 
00019     def test_major_minor_patch(self):
00020         ### SPEC:
00021         # A normal version number MUST take the form X.Y.Z
00022 
00023         with self.assertRaises(ValueError):
00024             Version('1')
00025         with self.assertRaises(ValueError):
00026             Version('1.1')
00027         # Doesn't raise
00028         Version('1.2.3')
00029         with self.assertRaises(ValueError):
00030             Version('1.2.3.4')
00031 
00032         ### SPEC:
00033         # Where X, Y, and Z are non-negative integers,
00034 
00035         with self.assertRaises(ValueError):
00036             Version('1.2.A')
00037         with self.assertRaises(ValueError):
00038             Version('1.-2.3')
00039         # Valid
00040         v = Version('1.2.3')
00041         self.assertEqual(1, v.major)
00042         self.assertEqual(2, v.minor)
00043         self.assertEqual(3, v.patch)
00044 
00045 
00046         ### Spec:
00047         # And MUST NOT contain leading zeroes
00048         with self.assertRaises(ValueError):
00049             Version('1.2.01')
00050         with self.assertRaises(ValueError):
00051             Version('1.02.1')
00052         with self.assertRaises(ValueError):
00053             Version('01.2.1')
00054         # Valid
00055         v = Version('0.0.0')
00056         self.assertEqual(0, v.major)
00057         self.assertEqual(0, v.minor)
00058         self.assertEqual(0, v.patch)
00059 
00060     def test_prerelease(self):
00061         ### SPEC:
00062         # A pre-release version MAY be denoted by appending a hyphen and a
00063         # series of dot separated identifiers immediately following the patch
00064         # version.
00065 
00066         with self.assertRaises(ValueError):
00067             Version('1.2.3 -23')
00068         # Valid
00069         v = Version('1.2.3-23')
00070         self.assertEqual(('23',), v.prerelease)
00071 
00072         ### SPEC:
00073         # Identifiers MUST comprise only ASCII alphanumerics and hyphen.
00074         # Identifiers MUST NOT be empty
00075         with self.assertRaises(ValueError):
00076             Version('1.2.3-a,')
00077         with self.assertRaises(ValueError):
00078             Version('1.2.3-..')
00079 
00080         ### SPEC:
00081         # Numeric identifiers MUST NOT include leading zeroes.
00082 
00083         with self.assertRaises(ValueError):
00084             Version('1.2.3-a0.01')
00085         with self.assertRaises(ValueError):
00086             Version('1.2.3-00')
00087         # Valid
00088         v = Version('1.2.3-0a.0.000zz')
00089         self.assertEqual(('0a', '0', '000zz'), v.prerelease)
00090 
00091     def test_build(self):
00092         ### SPEC:
00093         # Build metadata MAY be denoted by appending a plus sign and a series of
00094         # dot separated identifiers immediately following the patch or
00095         # pre-release version
00096 
00097         v = Version('1.2.3')
00098         self.assertEqual((), v.build)
00099         with self.assertRaises(ValueError):
00100             Version('1.2.3 +4')
00101 
00102         ### SPEC:
00103         # Identifiers MUST comprise only ASCII alphanumerics and hyphen.
00104         # Identifiers MUST NOT be empty
00105         with self.assertRaises(ValueError):
00106             Version('1.2.3+a,')
00107         with self.assertRaises(ValueError):
00108             Version('1.2.3+..')
00109 
00110         # Leading zeroes allowed
00111         v = Version('1.2.3+0.0a.01')
00112         self.assertEqual(('0', '0a', '01'), v.build)
00113 
00114     def test_precedence(self):
00115         ### SPEC:
00116         # Precedence is determined by the first difference when comparing from
00117         # left to right as follows: Major, minor, and patch versions are always
00118         # compared numerically.
00119         # Example: 1.0.0 < 2.0.0 < 2.1.0 < 2.1.1
00120         self.assertLess(Version('1.0.0'), Version('2.0.0'))
00121         self.assertLess(Version('2.0.0'), Version('2.1.0'))
00122         self.assertLess(Version('2.1.0'), Version('2.1.1'))
00123 
00124         ### SPEC:
00125         # When major, minor, and patch are equal, a pre-release version has
00126         # lower precedence than a normal version.
00127         # Example: 1.0.0-alpha < 1.0.0
00128         self.assertLess(Version('1.0.0-alpha'), Version('1.0.0'))
00129 
00130         ### SPEC:
00131         # Precedence for two pre-release versions with the same major, minor,
00132         # and patch version MUST be determined by comparing each dot separated
00133         # identifier from left to right until a difference is found as follows:
00134         # identifiers consisting of only digits are compared numerically
00135         self.assertLess(Version('1.0.0-1'), Version('1.0.0-2'))
00136 
00137         # and identifiers with letters or hyphens are compared lexically in
00138         # ASCII sort order.
00139         self.assertLess(Version('1.0.0-aa'), Version('1.0.0-ab'))
00140 
00141         # Numeric identifiers always have lower precedence than
00142         # non-numeric identifiers.
00143         self.assertLess(Version('1.0.0-9'), Version('1.0.0-a'))
00144 
00145         # A larger set of pre-release fields has a higher precedence than a
00146         # smaller set, if all of the preceding identifiers are equal.
00147         self.assertLess(Version('1.0.0-a.b.c'), Version('1.0.0-a.b.c.0'))
00148 
00149         # Example: 1.0.0-alpha < 1.0.0-alpha.1 < 1.0.0-alpha.beta < 1.0.0-beta < 1.0.0-beta.2 < 1.0.0-beta.11 < 1.0.0-rc.1 < 1.0.0.
00150         self.assertLess(Version('1.0.0-alpha'), Version('1.0.0-alpha.1'))
00151         self.assertLess(Version('1.0.0-alpha.1'), Version('1.0.0-alpha.beta'))
00152         self.assertLess(Version('1.0.0-alpha.beta'), Version('1.0.0-beta'))
00153         self.assertLess(Version('1.0.0-beta'), Version('1.0.0-beta.2'))
00154         self.assertLess(Version('1.0.0-beta.2'), Version('1.0.0-beta.11'))
00155         self.assertLess(Version('1.0.0-beta.11'), Version('1.0.0-rc.1'))
00156         self.assertLess(Version('1.0.0-rc.1'), Version('1.0.0'))
00157 
00158 
00159 
00160 class PrecedenceTestCase(unittest.TestCase):
00161     pass
00162 
00163 


rocon_semantic_version
Author(s): Raphaël Barrois
autogenerated on Fri May 2 2014 10:35:51