2
# This file is part of Checkbox.
4
# Copyright 2008 Canonical Ltd.
6
# Checkbox is free software: you can redistribute it and/or modify
7
# it under the terms of the GNU General Public License as published by
8
# the Free Software Foundation, either version 3 of the License, or
9
# (at your option) any later version.
11
# Checkbox is distributed in the hope that it will be useful,
12
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
# GNU General Public License for more details.
16
# You should have received a copy of the GNU General Public License
17
# along with Checkbox. If not, see <http://www.gnu.org/licenses/>.
21
from checkbox.lib.iterator import IteratorExclude, PREV
23
from checkbox.job import JobIterator, UNINITIATED
24
from checkbox.plugin import Plugin
25
from checkbox.properties import List, String
28
class TestsPrompt(Plugin):
30
# List of suites to blacklist
31
blacklist = List(String(), default_factory=lambda:"")
33
# List of suites to whitelist
34
whitelist = List(String(), default_factory=lambda:"")
36
def _tests_exclude(self, test):
37
whitelist_patterns = [re.compile(r"^%s$" % r) for r in self.whitelist if r]
38
blacklist_patterns = [re.compile(r"^%s$" % r) for r in self.blacklist if r]
41
if whitelist_patterns:
42
if not [name for p in whitelist_patterns if p.match(name)]:
44
elif blacklist_patterns:
45
if [name for p in blacklist_patterns if p.match(name)]:
50
def register(self, manager):
51
super(TestsPrompt, self).register(manager)
57
("report", self.report),
58
("report-test", self.report_test),
59
("prompt-test", self.prompt_test),
60
("prompt-tests", self.prompt_tests)]:
61
self._manager.reactor.call_on(rt, rh)
63
self._manager.reactor.call_on("prompt-suite", self.prompt_suite, -100)
65
def prompt_suite(self, interface, suite):
70
self._manager.reactor.fire("report-tests", self._tests.values())
72
def report_test(self, test):
73
key = (test["suite"], test["name"],)
74
self._keys.append(key)
75
if key not in self._tests:
76
test.setdefault("status", UNINITIATED)
77
self._tests[key] = test
79
def prompt_test(self, interface, test):
80
self._manager.reactor.fire("prompt-%s" % test["plugin"],
83
def prompt_tests(self, interface, blacklist=[], whitelist=[]):
84
# TODO: blacklist and whitelist are being ignored
85
if not self._iterator:
86
tests = [self._tests[k] for k in self._keys]
87
self._iterator = JobIterator(tests, self._manager.registry)
88
self._iterator = IteratorExclude(self._iterator,
89
self._tests_exclude, self._tests_exclude)
90
if interface.direction == PREV:
91
self._iterator = self._iterator.last()
95
test = self._iterator.go(interface.direction)
99
self._manager.reactor.fire("prompt-test", interface, test)
102
factory = TestsPrompt