tdb: Slightly simplify tdb_lock_list
[Samba/gbeck.git] / selftest / tests / test_target.py
blob00b7126a073a5fcbf63a78ea9466c01e8ef30203
1 # test_target.py -- The tests for selftest target code
2 # Copyright (C) 2012 Jelmer Vernooij <jelmer@samba.org>
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.
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.
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.
20 """Tests for selftest.target."""
22 from selftest.target import (
23 Environment,
24 EnvironmentDown,
25 EnvironmentManager,
26 NoneEnvironment,
27 NoneTarget,
28 Target,
29 UnsupportedEnvironment,
32 from selftest.tests import TestCase
35 class DummyEnvironment(Environment):
37 def __init__(self, name, prefix):
38 self.name = name
39 self.prefix = prefix
40 self.check_ret = True
41 self.log_ret = ""
43 def check(self):
44 return self.check_ret
46 def get_log(self):
47 return self.log_ret
50 class DummyTarget(Target):
52 def setup_env(self, name, prefix):
53 return DummyEnvironment(name, prefix)
56 class NoneEnvironmentTests(TestCase):
58 def setUp(self):
59 super(NoneEnvironmentTests, self).setUp()
60 self.env = NoneEnvironment()
62 def test_get_vars(self):
63 self.assertEquals({}, self.env.get_vars())
65 def test_check(self):
66 self.assertEquals(True, self.env.check())
68 def test_get_log(self):
69 self.assertEquals("", self.env.get_log())
72 class NoneTargetTests(TestCase):
74 def setUp(self):
75 super(NoneTargetTests, self).setUp()
76 self.target = NoneTarget()
78 def test_setup_env(self):
79 self.assertRaises(UnsupportedEnvironment, self.target.setup_env,
80 "something", "prefx")
83 class EnvironmentManagerTests(TestCase):
85 def setUp(self):
86 super(EnvironmentManagerTests, self).setUp()
87 self.mgr = EnvironmentManager(DummyTarget())
89 def test_none(self):
90 self.assertIs(
91 NoneEnvironment, type(self.mgr.setup_env("none", "prefix")))
93 def test_setup(self):
94 env = self.mgr.setup_env("something", "prefix")
95 self.assertEquals(env.name, "something")
96 self.assertEquals(env.prefix, "prefix")
98 def test_setup_reuses(self):
99 env1 = self.mgr.setup_env("something", "prefix")
100 env2 = self.mgr.setup_env("something", "prefix")
101 self.assertIs(env1, env2)
103 def test_setup_down(self):
104 env1 = self.mgr.setup_env("something", "prefix")
105 env1.check_ret = False
106 self.assertRaises(EnvironmentDown, self.mgr.setup_env, "something", "")
108 def test_check(self):
109 env = self.mgr.setup_env("something", "prefix")
110 self.assertTrue(env.check())
111 self.assertTrue(self.mgr.check_env("something"))
112 env.check_ret = False
113 self.assertFalse(env.check())
114 self.assertFalse(self.mgr.check_env("something"))
116 def test_get_log(self):
117 env = self.mgr.setup_env("something", "prefix")
118 self.assertEquals("", env.get_log())
119 self.assertEquals("", self.mgr.getlog_env("something"))
120 env.log_ret = 'bla'
121 self.assertEquals('bla', env.get_log())
122 self.assertEquals('bla', self.mgr.getlog_env("something"))
124 def test_get_running_env(self):
125 env = self.mgr.setup_env("something", "prefix")
126 self.assertIs(env, self.mgr.get_running_env("something"))
128 def test_get_running_env_nonexistent(self):
129 self.assertIs(None, self.mgr.get_running_env("something"))