| The Gaudi Framework v32r1 (f65d50dc)

QMTTest.py
Go to the documentation of this file.
1 # -*- coding: utf-8 -*-
2 from BaseTest import *
3 import logging
4 import os
5 import sys
6
7
8 class QMTTest(BaseTest):
9 def __init__(self, path=None):
10 BaseTest.__init__(self)
11 self.validator = ''
12 if path:
13 self.XMLParser(path)
14
15 def XMLParser(self, path):
16 '''
17 Parse a QMTest XML test description (.qmt file) to initialize the test
18 instance.
19 '''
20 log = logging.getLogger('QMTest.XMLParser')
21 import xml.etree.ElementTree as ET
22 log.debug('parsing %s', path)
23
24 self.name = '.'.join(
25 os.path.relpath(path, self.basedir).replace('.qmt', '').replace(
26 '.qms', '').split(os.sep))
27
28 tree = ET.parse(path)
29 for child in tree.getroot():
30 name = child.attrib['name']
31 if hasattr(self, name):
32 log.debug('setting %s', name)
33 value = child[0]
34 if name in ('args', 'unsupported_platforms'):
35 setattr(self, name,
36 [el.text for el in value.findall('text')])
37 elif name == 'environment':
38 setattr(
39 self, name,
40 dict(
41 el.text.split('=', 1)
42 for el in value.findall('text')))
43 else:
44 data = value.text
45 if data is not None:
46 if value.tag == 'integer':
47 data = int(data)
48 setattr(self, name, data)
49
50 def ValidateOutput(self, stdout, stderr, result):
51 if self.validator:
52
53 class CallWrapper(object):
54 """
55 Small wrapper class to dynamically bind some default arguments
56 to a callable.
57 """
58
59 def __init__(self, callable, extra_args={}):
60 self.callable = callable
61 self.extra_args = extra_args
62 # get the list of names of positional arguments
63 from inspect import getargspec
64 self.args_order = getargspec(callable)[0]
65 # Remove "self" from the list of positional arguments
66 # since it is added automatically
67 if self.args_order[0] == "self":
68 del self.args_order[0]
69
70 def __call__(self, *args, **kwargs):
71 # Check which positional arguments are used
72 positional = self.args_order[:len(args)]
73
74 kwargs = dict(kwargs) # copy the arguments dictionary
75 for a in self.extra_args:
76 # use "extra_args" for the arguments not specified as
77 # positional or keyword
78 if a not in positional and a not in kwargs:
79 kwargs[a] = self.extra_args[a]
80 return self.callable(*args, **kwargs)
81
82 # local names to be exposed in the script
83 stdout_ref = self._expandReferenceFileName(self.reference)
84 stderr_ref = self._expandReferenceFileName(self.error_reference)
85 exported_symbols = {
86 "self":
87 self,
88 "stdout":
89 stdout,
90 "stderr":
91 stderr,
92 "result":
93 result,
94 "causes":
95 self.causes,
96 "reference":
97 stdout_ref,
98 "error_reference":
99 stderr_ref,
100 "findReferenceBlock":
101 CallWrapper(self.findReferenceBlock, {
102 "stdout": stdout,
103 "result": result,
104 "causes": self.causes
105 }),
106 "validateWithReference":
107 CallWrapper(
108 self.validateWithReference, {
109 "stdout": stdout,
110 "stderr": stderr,
111 "result": result,
112 "causes": self.causes
113 }),
114 "countErrorLines":
115 CallWrapper(self.countErrorLines, {
116 "stdout": stdout,
117 "result": result,
118 "causes": self.causes
119 }),
120 "checkTTreesSummaries":
121 CallWrapper(self.CheckTTreesSummaries, {
122 "stdout": stdout,
123 "result": result,
124 "causes": self.causes
125 }),
126 "checkHistosSummaries":
127 CallWrapper(self.CheckHistosSummaries, {
128 "stdout": stdout,
129 "result": result,
130 "causes": self.causes
131 })
132 }
133 # print self.validator
134 exec (self.validator, globals(), exported_symbols)
135 return result, self.causes
136 else:
137 return super(QMTTest, self).ValidateOutput(stdout, stderr, result)
GaudiTesting.BaseTest.BaseTest.basedir
basedir
Definition: BaseTest.py:95
GaudiTesting.QMTTest.QMTTest.args_order
args_order
Definition: QMTTest.py:64
GaudiTesting.QMTTest.QMTTest.XMLParser
def XMLParser(self, path)
Definition: QMTTest.py:15
GaudiTesting.BaseTest.BaseTest.validateWithReference
def validateWithReference(self, stdout=None, stderr=None, result=None, causes=None, preproc=None)
Definition: BaseTest.py:475
GaudiTesting.QMTTest.QMTTest.ValidateOutput
def ValidateOutput(self, stdout, stderr, result)
Definition: QMTTest.py:50
GaudiTesting.BaseTest.BaseTest
Definition: BaseTest.py:67
GaudiTesting.BaseTest.BaseTest.reference
reference
Definition: BaseTest.py:74
GaudiTesting.QMTTest.QMTTest.validator
validator
Definition: QMTTest.py:11
GaudiTesting.QMTTest.QMTTest
Definition: QMTTest.py:8
GaudiTesting.BaseTest.BaseTest.error_reference
error_reference
Definition: BaseTest.py:75
GaudiTesting.QMTTest.QMTTest.extra_args
extra_args
Definition: QMTTest.py:61
GaudiTesting.BaseTest.BaseTest.causes
causes
Definition: BaseTest.py:88
GaudiTesting.BaseTest.BaseTest.countErrorLines
def countErrorLines(self, expected={ 'ERROR':0, 'FATAL':0 }, stdout=None, result=None, causes=None)
Definition: BaseTest.py:337
GaudiTesting.QMTTest.QMTTest.__init__
def __init__(self, path=None)
Definition: QMTTest.py:9
GaudiTesting.BaseTest.BaseTest._expandReferenceFileName
def _expandReferenceFileName(self, reffile)
Definition: BaseTest.py:561
GaudiTesting.QMTTest.QMTTest.callable
callable
Definition: QMTTest.py:60
GaudiTesting.BaseTest.BaseTest.findReferenceBlock
def findReferenceBlock(self, reference=None, stdout=None, result=None, causes=None, signature_offset=0, signature=None, id=None)
Definition: BaseTest.py:281
GaudiTesting.BaseTest.BaseTest.CheckHistosSummaries
def CheckHistosSummaries(self, stdout=None, result=None, causes=None, dict=None, ignore=None)
Definition: BaseTest.py:430
GaudiTesting.BaseTest.BaseTest.CheckTTreesSummaries
def CheckTTreesSummaries(self, stdout=None, result=None, causes=None, trees_dict=None, ignore=r"Basket|.*size|Compression")
Definition: BaseTest.py:385
GaudiTesting.BaseTest.BaseTest.name
name
Definition: BaseTest.py:87