diff options
author | Raphaël Barrois <raphael.barrois@polytechnique.org> | 2012-05-14 23:38:07 +0200 |
---|---|---|
committer | Raphaël Barrois <raphael.barrois@polytechnique.org> | 2012-05-14 23:38:07 +0200 |
commit | cd54db43ee69f61e032c399a572adf044d748bac (patch) | |
tree | 90886d7c555f1afa240fbc1c35399068343d299a /tests | |
parent | 5d644f1fdd266969eafd09d520c54bd52592da52 (diff) | |
download | semantic-version-cd54db43ee69f61e032c399a572adf044d748bac.tar.gz |
More tests.
Signed-off-by: Raphaël Barrois <raphael.barrois@polytechnique.org>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_match.py | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/tests/test_match.py b/tests/test_match.py new file mode 100644 index 0000000..64011b1 --- /dev/null +++ b/tests/test_match.py @@ -0,0 +1,67 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +import unittest + +import semantic_version + + +class MatchTestCase(unittest.TestCase): + invalid_specs = [ + '<0.1', + '<=0.1.4a', + '>0.1.1.1', + '~0.1.2-rc23,1', + ] + + valid_specs = [ + '~0.1', + '<=0.1.1', + '>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', + ] + + matches = { + '~0.1': [ + '0.1.1', + '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': [ + '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': [ + '0.1.1', + '0.1.2-rc1', + '0.1.2-rc1.3.4', + ], + } + + def test_invalid(self): + for invalid in self.invalid_specs: + self.assertRaises(ValueError, semantic_version.RequirementSpec, invalid) + + def test_simple(self): + for valid in self.valid_specs: + version = semantic_version.RequirementSpec(valid) + self.assertEqual(valid, str(version)) + + def test_match(self): + for spec_txt, versions in self.matches.items(): + spec = semantic_version.RequirementSpec(spec_txt) + for version_txt in versions: + version = semantic_version.SemanticVersion(version_txt) + + self.assertTrue(spec.match(version), "%r does not match %r" % (version, spec)) + + +if __name__ == '__main__': + unittest.main() + |