1 # test_testlist.py -- The tests for selftest testlist 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.testlist."""
22 from selftest.testlist import (
23 RestrictedTestManager,
29 from cStringIO import StringIO
34 class FindInListTests(unittest.TestCase):
37 self.assertIs(None, find_in_list([], "foo.test"))
39 def test_no_reason(self):
40 self.assertEquals("because",
41 find_in_list([("foo.*bar", "because")], "foo.bla.bar"))
44 class ReadTestRegexesTests(unittest.TestCase):
46 def test_comment(self):
47 f = StringIO("# I am a comment\n # I am also a comment\n")
48 self.assertEquals([], list(read_test_regexes(f)))
50 def test_no_reason(self):
51 f = StringIO(" foo\n")
52 self.assertEquals([("foo", None)], list(read_test_regexes(f)))
54 def test_reason(self):
55 f = StringIO(" foo # because\nbar\n")
56 self.assertEquals([("foo", "because"), ("bar", None)],
57 list(read_test_regexes(f)))
60 class ReadTestlistTests(unittest.TestCase):
62 def test_read_list(self):
63 inf = StringIO("-- TEST --\nfoo\nbar\nbla\n")
65 self.assertEquals([('foo', 'bar', 'bla', False, False)],
66 list(read_testlist(inf, outf)))
67 self.assertEquals("", outf.getvalue())
69 def test_read_list_passes_through(self):
70 inf = StringIO("MORENOISE\n-- TEST --\nfoo\nbar\nbla\nNOISE\n")
72 self.assertEquals([('foo', 'bar', 'bla', False, False)],
73 list(read_testlist(inf, outf)))
74 self.assertEquals("MORENOISE\nNOISE\n", outf.getvalue())
78 class RestrictedTestManagerTests(unittest.TestCase):
80 def test_unused(self):
81 mgr = RestrictedTestManager(["foo.bar"])
82 self.assertEquals(["foo.bar"], list(mgr.iter_unused()))
84 def test_run_testsuite(self):
85 mgr = RestrictedTestManager(["foo.bar"])
86 self.assertEquals(None, mgr.should_run_testsuite("foo.bar"))
88 def test_run_subtest(self):
89 mgr = RestrictedTestManager(["foo.bar.bla"])
90 self.assertEquals(["bla"], mgr.should_run_testsuite("foo.bar"))
92 def test_run_subtest_after_testsuite(self):
93 mgr = RestrictedTestManager(["foo.bar", "foo.bar.bla"])
94 self.assertEquals(None, mgr.should_run_testsuite("foo.bar"))
96 def test_run_multiple_subtests(self):
97 mgr = RestrictedTestManager(["foo.bar.blie", "foo.bar.bla"])
98 self.assertEquals(["blie", "bla"], mgr.should_run_testsuite("foo.bar"))
100 def test_run_nomatch(self):
101 mgr = RestrictedTestManager(["foo.bar"])
102 self.assertEquals([], mgr.should_run_testsuite("foo.blie.bla"))