aboutsummaryrefslogtreecommitdiff
path: root/python/dep_spec_TEST.py
blob: ac6a194eb32bf7b59b040eab78d92f1275c7e333 (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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#!/usr/bin/env python
# vim: set fileencoding=utf-8 sw=4 sts=4 et :

#
# Copyright (c) 2007 Piotr Jaroszyński <peper@gentoo.org>
#
# This file is part of the Paludis package manager. Paludis is free software;
# you can redistribute it and/or modify it under the terms of the GNU General
# Public License version 2, as published by the Free Software Foundation.
#
# Paludis is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along with
# this program; if not, write to the Free Software Foundation, Inc., 59 Temple
# Place, Suite 330, Boston, MA  02111-1307  USA
#

from paludis import *
import unittest

class TestCase_1_DepSpecs(unittest.TestCase):
    def get_depspecs(self):
        self.ptds = PlainTextDepSpec("foo")
        self.pds = PackageDepSpec(">=foo/bar-1:100::testrepo", PackageDepSpecParseMode.PERMISSIVE)
        self.bds = BlockDepSpec(self.pds)

    def test_01_init(self):
        self.get_depspecs()

    def test_02_create_error(self):
        self.assertRaises(Exception, DepSpec)
        self.assertRaises(Exception, AllDepSpec)
        self.assertRaises(Exception, AnyDepSpec)
        self.assertRaises(Exception, StringDepSpec)
        self.assertRaises(BadVersionOperatorError, PackageDepSpec, "<>foo/bar", PackageDepSpecParseMode.PERMISSIVE)
        self.assertRaises(PackageDepSpecError, PackageDepSpec, "=foo/bar", PackageDepSpecParseMode.PERMISSIVE)

    def test_03_str(self):
        self.get_depspecs()
        self.assertEqual(str(self.ptds), "foo")
        self.assertEqual(str(self.pds), ">=foo/bar-1:100::testrepo")
        self.assertEqual(str(self.bds.blocked_spec), ">=foo/bar-1:100::testrepo")

    def test_04_slot(self):
        self.get_depspecs()
        self.assertEqual(str(self.pds.slot), "100")

    def test_05_package(self):
        self.get_depspecs()
        self.assertEqual(str(self.pds.package), "foo/bar")

    def test_06_repository(self):
        self.get_depspecs()
        self.assertEqual(str(self.pds.repository), "testrepo")

    def test_07_version_requirements(self):
        self.get_depspecs()
        vrc = self.pds.version_requirements

        self.assertEquals(len(list(vrc)), 1)
        self.assertEquals(iter(vrc).next().version_spec, VersionSpec("1"))
        self.assertEquals(iter(vrc).next().version_operator.value, VersionOperator(">=").value)

    def test_08_version_requirements_mode(self):
        self.get_depspecs()
        self.assertEquals(self.pds.version_requirements_mode, VersionRequirementsMode.AND)

#    def test_09_use_requirements(self):
#        spec = PortageDepParser.parse_depend("foo/monkey[foo]", PackageDepSpecParseMode.PERMISSIVE)
#        ur = iter(iter(spec).next().use_requirements).next()
#        self.assertEquals(str(ur[0]), "foo")
#        self.assertEquals(ur[1], UseFlagState.ENABLED)
#
#    def test_10_composites(self):
#        spec = PortageDepParser.parse_depend("|| ( foo/bar foo/baz ) foo/monkey",
#                PackageDepSpecParseMode.PERMISSIVE)
#
#        self.assert_(isinstance(spec, CompositeDepSpec))
#        self.assert_(isinstance(spec, AllDepSpec))
#
#        self.assertEqual(len(list(spec)), 2)
#
#        for i, subspec1 in enumerate(spec):
#            if i == 0:
#                self.assert_(isinstance(subspec1, AnyDepSpec))
#                for j, subspec2 in enumerate(subspec1):
#                    if j == 0:
#                        self.assert_(isinstance(subspec2, PackageDepSpec))
#                        self.assertEquals(str(subspec2), "foo/bar")
#                    elif j == 1:
#                        self.assert_(isinstance(subspec2, PackageDepSpec))
#                        self.assertEquals(str(subspec2), "foo/baz")
#                    else:
#                        self.assertEquals("Too many items", "OK")
#            elif i == 1:
#                self.assert_(isinstance(subspec1, PackageDepSpec))
#                self.assertEquals(str(subspec1), "foo/monkey")
#            else:
#                self.assertEquals("Too many items", "OK")

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