test_parsing.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 import unittest
00007 
00008 import semantic_version
00009 
00010 
00011 class ParsingTestCase(unittest.TestCase):
00012     invalids = [
00013         None,
00014         '',
00015         '0',
00016         '0.1',
00017         '0.1.4a',
00018         '0.1.1.1',
00019         '0.1.2-rc23,1',
00020     ]
00021 
00022     valids = [
00023         '0.1.1',
00024         '0.1.2-rc1',
00025         '0.1.2-rc1.3.4',
00026         '0.1.2+build42-12.2012-01-01.12h23',
00027         '0.1.2-rc1.3-14.15+build.2012-01-01.11h34',
00028     ]
00029 
00030     def test_invalid(self):
00031         for invalid in self.invalids:
00032             self.assertRaises(ValueError, semantic_version.Version, invalid)
00033 
00034     def test_simple(self):
00035         for valid in self.valids:
00036             version = semantic_version.Version(valid)
00037             self.assertEqual(valid, str(version))
00038 
00039 
00040 class ComparisonTestCase(unittest.TestCase):
00041     order = [
00042         '1.0.0-alpha',
00043         '1.0.0-alpha.1',
00044         '1.0.0-beta.2',
00045         '1.0.0-beta.11',
00046         '1.0.0-rc.1',
00047         '1.0.0-rc.1+build.1',
00048         '1.0.0',
00049         '1.0.0+0.3.7',
00050         '1.3.7+build',
00051         '1.3.7+build.2.b8f12d7',
00052         '1.3.7+build.11.e0f985a',
00053     ]
00054 
00055     def test_comparisons(self):
00056         for i, first in enumerate(self.order):
00057             first_ver = semantic_version.Version(first)
00058             for j, second in enumerate(self.order):
00059                 second_ver = semantic_version.Version(second)
00060                 if i < j:
00061                     self.assertTrue(first_ver < second_ver, '%r !< %r' % (first_ver, second_ver))
00062                 elif i == j:
00063                     self.assertTrue(first_ver == second_ver, '%r != %r' % (first_ver, second_ver))
00064                 else:
00065                     self.assertTrue(first_ver > second_ver, '%r !> %r' % (first_ver, second_ver))
00066 
00067                 cmp_res = -1 if i < j else (1 if i > j else 0)
00068                 self.assertEqual(cmp_res, semantic_version.compare(first, second))
00069 
00070 
00071 if __name__ == '__main__':  # pragma: no cover
00072     unittest.main()


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