~roadmr/ubuntu/oneiric/checkbox/fix-662322-in-0.12.9

« back to all changes in this revision

Viewing changes to plugins/tests_prompt.py

  • Committer: Bazaar Package Importer
  • Author(s): Marc Tardif, Gabor Keleman
  • Date: 2009-08-19 15:36:05 UTC
  • Revision ID: james.westby@ubuntu.com-20090819153605-weo6htup3yi6zn0t
Tags: 0.8~alpha4
* New upstream version:
  * Changed icon.
  * Added timeout property to lock_prompt plugin.
  * Added concept of attachments to tests.
  * Added support for backslahes in templates to wrap lines.
  * Added support blacklisting and whitelisting both tests and suites.
  * Introduced the concept of jobs for suites, tests and attachments.
  * Removed upstart event which is no longer needed.
  * Replaced architecture and category with requires in test definitions.
* Fixed pygst dependency (LP: #334442)
* Fixed configuration file updates during install (LP: #330596)
* Fixed and expanded translations (LP: #347038)
* Fixed ignored system proxy settings (LP: #345548)
* Fixed parsing blank lines in templates (LP: #393907)
* Fixed escaping of lists (LP: #394001)
* Fixed timeout in manual tests (LP: #377986)
* Fixed CLI interface dialog.
* Fixed support for FreeDesktop XDG base directory specification (LP: #363549)
* Added general and package specific apport hooks

[ Gabor Keleman ]
* Fixed untranslated strings in tests (LP: #374666)
* Fixed untranslated last screen (LP: #374646)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#
 
2
# This file is part of Checkbox.
 
3
#
 
4
# Copyright 2008 Canonical Ltd.
 
5
#
 
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.
 
10
#
 
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.
 
15
#
 
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/>.
 
18
#
 
19
import re
 
20
 
 
21
from checkbox.lib.iterator import IteratorExclude, PREV
 
22
 
 
23
from checkbox.job import JobIterator, UNINITIATED
 
24
from checkbox.plugin import Plugin
 
25
from checkbox.properties import List, String
 
26
 
 
27
 
 
28
class TestsPrompt(Plugin):
 
29
 
 
30
    # List of suites to blacklist
 
31
    blacklist = List(String(), default_factory=lambda:"")
 
32
 
 
33
    # List of suites to whitelist
 
34
    whitelist = List(String(), default_factory=lambda:"")
 
35
 
 
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]
 
39
 
 
40
        name = test["name"]
 
41
        if whitelist_patterns:
 
42
            if not [name for p in whitelist_patterns if p.match(name)]:
 
43
                return True
 
44
        elif blacklist_patterns:
 
45
            if [name for p in blacklist_patterns if p.match(name)]:
 
46
                return True
 
47
 
 
48
        return False
 
49
 
 
50
    def register(self, manager):
 
51
        super(TestsPrompt, self).register(manager)
 
52
        self._iterator = None
 
53
        self._keys = []
 
54
        self._tests = {}
 
55
 
 
56
        for (rt, rh) in [
 
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)
 
62
 
 
63
        self._manager.reactor.call_on("prompt-suite", self.prompt_suite, -100)
 
64
 
 
65
    def prompt_suite(self, interface, suite):
 
66
        self._iterator = None
 
67
        self._keys = []
 
68
 
 
69
    def report(self):
 
70
        self._manager.reactor.fire("report-tests", self._tests.values())
 
71
 
 
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
 
78
 
 
79
    def prompt_test(self, interface, test):
 
80
        self._manager.reactor.fire("prompt-%s" % test["plugin"],
 
81
            interface, test)
 
82
 
 
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()
 
92
 
 
93
        while True:
 
94
            try:
 
95
                test = self._iterator.go(interface.direction)
 
96
            except StopIteration:
 
97
                break
 
98
 
 
99
            self._manager.reactor.fire("prompt-test", interface, test)
 
100
 
 
101
 
 
102
factory = TestsPrompt