selftest.target: Add tests for check.
[sfrench/samba-autobuild/.git] / selftest / tests / test_target.py
1 # test_target.py -- The tests for selftest target code
2 # Copyright (C) 2012 Jelmer Vernooij <jelmer@samba.org>
3 #
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; version 3
7 # of the License or (at your option) any later version of
8 # the License.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
18 # MA  02110-1301, USA.
19
20 """Tests for selftest.target."""
21
22 from selftest.target import (
23     EnvironmentManager,
24     NoneEnvironment,
25     Environment,
26     Target,
27     )
28
29 import unittest
30
31
32 class DummyEnvironment(Environment):
33
34     def __init__(self, name, prefix):
35         self.name = name
36         self.prefix = prefix
37         self.check_ret = True
38         self.log_ret = ""
39
40     def check(self):
41         return self.check_ret
42
43     def get_log(self):
44         return self.log_ret
45
46
47 class DummyTarget(Target):
48
49     def setup_env(self, name, prefix):
50         return DummyEnvironment(name, prefix)
51
52
53 class EnvironmentManagerTests(unittest.TestCase):
54
55     def setUp(self):
56         self.mgr = EnvironmentManager(DummyTarget())
57
58     def test_none(self):
59         self.assertIs(
60             NoneEnvironment, type(self.mgr.setup_env("none", "prefix")))
61
62     def test_setup(self):
63         env = self.mgr.setup_env("something", "prefix")
64         self.assertEquals(env.name, "something")
65         self.assertEquals(env.prefix, "prefix")
66
67     def test_check(self):
68         env = self.mgr.setup_env("something", "prefix")
69         self.assertTrue(env.check())
70         self.assertTrue(self.mgr.check_env("something"))
71         env.check_ret = False
72         self.assertFalse(env.check())
73         self.assertFalse(self.mgr.check_env("something"))