selftest.testlist: Add read_testlist.
[sharpe/samba-autobuild/.git] / selftest / tests / test_testlist.py
1 # test_testlist.py -- The tests for selftest testlist code
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.testlist."""
21
22 from selftest.testlist import (
23     find_in_list,
24     read_test_regexes,
25     read_testlist,
26     )
27
28 from cStringIO import StringIO
29
30 import unittest
31
32
33 class FindInListTests(unittest.TestCase):
34
35     def test_empty(self):
36         self.assertIs(None, find_in_list([], "foo.test"))
37
38     def test_no_reason(self):
39         self.assertEquals("because",
40             find_in_list([("foo.*bar", "because")], "foo.bla.bar"))
41
42
43 class ReadTestRegexesTests(unittest.TestCase):
44
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)))
48
49     def test_no_reason(self):
50         f = StringIO(" foo\n")
51         self.assertEquals([("foo", None)], list(read_test_regexes(f)))
52
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)))
57
58
59 class ReadTestlistTests(unittest.TestCase):
60
61     def test_read_list(self):
62         inf = StringIO("-- TEST --\nfoo\nbar\nbla\n")
63         outf = StringIO()
64         self.assertEquals([('foo', 'bar', 'bla', False, False)],
65                 list(read_testlist(inf, outf)))
66         self.assertEquals("", outf.getvalue())
67
68     def test_read_list_passes_through(self):
69         inf = StringIO("MORENOISE\n-- TEST --\nfoo\nbar\nbla\nNOISE\n")
70         outf = StringIO()
71         self.assertEquals([('foo', 'bar', 'bla', False, False)],
72                 list(read_testlist(inf, outf)))
73         self.assertEquals("MORENOISE\nNOISE\n", outf.getvalue())