diff options
Diffstat (limited to 'tests')
-rwxr-xr-x | tests/test_base.py | 39 | ||||
-rwxr-xr-x | tests/test_match.py | 7 | ||||
-rw-r--r-- | tests/test_npm.py | 7 | ||||
-rwxr-xr-x | tests/test_parsing.py | 13 |
4 files changed, 66 insertions, 0 deletions
diff --git a/tests/test_base.py b/tests/test_base.py index 5a6497b..cd0b5f5 100755 --- a/tests/test_base.py +++ b/tests/test_base.py @@ -6,6 +6,7 @@ """Test the various functions from 'base'.""" import unittest +import sys from semantic_version import base @@ -13,6 +14,12 @@ from semantic_version import base class TopLevelTestCase(unittest.TestCase): """Test module-level functions.""" + if sys.version_info[0] <= 2: + import contextlib + @contextlib.contextmanager + def subTest(self, **kwargs): + yield + versions = ( ('0.1.0', '0.1.1', -1), ('0.1.1', '0.1.1', 0), @@ -89,6 +96,12 @@ class TopLevelTestCase(unittest.TestCase): class VersionTestCase(unittest.TestCase): + if sys.version_info[0] <= 2: + import contextlib + @contextlib.contextmanager + def subTest(self, **kwargs): + yield + versions = { '1.0.0-alpha': (1, 0, 0, ('alpha',), ()), '1.0.0-alpha.1': (1, 0, 0, ('alpha', '1'), ()), @@ -199,6 +212,7 @@ class VersionTestCase(unittest.TestCase): ])) ) + @unittest.skipIf(sys.version_info[0] <= 2, "Comparisons don't raise TypeError in Python 2") def test_invalid_comparisons(self): v = base.Version('0.1.0') with self.assertRaises(TypeError): @@ -367,6 +381,12 @@ class VersionTestCase(unittest.TestCase): class SpecItemTestCase(unittest.TestCase): + if sys.version_info[0] <= 2: + import contextlib + @contextlib.contextmanager + def subTest(self, **kwargs): + yield + invalids = [ '<=0.1.1+build3', '<=0.1.1+', @@ -540,6 +560,12 @@ class SpecItemTestCase(unittest.TestCase): class CoerceTestCase(unittest.TestCase): + if sys.version_info[0] <= 2: + import contextlib + @contextlib.contextmanager + def subTest(self, **kwargs): + yield + examples = { # Dict of target: [list of equivalents] '0.0.0': ('0', '0.0', '0.0.0', '0.0.0+', '0-'), @@ -564,6 +590,19 @@ class CoerceTestCase(unittest.TestCase): class SpecTestCase(unittest.TestCase): + if sys.version_info[0] <= 2: + import contextlib + @contextlib.contextmanager + def subTest(self, **kwargs): + yield + + def assertCountEqual(self, a, b): + import collections + self.assertEqual( + collections.Counter(a), + collections.Counter(b), + ) + examples = { '>=0.1.1,<0.1.2': ['>=0.1.1', '<0.1.2'], '>=0.1.0,!=0.1.3-rc1,<0.1.3': ['>=0.1.0', '!=0.1.3-rc1', '<0.1.3'], diff --git a/tests/test_match.py b/tests/test_match.py index 4bf7162..f807828 100755 --- a/tests/test_match.py +++ b/tests/test_match.py @@ -4,11 +4,18 @@ # This code is distributed under the two-clause BSD License. import unittest +import sys import semantic_version class MatchTestCase(unittest.TestCase): + if sys.version_info[0] <= 2: + import contextlib + @contextlib.contextmanager + def subTest(self, **kwargs): + yield + invalid_specs = [ '', '!0.1', diff --git a/tests/test_npm.py b/tests/test_npm.py index 86cbc76..7bed337 100644 --- a/tests/test_npm.py +++ b/tests/test_npm.py @@ -6,11 +6,18 @@ """Test NPM-style specifications.""" import unittest +import sys from semantic_version import base class NpmSpecTests(unittest.TestCase): + if sys.version_info[0] <= 2: + import contextlib + @contextlib.contextmanager + def subTest(self, **kwargs): + yield + examples = { # range: [matchings], [failings] '>=1.2.7': ( diff --git a/tests/test_parsing.py b/tests/test_parsing.py index 0da679f..01b7b5e 100755 --- a/tests/test_parsing.py +++ b/tests/test_parsing.py @@ -5,11 +5,18 @@ import itertools import unittest +import sys import semantic_version class ParsingTestCase(unittest.TestCase): + if sys.version_info[0] <= 2: + import contextlib + @contextlib.contextmanager + def subTest(self, **kwargs): + yield + invalids = [ None, '', @@ -66,6 +73,12 @@ class ParsingTestCase(unittest.TestCase): class ComparisonTestCase(unittest.TestCase): + if sys.version_info[0] <= 2: + import contextlib + @contextlib.contextmanager + def subTest(self, **kwargs): + yield + order = [ '1.0.0-alpha', '1.0.0-alpha.1', |