summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorRaphaël Barrois <raphael.barrois@polyconseil.fr>2012-05-14 18:42:09 +0200
committerRaphaël Barrois <raphael.barrois@polyconseil.fr>2012-05-14 18:42:09 +0200
commit23864f705ca70a7902cf3fa972ca0cff2792c87c (patch)
treec2d31bbf1912251c2de5e0674beb9576ff795a2e /tests
downloadsemantic-version-23864f705ca70a7902cf3fa972ca0cff2792c87c.tar.gz
Initial version
Signed-off-by: Raphaël Barrois <raphael.barrois@polyconseil.fr>
Diffstat (limited to 'tests')
-rw-r--r--tests/__init__.py0
-rw-r--r--tests/test_parsing.py64
2 files changed, 64 insertions, 0 deletions
diff --git a/tests/__init__.py b/tests/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/tests/__init__.py
diff --git a/tests/test_parsing.py b/tests/test_parsing.py
new file mode 100644
index 0000000..cdf21fc
--- /dev/null
+++ b/tests/test_parsing.py
@@ -0,0 +1,64 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+import unittest
+
+import semantic_version
+
+
+class ParsingTestCase(unittest.TestCase):
+ invalids = [
+ '0.1',
+ '0.1.4a',
+ '0.1.1.1',
+ '0.1.2-rc23,1',
+ ]
+
+ valids = [
+ '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',
+ ]
+
+ def test_invalid(self):
+ for invalid in self.invalids:
+ self.assertRaises(ValueError, semantic_version.SemanticVersion, invalid)
+
+ def test_simple(self):
+ for valid in self.valids:
+ version = semantic_version.SemanticVersion(valid)
+ self.assertEqual(valid, str(version))
+
+
+class ComparisonTestCase(unittest.TestCase):
+ order = [
+ '1.0.0-alpha',
+ '1.0.0-alpha.1',
+ '1.0.0-beta.2',
+ '1.0.0-beta.11',
+ '1.0.0-rc.1',
+ '1.0.0-rc.1+build.1',
+ '1.0.0',
+ '1.0.0+0.3.7',
+ '1.3.7+build',
+ '1.3.7+build.2.b8f12d7',
+ '1.3.7+build.11.e0f985a',
+ ]
+
+ def test_comparisons(self):
+ for i, first in enumerate(self.order):
+ first_ver = semantic_version.SemanticVersion(first)
+ for j, second in enumerate(self.order):
+ second_ver = semantic_version.SemanticVersion(second)
+ if i < j:
+ self.assertTrue(first_ver < second_ver, '%r !< %r' % (first_ver, second_ver))
+ elif i == j:
+ self.assertTrue(first_ver == second_ver, '%r != %r' % (first_ver, second_ver))
+ else:
+ self.assertTrue(first_ver > second_ver, '%r !> %r' % (first_ver, second_ver))
+
+
+if __name__ == '__main__':
+ unittest.main()