summaryrefslogtreecommitdiff
path: root/tests/test_match.py
blob: 64011b1fb008c5b8511f4abf5d70554af74d4679 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import unittest

import semantic_version


class MatchTestCase(unittest.TestCase):
    invalid_specs = [
        '<0.1',
        '<=0.1.4a',
        '>0.1.1.1',
        '~0.1.2-rc23,1',
    ]

    valid_specs = [
        '~0.1',
        '<=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',
    ]

    matches = {
        '~0.1': [
            '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',
        ],
        '~0.1.2': [
            '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',
        ],
        '<=0.1.2': [
            '0.1.1',
            '0.1.2-rc1',
            '0.1.2-rc1.3.4',
        ],
    }

    def test_invalid(self):
        for invalid in self.invalid_specs:
            self.assertRaises(ValueError, semantic_version.RequirementSpec, invalid)

    def test_simple(self):
        for valid in self.valid_specs:
            version = semantic_version.RequirementSpec(valid)
            self.assertEqual(valid, str(version))

    def test_match(self):
        for spec_txt, versions in self.matches.items():
            spec = semantic_version.RequirementSpec(spec_txt)
            for version_txt in versions:
                version = semantic_version.SemanticVersion(version_txt)
                
                self.assertTrue(spec.match(version), "%r does not match %r" % (version, spec))


if __name__ == '__main__':
    unittest.main()