aboutsummaryrefslogtreecommitdiff
path: root/python/choices_TEST.py
blob: e22b0a5e74d539182891bcacff6c4474523061e2 (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
139
#!/usr/bin/env python
# vim: set fileencoding=utf-8 sw=4 sts=4 et :

#
# Copyright (c) 2008, 2011 Ciaran McCreesh
#
# 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

repo_path = os.path.join(os.getcwd(), "choices_TEST_dir/testrepo")
ph = os.path.join(os.getcwd(), "choices_TEST_dir/home")
os.environ["PALUDIS_HOME"] = ph

from paludis import *
from additional_tests import *

import unittest

Log.instance.log_level = LogLevel.WARNING

class TestCase_01_Choices(unittest.TestCase):
    def setUp(self):
        self.e = EnvironmentFactory.instance.create("")
        self.pid = iter(self.e.fetch_repository("testrepo").package_ids("foo/bar", [])).next()
        self.choices = self.pid.find_metadata("PALUDIS_CHOICES").parse_value()

    def test_01_choices(self):
        self.assert_(isinstance(self.choices, Choices), self.choices.__class__)

    def test_02_find_by_name_with_prefix(self):
        self.assert_(self.choices.find_by_name_with_prefix("testflag"))
        self.assert_(isinstance(self.choices.find_by_name_with_prefix("testflag"), ChoiceValue))
        self.assert_(not self.choices.find_by_name_with_prefix("monkey"))

    def test_03_has_matching_contains_every_value_prefix(self):
        self.assert_(self.choices.has_matching_contains_every_value_prefix("linguas_en"))
        self.assert_(not self.choices.has_matching_contains_every_value_prefix("foo"))

    def test_04_iter(self):
        self.assert_(isinstance(iter(self.choices).next(), Choice))
        found = False
        for f in self.choices:
            if f.raw_name == "USE":
                found = True
        self.assert_(found)

class TestCase_02_Choice(unittest.TestCase):
    def setUp(self):
        self.e = EnvironmentFactory.instance.create("")
        self.pid = iter(self.e.fetch_repository("testrepo").package_ids("foo/bar", [])).next()
        self.choices = self.pid.find_metadata("PALUDIS_CHOICES").parse_value()
        self.use = None
        self.linguas = None
        for f in self.choices:
            if f.raw_name == "USE":
                self.use = f
            elif f.raw_name == "LINGUAS":
                self.linguas = f

    def test_01_use(self):
        self.assert_(self.use)
        self.assertEquals(self.use.raw_name, "USE")
        self.assertEquals(self.use.human_name, "USE")
        self.assertEquals(self.use.prefix, "")
        self.assertEquals(self.use.contains_every_value, False)
        self.assertEquals(self.use.hidden, False)
        self.assertEquals(self.use.show_with_no_prefix, True)
        self.assertEquals(self.use.consider_added_or_changed, True)

    def test_02_linguas(self):
        self.assert_(self.linguas)
        self.assertEquals(self.linguas.raw_name, "LINGUAS")
        self.assertEquals(self.linguas.human_name, "linguas")
        self.assertEquals(self.linguas.prefix, "linguas")
        self.assertEquals(self.linguas.contains_every_value, True)
        self.assertEquals(self.linguas.hidden, False)
        self.assertEquals(self.linguas.show_with_no_prefix, False)
        self.assertEquals(self.linguas.consider_added_or_changed, True)

    def test_03_use_iter(self):
        self.assert_(isinstance(iter(self.use).next(), ChoiceValue))
        found = False
        for f in self.use:
            if f.name_with_prefix == "testflag":
                found = True
        self.assert_(found)

    def test_04_linguas_iter(self):
        self.assert_(isinstance(iter(self.linguas).next(), ChoiceValue))
        found = False
        for f in self.linguas:
            if f.name_with_prefix == "linguas_en":
                found = True
        self.assert_(found)

class TestCase_03_ChoiceValue(unittest.TestCase):
    def setUp(self):
        self.e = EnvironmentFactory.instance.create("")
        self.pid = iter(self.e.fetch_repository("testrepo").package_ids("foo/bar", [])).next()
        self.choices = self.pid.find_metadata("PALUDIS_CHOICES").parse_value()
        self.use_testflag = self.choices.find_by_name_with_prefix("testflag")
        self.linguas_en = self.choices.find_by_name_with_prefix("linguas_en")

    def test_01_use_testflag(self):
        self.assert_(self.use_testflag)
        self.assertEquals(self.use_testflag.unprefixed_name, "testflag")
        self.assertEquals(self.use_testflag.name_with_prefix, "testflag")
        self.assertEquals(self.use_testflag.enabled, False)
        self.assertEquals(self.use_testflag.enabled_by_default, False)
        self.assertEquals(self.use_testflag.locked, False)
        self.assertEquals(self.use_testflag.description, "the test flag")
        self.assertEquals(self.use_testflag.explicitly_listed, True)

    def test_02_linguas_en(self):
        self.assert_(self.linguas_en)
        self.assertEquals(self.linguas_en.unprefixed_name, "en")
        self.assertEquals(self.linguas_en.name_with_prefix, "linguas_en")
        self.assertEquals(self.linguas_en.enabled, False)
        self.assertEquals(self.linguas_en.enabled_by_default, False)
        self.assertEquals(self.linguas_en.locked, False)
        self.assertEquals(self.linguas_en.description, "English")
        self.assertEquals(self.linguas_en.explicitly_listed, True)

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