Add a few tests.

Signed-off-by: Raphaël Barrois <raphael.barrois@polyconseil.fr>
This commit is contained in:
Raphaël Barrois
2012-05-22 09:46:28 +02:00
parent 7e85ad59cf
commit 9e58282b8b
3 changed files with 32 additions and 2 deletions

View File

@@ -190,7 +190,7 @@ Representing a version (the Version class)
Version specifications (the Spec class)
-------------------------------------------
---------------------------------------
Version specifications describe a 'range' of accepted versions:

View File

@@ -128,7 +128,7 @@ class Version(object):
def __repr__(self):
return '<%sVersion(%s, %s, %s, %r, %r)>' % (
', partial=True' if self.partial else '',
'~' if self.partial else '',
self.major,
self.minor,
self.patch,

View File

@@ -59,6 +59,36 @@ class ComparisonTestCase(unittest.TestCase):
a, b, result, expected))
class TopLevelTestCase(unittest.TestCase):
"""Test module-level functions."""
versions = (
('0.1.0', '0.1.1', -1),
('0.1.1', '0.1.1', 0),
('0.1.1', '0.1.0', 1),
('0.1.0-alpha', '0.1.0', -1),
('0.1.0-alpha+2', '0.1.0-alpha', 1),
)
def test_compare(self):
for a, b, expected in self.versions:
result = base.compare(a, b)
self.assertEqual(expected, result,
"compare(%r, %r) should be %r instead of %r" % (a, b, expected, result))
matches = (
('>=0.1.1', '0.1.2'),
('>=0.1.1', '0.1.1'),
('>=0.1.1', '0.1.1-alpha'),
('>=0.1.1,!=0.2.0', '0.2.1'),
)
def test_match(self):
for spec, version in self.matches:
self.assertTrue(base.match(spec, version),
"%r should accept %r" % (spec, version))
class VersionTestCase(unittest.TestCase):
versions = {
'1.0.0-alpha': (1, 0, 0, ('alpha',), ()),