1 # test_run.py -- Tests for selftest.run
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.run."""
24 from selftest.run import (
26 expand_environment_strings,
31 from selftest.tests import TestCase
34 class ExpandEnvironmentStringsTests(TestCase):
36 def test_no_vars(self):
37 self.assertEquals("foo bar", expand_environment_strings("foo bar", {}))
39 def test_simple(self):
40 self.assertEquals("foo bar",
41 expand_environment_strings("foo $BLA", {"BLA": "bar"}))
43 def test_unknown(self):
44 self.assertEquals("foo $BLA",
45 expand_environment_strings("foo $BLA", {}))
48 class ExpandCommandListTests(TestCase):
50 def test_no_list(self):
51 self.assertIs(None, expand_command_list("test bla"))
54 self.assertEquals("test --list", expand_command_list("test $LISTOPT"))
57 class ExpandCommandRunTests(TestCase):
59 def test_idlist(self):
60 self.assertEquals(("test foo bar", None),
61 expand_command_run("test", False, True, subtests=["foo", "bar"]))
63 def test_idlist_all(self):
64 self.assertEquals(("test", None),
65 expand_command_run("test", False, True))
67 def test_loadlist(self):
68 (cmd, tmpf) = expand_command_run("test $LOADLIST", True, False,
69 subtests=["foo", "bar"])
70 self.addCleanup(os.remove, tmpf)
73 self.assertEquals(f.read(), "foo\nbar\n")
76 self.assertEquals("test --load-list=%s" % tmpf, cmd)
78 def test_loadlist_all(self):
79 self.assertEquals(("test ", None),
80 expand_command_run("test $LOADLIST", True, False))
83 class ExportedEnvvarsStrTests(TestCase):
85 def test_no_vars(self):
86 self.assertEquals("", exported_envvars_str({}, ["foo", "bar"]))
89 self.assertEquals("foo=1\n",
90 exported_envvars_str({"foo": "1"}, ["foo", "bar"]))
92 def test_vars_unknown(self):
93 self.assertEquals("foo=1\n",
94 exported_envvars_str({"foo": "1", "bla": "2"}, ["foo", "bar"]))