aboutsummaryrefslogtreecommitdiff
path: root/python/mask_TEST.py
blob: d272f2bddc4b9cc25b1ff67fcc1a16ee1e4927a4 (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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#!/usr/bin/env python
# vim: set fileencoding=utf-8 sw=4 sts=4 et :

#
# Copyright (c) 2007 Piotr JaroszyƄski
#
# 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
#

import os

os.environ["PALUDIS_HOME"] = os.path.join(os.getcwd(), "mask_TEST_dir/home")

from paludis import *
from additional_tests import *

import unittest

Log.instance.log_level = LogLevel.WARNING

class TestCase_01_Masks(unittest.TestCase):
    def setUp(self):
        self.e = EnvironmentFactory.instance.create("")

    def test_01_user_mask(self):
        q = Selection.RequireExactlyOne(Generator.Matches(
            parse_user_package_dep_spec("=masked/user-1.0", self.e, []), []))
        pid = next(iter(self.e[q]))
        m = next(iter(pid.masks))

        self.assert_(isinstance(m, Mask))
        self.assert_(isinstance(m, UserMask))

        self.assertEquals(m.key(), "U")
        self.assertEquals(m.description(), "user")

    def test_02_unaccepted_mask(self):
        q = Selection.RequireExactlyOne(Generator.Matches(
            parse_user_package_dep_spec("=masked/unaccepted-1.0", self.e, []), []))
        pid = next(iter(self.e[q]))
        m = next(iter(pid.masks))

        self.assert_(isinstance(m, Mask))
        self.assert_(isinstance(m, UnacceptedMask))

        self.assertEquals(m.key(), "K")
        self.assertEquals(m.description(), "keyword")
        self.assertEquals(m.unaccepted_key_name(), "KEYWORDS")

    def test_03_repository_mask(self):
        q = Selection.RequireExactlyOne(Generator.Matches(
            parse_user_package_dep_spec("=masked/repo-1.0", self.e, []), []))
        pid = next(iter(self.e[q]))
        m = next(iter(pid.masks))

        self.assert_(isinstance(m, Mask))
        self.assert_(isinstance(m, RepositoryMask))

        self.assertEquals(m.key(), "R")
        self.assertEquals(m.description(), "repository")

        package_mask_path = os.path.realpath(os.path.join(os.getcwd(),
            "mask_TEST_dir/testrepo/profiles/package.mask"))

    def test_04_unsupported_mask(self):
        q = Selection.RequireExactlyOne(Generator.Matches(
            parse_user_package_dep_spec("=masked/unsupported-1.0", self.e, []), []))
        pid = next(iter(self.e[q]))
        m = next(iter(pid.masks))

        self.assert_(isinstance(m, Mask))
        self.assert_(isinstance(m, UnsupportedMask))

        self.assertEquals(m.key(), "E")
        self.assertEquals(m.description(), "eapi")
        self.assertEquals(m.explanation(), "Unsupported EAPI 'unsupported'")

class TestCase_02_Masks_subclassing(unittest.TestCase):
    def test_01_user_mask(self):
        class TestUserMask(UserMask):
            def key(self):
                return "T"

            def description(self):
                return "test"

        test_user_mask(TestUserMask())

    def test_02_unaccepted_mask(self):
        class TestUnacceptedMask(UnacceptedMask):
            def key(self):
                return "T"

            def description(self):
                return "test"

            def unaccepted_key_name(self):
                return "monkey"

        test_unaccepted_mask(TestUnacceptedMask())

    def test_03_repository_mask(self):
        class TestRepositoryMask(RepositoryMask):
            def key(self):
                return "T"

            def description(self):
                return "test"

        test_repository_mask(TestRepositoryMask())

    def test_04_unsupported_mask(self):
        class TestUnsupportedMask(UnsupportedMask):
            def key(self):
                return "T"

            def description(self):
                return "test"

            def explanation(self):
                return "test"

        test_unsupported_mask(TestUnsupportedMask())


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