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

« back to all changes in this revision

Viewing changes to plugins/suites_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
 
22
 
 
23
from checkbox.job import JobIterator
 
24
from checkbox.properties import List, Path, String
 
25
from checkbox.plugin import Plugin
 
26
 
 
27
from gettext import gettext as _
 
28
 
 
29
 
 
30
class SuitesPrompt(Plugin):
 
31
 
 
32
    # Plugin default for running suite types
 
33
    plugin_default = String(default="external")
 
34
 
 
35
    # Plugin priorities for running suites
 
36
    plugin_priorities = List(String(), default_factory=lambda:"internal")
 
37
 
 
38
    # Space separated list of directories where suite files are stored.
 
39
    directories = List(Path(),
 
40
        default_factory=lambda:"%(checkbox_share)s/suites")
 
41
 
 
42
    # List of suites to blacklist
 
43
    blacklist = List(String(), default_factory=lambda:"")
 
44
 
 
45
    # List of suites to whitelist
 
46
    whitelist = List(String(), default_factory=lambda:"")
 
47
 
 
48
    def _suites_compare(self, a, b):
 
49
        priorities = self.plugin_priorities
 
50
        if a["plugin"] in priorities:
 
51
            if b["plugin"] in priorities:
 
52
                ia = priorities.index(a["plugin"])
 
53
                ib = priorities.index(b["plugin"])
 
54
                if ia != ib:
 
55
                    return cmp(ia, ib)
 
56
            else:
 
57
                return -1
 
58
        elif b["plugin"] in priorities:
 
59
            return 1
 
60
 
 
61
        return cmp(a["name"], b["name"])
 
62
 
 
63
    def _suites_exclude(self, suite):
 
64
        whitelist_patterns = [re.compile(r"^%s$" % r) for r in self.whitelist if r]
 
65
        blacklist_patterns = [re.compile(r"^%s$" % r) for r in self.blacklist if r]
 
66
 
 
67
        name = suite["name"]
 
68
        if whitelist_patterns:
 
69
            if not [name for p in whitelist_patterns if p.match(name)]:
 
70
                return True
 
71
        elif blacklist_patterns:
 
72
            if [name for p in blacklist_patterns if p.match(name)]:
 
73
                return True
 
74
 
 
75
        suites_ignore = self.persist.get("ignore", [])
 
76
        if suite["description"] in suites_ignore:
 
77
            return True
 
78
 
 
79
        return False
 
80
 
 
81
    def register(self, manager):
 
82
        super(SuitesPrompt, self).register(manager)
 
83
        self._iterator = None
 
84
        self._suite = None
 
85
        self._suites = {}
 
86
 
 
87
        for (rt, rh) in [
 
88
             ("gather", self.gather),
 
89
             ("gather-persist", self.gather_persist),
 
90
             ("report-suite", self.report_suite),
 
91
             ("prompt-suite", self.prompt_suite),
 
92
             ("prompt-suites", self.prompt_suites)]:
 
93
            self._manager.reactor.call_on(rt, rh)
 
94
 
 
95
        self._manager.reactor.call_on("prompt-gather", self.prompt_gather, 100)
 
96
        self._manager.reactor.call_on("report-(attachment|test)",
 
97
            self.report_attachment_or_test, -100)
 
98
 
 
99
    def gather(self):
 
100
        for directory in self.directories:
 
101
            self._manager.reactor.fire("message-directory", directory)
 
102
 
 
103
    def gather_persist(self, persist):
 
104
        self.persist = persist.root_at("suites_prompt")
 
105
 
 
106
    def report_attachment_or_test(self, element):
 
107
        if self._suite:
 
108
            element.setdefault("suite", self._suite["name"])
 
109
 
 
110
    def report_suite(self, suite):
 
111
        key = suite["name"]
 
112
        if key not in self._suites:
 
113
            suite.setdefault("plugin", self.plugin_default)
 
114
            self._suites[key] = suite
 
115
            self._iterator = JobIterator(self._suites.values(),
 
116
                self._manager.registry, self._suites_compare)
 
117
            self._iterator = IteratorExclude(self._iterator,
 
118
                self._suites_exclude, self._suites_exclude)
 
119
            if self._suite:
 
120
                for suite in self._iterator:
 
121
                    if suite == self._suite:
 
122
                        break
 
123
 
 
124
    def prompt_gather(self, interface):
 
125
        suites = self._suites.values()
 
126
        if len(suites) > 1:
 
127
            suites_all = set([s["description"] for s in suites])
 
128
            suites_ignore = set(self.persist.get("ignore", []))
 
129
            suites_default = suites_all.difference(suites_ignore)
 
130
            suites_default = set(interface.show_check(
 
131
                _("Select the suites to test"),
 
132
                sorted(suites_all), suites_default))
 
133
            suites_ignore = suites_all.difference(suites_default)
 
134
            self.persist.set("ignore", list(suites_ignore))
 
135
 
 
136
    def prompt_suite(self, interface, suite):
 
137
        self._manager.reactor.fire("prompt-%s" % suite["plugin"],
 
138
            interface, suite)
 
139
 
 
140
    def prompt_suites(self, interface):
 
141
        while True:
 
142
            try:
 
143
                self._suite = self._iterator.go(interface.direction)
 
144
            except StopIteration:
 
145
                break
 
146
 
 
147
            self._manager.reactor.fire("prompt-suite", interface, self._suite)
 
148
 
 
149
 
 
150
factory = SuitesPrompt