summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorRaphaël Barrois <raphael.barrois@polytechnique.org>2013-03-21 23:38:40 +0100
committerRaphaël Barrois <raphael.barrois@polytechnique.org>2013-03-21 23:38:49 +0100
commit6aae60fb530f7608bc379a57a477e904a816544d (patch)
tree44a68fb691b7d9aeb0a560b54438f6f7180ce02d /tests
parenta77278819e5f9637e8ff1954ec33ecbf753ac89a (diff)
downloadsemantic-version-6aae60fb530f7608bc379a57a477e904a816544d.tar.gz
Add Python3 support.
Diffstat (limited to 'tests')
-rw-r--r--tests/compat.py14
-rwxr-xr-xtests/test_base.py27
-rw-r--r--tests/test_django.py4
-rwxr-xr-xtests/test_parsing.py4
4 files changed, 42 insertions, 7 deletions
diff --git a/tests/compat.py b/tests/compat.py
new file mode 100644
index 0000000..90f1baa
--- /dev/null
+++ b/tests/compat.py
@@ -0,0 +1,14 @@
+# -*- coding: utf-8 -*-
+# Copyright (c) 2012-2013 Raphaël Barrois
+# This code is distributed under the two-clause BSD License.
+
+import sys
+
+is_python2 = (sys.version_info[0] == 2)
+
+
+try: # pragma: no cover
+ import unittest2 as unittest
+except ImportError: # pragma: no cover
+ import unittest
+
diff --git a/tests/test_base.py b/tests/test_base.py
index 84119f1..3006ba0 100755
--- a/tests/test_base.py
+++ b/tests/test_base.py
@@ -5,11 +5,7 @@
"""Test the various functions from 'base'."""
-try: # pragma: no cover
- import unittest2 as unittest
-except ImportError: # pragma: no cover
- import unittest
-
+from .compat import unittest, is_python2
from semantic_version import base
@@ -171,6 +167,8 @@ class VersionTestCase(unittest.TestCase):
self.assertNotEqual(text, base.Version(text))
partial_versions = {
+ '1.1': (1, 1, None, None, None),
+ '2': (2, None, None, None, None),
'1.0.0-alpha': (1, 0, 0, ('alpha',), None),
'1.0.0-alpha.1': (1, 0, 0, ('alpha', '1'), None),
'1.0.0-beta.2': (1, 0, 0, ('beta', '2'), None),
@@ -229,6 +227,21 @@ class VersionTestCase(unittest.TestCase):
]))
)
+ @unittest.skipIf(is_python2, "Comparisons to other objects are broken in Py2.")
+ def test_invalid_comparisons(self):
+ v = base.Version('0.1.0')
+ with self.assertRaises(TypeError):
+ v < '0.1.0'
+ with self.assertRaises(TypeError):
+ v <= '0.1.0'
+ with self.assertRaises(TypeError):
+ v > '0.1.0'
+ with self.assertRaises(TypeError):
+ v >= '0.1.0'
+
+ self.assertTrue(v != '0.1.0')
+ self.assertFalse(v == '0.1.0')
+
class SpecItemTestCase(unittest.TestCase):
components = {
@@ -345,6 +358,7 @@ class SpecItemTestCase(unittest.TestCase):
class CoerceTestCase(unittest.TestCase):
examples = {
# Dict of target: [list of equivalents]
+ '0.0.0': ('0', '0.0', '0.0.0', '0.0.0+', '0-', '00000000.00'),
'0.1.0': ('0.1', '0.1+', '0.1-', '0.1.0', '0.000001.000000000000'),
'0.1.0+2': ('0.1.0+2', '0.1.0.2'),
'0.1.0+2.3.4': ('0.1.0+2.3.4', '0.1.0+2+3+4', '0.1.0.2+3+4'),
@@ -360,6 +374,9 @@ class CoerceTestCase(unittest.TestCase):
v_sample = base.Version.coerce(sample)
self.assertEqual(target, v_sample)
+ def test_invalid(self):
+ self.assertRaises(ValueError, base.Version.coerce, 'v1')
+
class SpecTestCase(unittest.TestCase):
examples = {
diff --git a/tests/test_django.py b/tests/test_django.py
index fd4e044..ffdfe58 100644
--- a/tests/test_django.py
+++ b/tests/test_django.py
@@ -2,6 +2,8 @@
# Copyright (c) 2012-2013 Raphaël Barrois
# This code is distributed under the two-clause BSD License.
+from __future__ import unicode_literals
+
try: # pragma: no cover
import unittest2 as unittest
except ImportError: # pragma: no cover
@@ -28,7 +30,7 @@ if django_loaded: # pragma: no cover
'tests.django_test_app',
]
)
- from django_test_app import models
+ from .django_test_app import models
from django.core import serializers
try: # pragma: no cover
diff --git a/tests/test_parsing.py b/tests/test_parsing.py
index 01c8ae8..585011d 100755
--- a/tests/test_parsing.py
+++ b/tests/test_parsing.py
@@ -63,7 +63,9 @@ class ComparisonTestCase(unittest.TestCase):
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))
- self.assertEqual(cmp(i, j), semantic_version.compare(first, second))
+
+ cmp_res = -1 if i < j else (1 if i > j else 0)
+ self.assertEqual(cmp_res, semantic_version.compare(first, second))
if __name__ == '__main__': # pragma: no cover