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 (
28 from cStringIO import StringIO
33 class FindInListTests(unittest.TestCase):
36 self.assertIs(None, find_in_list([], "foo.test"))
38 def test_no_reason(self):
39 self.assertEquals("because",
40 find_in_list([("foo.*bar", "because")], "foo.bla.bar"))
43 class ReadTestRegexesTests(unittest.TestCase):
45 def test_comment(self):
46 f = StringIO("# I am a comment\n # I am also a comment\n")
47 self.assertEquals([], list(read_test_regexes(f)))
49 def test_no_reason(self):
50 f = StringIO(" foo\n")
51 self.assertEquals([("foo", None)], list(read_test_regexes(f)))
53 def test_reason(self):
54 f = StringIO(" foo # because\nbar\n")
55 self.assertEquals([("foo", "because"), ("bar", None)],
56 list(read_test_regexes(f)))
59 class ReadTestlistTests(unittest.TestCase):
61 def test_read_list(self):
62 inf = StringIO("-- TEST --\nfoo\nbar\nbla\n")
64 self.assertEquals([('foo', 'bar', 'bla', False, False)],
65 list(read_testlist(inf, outf)))
66 self.assertEquals("", outf.getvalue())
68 def test_read_list_passes_through(self):
69 inf = StringIO("MORENOISE\n-- TEST --\nfoo\nbar\nbla\nNOISE\n")
71 self.assertEquals([('foo', 'bar', 'bla', False, False)],
72 list(read_testlist(inf, outf)))
73 self.assertEquals("MORENOISE\nNOISE\n", outf.getvalue())