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
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,
20 """Tests for selftest.target."""
22 from selftest
.target
import (
29 UnsupportedEnvironment
,
32 from selftest
.tests
import TestCase
35 class DummyEnvironment(Environment
):
37 def __init__(self
, name
, prefix
):
50 class DummyTarget(Target
):
52 def setup_env(self
, name
, prefix
):
53 return DummyEnvironment(name
, prefix
)
56 class NoneEnvironmentTests(TestCase
):
59 super(NoneEnvironmentTests
, self
).setUp()
60 self
.env
= NoneEnvironment()
62 def test_get_vars(self
):
63 self
.assertEquals({}, self
.env
.get_vars())
66 self
.assertEquals(True, self
.env
.check())
68 def test_get_log(self
):
69 self
.assertEquals("", self
.env
.get_log())
72 class NoneTargetTests(TestCase
):
75 super(NoneTargetTests
, self
).setUp()
76 self
.target
= NoneTarget()
78 def test_setup_env(self
):
79 self
.assertRaises(UnsupportedEnvironment
, self
.target
.setup_env
,
83 class EnvironmentManagerTests(TestCase
):
86 super(EnvironmentManagerTests
, self
).setUp()
87 self
.mgr
= EnvironmentManager(DummyTarget())
91 NoneEnvironment
, type(self
.mgr
.setup_env("none", "prefix")))
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"))
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"))