f1ce4bc9de80d84557994472ec22fe0ffc6857d4
[ira/wip.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     )
29
30 from selftest.tests import TestCase
31
32
33 class ExpandEnvironmentStringsTests(TestCase):
34
35     def test_no_vars(self):
36         self.assertEquals("foo bar", expand_environment_strings("foo bar", {}))
37
38     def test_simple(self):
39         self.assertEquals("foo bar",
40             expand_environment_strings("foo $BLA", {"BLA": "bar"}))
41
42     def test_unknown(self):
43         self.assertEquals("foo $BLA",
44             expand_environment_strings("foo $BLA", {}))
45
46
47 class ExpandCommandListTests(TestCase):
48
49     def test_no_list(self):
50         self.assertIs(None, expand_command_list("test bla"))
51
52     def test_list(self):
53         self.assertEquals("test --list", expand_command_list("test $LISTOPT"))
54
55
56 class ExpandCommandRunTests(TestCase):
57
58     def test_idlist(self):
59         self.assertEquals(("test foo bar", None),
60             expand_command_run("test", False, True, subtests=["foo", "bar"]))
61
62     def test_idlist_all(self):
63         self.assertEquals(("test", None),
64             expand_command_run("test", False, True))
65
66     def test_loadlist(self):
67         (cmd, tmpf) = expand_command_run("test $LOADLIST", True, False,
68             subtests=["foo", "bar"])
69         self.addCleanup(os.remove, tmpf)
70         f = open(tmpf, 'r')
71         try:
72             self.assertEquals(f.read(), "foo\nbar\n")
73         finally:
74             f.close()
75         self.assertEquals("test --load-list=%s" % tmpf, cmd)
76
77     def test_loadlist_all(self):
78         self.assertEquals(("test ", None),
79             expand_command_run("test $LOADLIST", True, False))