test_match.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 MatchTestCase(unittest.TestCase):
00012     invalid_specs = [
00013         '',
00014         '!0.1',
00015         '<=0.1.4a',
00016         '>0.1.1.1',
00017         '~0.1.2-rc23,1',
00018     ]
00019 
00020     valid_specs = [
00021         '==0.1.0',
00022         '<=0.1.1',
00023         '<0.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     matches = {
00031         '==0.1.2': [
00032             '0.1.2-rc1',
00033             '0.1.2-rc1.3.4',
00034             '0.1.2+build42-12.2012-01-01.12h23',
00035             '0.1.2-rc1.3-14.15+build.2012-01-01.11h34',
00036         ],
00037         '<=0.1.2': [
00038             '0.1.1',
00039             '0.1.2-rc1',
00040             '0.1.2-rc1.3.4',
00041             '0.1.2',
00042             '0.1.2+build4',
00043         ],
00044         '<0.1.2+': [
00045             '0.1.1',
00046             '0.1.2-rc1',
00047             '0.1.2-rc1.3.4',
00048             '0.1.2-rc1+build4.5',
00049         ],
00050         '>=0.1.1': [
00051             '0.1.1',
00052             '0.1.1+build4.5',
00053             '0.1.2-rc1.3',
00054             '0.2.0',
00055             '1.0.0',
00056         ],
00057         '>0.1.1': [
00058             '0.1.2+build4.5',
00059             '0.1.2-rc1.3',
00060             '0.2.0',
00061             '1.0.0',
00062         ],
00063         '>0.1.1+': [
00064             '0.1.1+b2',
00065             '0.1.2-rc1',
00066             '1.1.1',
00067             '2.0.4',
00068         ],
00069         '<0.1.1-': [
00070             '0.1.1-alpha',
00071             '0.1.1-rc4',
00072             '0.1.0+12.3',
00073         ],
00074     }
00075 
00076     def test_invalid(self):
00077         for invalid in self.invalid_specs:
00078             self.assertRaises(ValueError, semantic_version.Spec, invalid)
00079 
00080     def test_simple(self):
00081         for valid in self.valid_specs:
00082             version = semantic_version.Spec(valid)
00083             self.assertEqual(valid, str(version))
00084 
00085     def test_match(self):
00086         for spec_txt, versions in self.matches.items():
00087             spec = semantic_version.Spec(spec_txt)
00088             self.assertNotEqual(spec, spec_txt)
00089             for version_txt in versions:
00090                 version = semantic_version.Version(version_txt)
00091                 self.assertTrue(spec.match(version), "%r does not match %r" % (version, spec))
00092                 self.assertTrue(semantic_version.match(spec_txt, version_txt))
00093                 self.assertTrue(version in spec, "%r not in %r" % (version, spec))
00094 
00095     def test_contains(self):
00096         spec = semantic_version.Spec('<=0.1.1')
00097         self.assertFalse('0.1.0' in spec, "0.1.0 should not be in %r" % spec)
00098 
00099         version = semantic_version.Version('0.1.1+4.2')
00100         self.assertTrue(version in spec, "%r should be in %r" % (version, spec))
00101 
00102         version = semantic_version.Version('0.1.1-rc1+4.2')
00103         self.assertTrue(version in spec, "%r should be in %r" % (version, spec))
00104 
00105     def test_prerelease_check(self):
00106         strict_spec = semantic_version.Spec('>=0.1.1-')
00107         lax_spec = semantic_version.Spec('>=0.1.1')
00108         version = semantic_version.Version('0.1.1-rc1+4.2')
00109         self.assertTrue(version in lax_spec, "%r should be in %r" % (version, lax_spec))
00110         self.assertFalse(version in strict_spec, "%r should not be in %r" % (version, strict_spec))
00111 
00112     def test_build_check(self):
00113         strict_spec = semantic_version.Spec('<=0.1.1-rc1+')
00114         lax_spec = semantic_version.Spec('<=0.1.1-rc1')
00115         version = semantic_version.Version('0.1.1-rc1+4.2')
00116         self.assertTrue(version in lax_spec, "%r should be in %r" % (version, lax_spec))
00117         self.assertFalse(version in strict_spec, "%r should not be in %r" % (version, strict_spec))
00118 
00119 
00120 if __name__ == '__main__':  # pragma: no cover
00121     unittest.main()
00122 


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