1 # testlist.py -- Test list
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 """Selftest test list management."""
22 __all__ = ['find_in_list', 'read_test_regexes', 'read_testlist']
26 def find_in_list(list, fullname):
29 :param list: List with 2-tuples with regex and reason
31 for (regex, reason) in list:
32 if re.match(regex, fullname):
33 if reason is not None:
40 def read_test_regexes(f):
41 """Read tuples with regular expression and optional string from a file.
43 :param f: File-like object to read from
44 :return: Iterator over tuples with regular expression and test name
46 for l in f.readlines():
51 (test, reason) = l.split("#", 1)
55 yield test.strip(), reason.strip()
58 def should_run_test(tests, name):
62 if re.match(test, name):
67 def read_testlist(inf, outf):
68 """Read a list of tests from a file.
70 :param inf: File-like object to read from.
71 :param outf: File-like object to write to.
72 :return: Iterator over tuples describing tests
78 if l.startswith("-- TEST") and l.endswith(" --\n"):
79 supports_loadlist = l.startswith("-- TEST-LOADLIST")
80 supports_idlist = l.startswith("-- TEST-IDLIST")
81 name = inf.readline().rstrip("\n")
82 env = inf.readline().rstrip("\n")
83 cmdline = inf.readline().rstrip("\n")
84 yield (name, env, cmdline, supports_loadlist, supports_idlist)
89 def read_restricted_test_list(f):
90 for l in f.readlines():
94 class RestrictedTestManager(object):
95 """Test manager which can filter individual tests that should be run."""
97 def __init__(self, test_list):
98 self.test_list = test_list
99 self.unused = set(self.test_list)
102 def from_path(cls, path):
105 return cls(read_restricted_test_list(f))
109 def should_run_testsuite(self, name):
110 """Determine whether a testsuite should be run.
112 :param name: Name of the testsuite
113 :return: None if full testsuite should be run,
114 a list of subtests to run or [] if it should
118 for r in self.test_list:
122 self.unused.remove(r)
123 elif r.startswith(name + "."):
124 if match is not None:
125 match.append(r[len(name+"."):])
127 self.unused.remove(r)
130 def iter_unused(self):
131 """Iterate over entry entries that were unused.
133 :return: Iterator over test list entries that were not used.
135 return iter(self.unused)