aboutsummaryrefslogtreecommitdiff
path: root/python/environment_TEST.py
blob: 54086c8899636620039f52bd68e876992080fe79 (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
140
141
142
143
#!/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

ph = os.path.join(os.getcwd(), "environment_TEST_dir/home")
repo = os.path.join(os.getcwd(), "environment_TEST_dir/testrepo")
slaverepo = os.path.join(os.getcwd(), "environment_TEST_dir/slaverepo")
os.environ["PALUDIS_HOME"] = ph

from paludis import *
from additional_tests import *

import unittest

Log.instance.log_level = LogLevel.WARNING

class TestCase_01_Environments(unittest.TestCase):
    def setUp(self):
        self.e = EnvironmentFactory.instance.create("")
        self.nce = NoConfigEnvironment(repo)

    def test_01_create(self):
        NoConfigEnvironment(repo)
        NoConfigEnvironment(repo, "/var/empty")
        NoConfigEnvironment(repo, "/var/empty", "")
        NoConfigEnvironment(repo, master_repository_name="")
        NoConfigEnvironment(repo, write_cache_dir="/var/empty")

    def test_02_create_error(self):
        self.assertRaises(Exception, Environment)
        self.assertRaises(Exception, NoConfigEnvironment)

    def test_03_subclass(self):
        self.assert_(isinstance(NoConfigEnvironment(repo), Environment))

    def test_06_package_database(self):
        self.assert_(isinstance(self.e.package_database, PackageDatabase))
        self.assert_(isinstance(self.nce.package_database, PackageDatabase))

    def test_07_sets(self):
        self.assert_(isinstance(self.e.set("everything"), AllDepSpec))
        self.assert_(isinstance(self.nce.set("everything"), AllDepSpec))

        self.assert_(isinstance(self.e.set_names, SetNameIterable))
        self.assert_(isinstance(self.nce.set_names, SetNameIterable))

    def test_08_repositories(self):
        nce2 = NoConfigEnvironment(repo, master_repository_name="slaverepo", extra_repository_dirs=[slaverepo])

        self.assert_(isinstance(self.nce.main_repository, Repository))
        self.assertEquals(self.nce.master_repository, None)
        self.assert_(isinstance(nce2.main_repository, Repository))
        self.assert_(isinstance(nce2.master_repository, Repository))

    def test_12_config_dir(self):
        self.assert_(isinstance(self.e.config_dir, str))

class TestCase_03_TestEnvironment(unittest.TestCase):
    def test_01_create(self):
        env = TestEnvironment()

class TestCase_04_Environment_subclassingd(unittest.TestCase):
    class SubEnv(EnvironmentImplementation):
        def __init__(self):
            EnvironmentImplementation.__init__(self)

        def accept_license(self, l, pid):
            return False

        def accept_keywords(self, kns, pid):
            return False

        def mask_for_breakage(self, pid):
            return UserMask()

        def mask_for_user(self, pid, b):
            return UserMask()

        def unmasked_by_user(self, pid, reason):
            return False

        def bashrc_files(self):
            return ["/path"]

        def syncers_dirs(self):
            return ["/path"]

        def fetchers_dirs(self):
            return ["/path"]

        def hook_dirs(self):
            return ["/path"]

        def paludis_command(self):
            return "paludis"

        def set_paludis_command(self, s):
            pass

        def reduced_uid(self):
            return 0

        def reduced_gid(self):
            return 0

        def mirrors(self, mirror):
            return ["mirror"]

        def set_names(self):
            return ["set"]

        def set(self, set):
            return AllDepSpec()

        def distribution(self):
            return EnvironmentImplementation.distribution(self)

        def need_keys_added(self):
            return

    def test_01_environment_implementation(self):
        test_env(self.SubEnv())

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