894ceaa7fccf37cef13c4ab98514a624e402a13e
[sharpe/samba-autobuild/.git] / selftest / tests / test_run.py
1 # test_run.py -- Tests for selftest.run
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.run."""
21
22 import os
23
24 from selftest.run import (
25     expand_command_list,
26     expand_environment_strings,
27     expand_command_run,
28     exported_envvars_str,
29     )
30
31 from selftest.tests import TestCase
32
33
34 class ExpandEnvironmentStringsTests(TestCase):
35
36     def test_no_vars(self):
37         self.assertEquals("foo bar", expand_environment_strings("foo bar", {}))
38
39     def test_simple(self):
40         self.assertEquals("foo bar",
41             expand_environment_strings("foo $BLA", {"BLA": "bar"}))
42
43     def test_unknown(self):
44         self.assertEquals("foo $BLA",
45             expand_environment_strings("foo $BLA", {}))
46
47
48 class ExpandCommandListTests(TestCase):
49
50     def test_no_list(self):
51         self.assertIs(None, expand_command_list("test bla"))
52
53     def test_list(self):
54         self.assertEquals("test --list", expand_command_list("test $LISTOPT"))
55
56
57 class ExpandCommandRunTests(TestCase):
58
59     def test_idlist(self):
60         self.assertEquals(("test foo bar", None),
61             expand_command_run("test", False, True, subtests=["foo", "bar"]))
62
63     def test_idlist_all(self):
64         self.assertEquals(("test", None),
65             expand_command_run("test", False, True))
66
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)
71         f = open(tmpf, 'r')
72         try:
73             self.assertEquals(f.read(), "foo\nbar\n")
74         finally:
75             f.close()
76         self.assertEquals("test --load-list=%s" % tmpf, cmd)
77
78     def test_loadlist_all(self):
79         self.assertEquals(("test ", None),
80             expand_command_run("test $LOADLIST", True, False))
81
82
83 class ExportedEnvvarsStrTests(TestCase):
84
85     def test_no_vars(self):
86         self.assertEquals("", exported_envvars_str({}, ["foo", "bar"]))
87
88     def test_vars(self):
89         self.assertEquals("foo=1\n",
90             exported_envvars_str({"foo": "1"}, ["foo", "bar"]))
91
92     def test_vars_unknown(self):
93         self.assertEquals("foo=1\n",
94             exported_envvars_str({"foo": "1", "bla": "2"}, ["foo", "bar"]))