ยปCore Development>Code coverage>Lib/distutils/tests/test_version.py

Python code coverage for Lib/distutils/tests/test_version.py

#countcontent
1n/a"""Tests for distutils.version."""
2n/aimport unittest
3n/afrom distutils.version import LooseVersion
4n/afrom distutils.version import StrictVersion
5n/afrom test.support import run_unittest
6n/a
7n/aclass VersionTestCase(unittest.TestCase):
8n/a
9n/a def test_prerelease(self):
10n/a version = StrictVersion('1.2.3a1')
11n/a self.assertEqual(version.version, (1, 2, 3))
12n/a self.assertEqual(version.prerelease, ('a', 1))
13n/a self.assertEqual(str(version), '1.2.3a1')
14n/a
15n/a version = StrictVersion('1.2.0')
16n/a self.assertEqual(str(version), '1.2')
17n/a
18n/a def test_cmp_strict(self):
19n/a versions = (('1.5.1', '1.5.2b2', -1),
20n/a ('161', '3.10a', ValueError),
21n/a ('8.02', '8.02', 0),
22n/a ('3.4j', '1996.07.12', ValueError),
23n/a ('3.2.pl0', '3.1.1.6', ValueError),
24n/a ('2g6', '11g', ValueError),
25n/a ('0.9', '2.2', -1),
26n/a ('1.2.1', '1.2', 1),
27n/a ('1.1', '1.2.2', -1),
28n/a ('1.2', '1.1', 1),
29n/a ('1.2.1', '1.2.2', -1),
30n/a ('1.2.2', '1.2', 1),
31n/a ('1.2', '1.2.2', -1),
32n/a ('0.4.0', '0.4', 0),
33n/a ('1.13++', '5.5.kw', ValueError))
34n/a
35n/a for v1, v2, wanted in versions:
36n/a try:
37n/a res = StrictVersion(v1)._cmp(StrictVersion(v2))
38n/a except ValueError:
39n/a if wanted is ValueError:
40n/a continue
41n/a else:
42n/a raise AssertionError(("cmp(%s, %s) "
43n/a "shouldn't raise ValueError")
44n/a % (v1, v2))
45n/a self.assertEqual(res, wanted,
46n/a 'cmp(%s, %s) should be %s, got %s' %
47n/a (v1, v2, wanted, res))
48n/a
49n/a
50n/a def test_cmp(self):
51n/a versions = (('1.5.1', '1.5.2b2', -1),
52n/a ('161', '3.10a', 1),
53n/a ('8.02', '8.02', 0),
54n/a ('3.4j', '1996.07.12', -1),
55n/a ('3.2.pl0', '3.1.1.6', 1),
56n/a ('2g6', '11g', -1),
57n/a ('0.960923', '2.2beta29', -1),
58n/a ('1.13++', '5.5.kw', -1))
59n/a
60n/a
61n/a for v1, v2, wanted in versions:
62n/a res = LooseVersion(v1)._cmp(LooseVersion(v2))
63n/a self.assertEqual(res, wanted,
64n/a 'cmp(%s, %s) should be %s, got %s' %
65n/a (v1, v2, wanted, res))
66n/a
67n/adef test_suite():
68n/a return unittest.makeSuite(VersionTestCase)
69n/a
70n/aif __name__ == "__main__":
71n/a run_unittest(test_suite())