Go to the documentation of this file.00001
00002
00003
00004
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
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
00021
00022
00023 with self.assertRaises(ValueError):
00024 Version('1')
00025 with self.assertRaises(ValueError):
00026 Version('1.1')
00027
00028 Version('1.2.3')
00029 with self.assertRaises(ValueError):
00030 Version('1.2.3.4')
00031
00032
00033
00034
00035 with self.assertRaises(ValueError):
00036 Version('1.2.A')
00037 with self.assertRaises(ValueError):
00038 Version('1.-2.3')
00039
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
00047
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
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
00062
00063
00064
00065
00066 with self.assertRaises(ValueError):
00067 Version('1.2.3 -23')
00068
00069 v = Version('1.2.3-23')
00070 self.assertEqual(('23',), v.prerelease)
00071
00072
00073
00074
00075 with self.assertRaises(ValueError):
00076 Version('1.2.3-a,')
00077 with self.assertRaises(ValueError):
00078 Version('1.2.3-..')
00079
00080
00081
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
00088 v = Version('1.2.3-0a.0.000zz')
00089 self.assertEqual(('0a', '0', '000zz'), v.prerelease)
00090
00091 def test_build(self):
00092
00093
00094
00095
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
00103
00104
00105 with self.assertRaises(ValueError):
00106 Version('1.2.3+a,')
00107 with self.assertRaises(ValueError):
00108 Version('1.2.3+..')
00109
00110
00111 v = Version('1.2.3+0.0a.01')
00112 self.assertEqual(('0', '0a', '01'), v.build)
00113
00114 def test_precedence(self):
00115
00116
00117
00118
00119
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
00125
00126
00127
00128 self.assertLess(Version('1.0.0-alpha'), Version('1.0.0'))
00129
00130
00131
00132
00133
00134
00135 self.assertLess(Version('1.0.0-1'), Version('1.0.0-2'))
00136
00137
00138
00139 self.assertLess(Version('1.0.0-aa'), Version('1.0.0-ab'))
00140
00141
00142
00143 self.assertLess(Version('1.0.0-9'), Version('1.0.0-a'))
00144
00145
00146
00147 self.assertLess(Version('1.0.0-a.b.c'), Version('1.0.0-a.b.c.0'))
00148
00149
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