1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 from qm.fields import TextField
21 from qm.test.expectation_database import ExpectationDatabase
22 from qm.test.result import Result
23 from qm.test.base import load_results
24 from qm.xmlutil import *
25 import re
26
27
28
29
30
32 """An 'XMLExpectationDatabase' reads expectations from
33 an XML file."""
34
35 file_name = TextField()
36
37
39
40 super(XMLExpectationDatabase, self).__init__(**args)
41 self._expectations = []
42 document = load_xml(open(self.file_name))
43 root = document.documentElement
44 for e in root.getElementsByTagName('expectation'):
45 test_id = e.getAttribute('test_id')
46 outcome = {'pass':Result.PASS,
47 'fail':Result.FAIL,}[e.getAttribute('outcome')]
48 filters = {}
49 for a in e.getElementsByTagName('annotation'):
50 filters[a.getAttribute('name')] = a.getAttribute('value')
51 description = e.getElementsByTagName('description')
52 if description: description = get_dom_text(description[0])
53 self._expectations.append((test_id, outcome, filters, description))
54
55
57
58
59 outcome, description = Result.PASS, ''
60 for rule_id, rule_outcome, rule_annotations, rule_description in self._expectations:
61 if re.match(rule_id, test_id):
62 match = True
63 for a in rule_annotations.iteritems():
64 if (a[0] not in self.testrun_parameters or
65 not re.match(a[1], self.testrun_parameters[a[0]])):
66 match = False
67 if match:
68 outcome = rule_outcome
69 description = rule_description
70 return Result(Result.TEST, test_id, outcome,
71 annotations={'description':description})
72