All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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 
8 
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 = path
25 
26  tree = ET.parse(path)
27  for child in tree.getroot():
28  name = child.attrib['name']
29  if hasattr(self, name):
30  log.debug('setting %s', name)
31  value = child[0]
32  if name in ('args', 'unsupported_platforms'):
33  setattr(self, name, [el.text
34  for el in value.findall('text')])
35  elif name == 'environment':
36  setattr(self, name, dict(el.text.split('=', 1)
37  for el in value.findall('text')))
38  else:
39  data = value.text
40  if data is not None:
41  if value.tag == 'integer':
42  data = int(data)
43  setattr(self, name, data)
44 
45 
46  def ValidateOutput(self, stdout, stderr, result):
47  if self.validator:
48  class CallWrapper(object):
49  """
50  Small wrapper class to dynamically bind some default arguments
51  to a callable.
52  """
53  def __init__(self, callable, extra_args = {}):
54  self.callable = callable
55  self.extra_args = extra_args
56  # get the list of names of positional arguments
57  from inspect import getargspec
58  self.args_order = getargspec(callable)[0]
59  # Remove "self" from the list of positional arguments
60  # since it is added automatically
61  if self.args_order[0] == "self":
62  del self.args_order[0]
63  def __call__(self, *args, **kwargs):
64  # Check which positional arguments are used
65  positional = self.args_order[:len(args)]
66 
67  kwargs = dict(kwargs) # copy the arguments dictionary
68  for a in self.extra_args:
69  # use "extra_args" for the arguments not specified as
70  # positional or keyword
71  if a not in positional and a not in kwargs:
72  kwargs[a] = self.extra_args[a]
73  return apply(self.callable, args, kwargs)
74 
75  # local names to be exposed in the script
76  exported_symbols = {"self":self,
77  "stdout":stdout,
78  "stderr":stderr,
79  "result":result,
80  "causes":self.causes,
81  "findReferenceBlock":
82  CallWrapper(self.findReferenceBlock, {"stdout":stdout,
83  "result":result,
84  "causes":self.causes}),
85  "validateWithReference":
86  CallWrapper(self.validateWithReference, {"stdout":stdout,
87  "stderr":stderr,
88  "result":result,
89  "causes":self.causes}),
90  "countErrorLines":
91  CallWrapper(self.countErrorLines, {"stdout":stdout,
92  "result":result,
93  "causes":self.causes}),
94  "checkTTreesSummaries":
95  CallWrapper(self.CheckTTreesSummaries, {"stdout":stdout,
96  "result":result,
97  "causes":self.causes}),
98  "checkHistosSummaries":
99  CallWrapper(self.CheckHistosSummaries, {"stdout":stdout,
100  "result":result,
101  "causes":self.causes})
102  }
103  #print self.validator
104  exec self.validator in globals(), exported_symbols
105  else:
106  if self.stderr == '':
107  self.validateWithReference(stdout, stderr, result, self.causes)
108  elif stderr.strip() != self.stderr.strip():
109  self.causes.append('standard error')
110 
111  return result, self.causes
def XMLParser(self, path)
Definition: QMTTest.py:15
def validateWithReference(self, stdout=None, stderr=None, result=None, causes=None, preproc=None)
Definition: BaseTest.py:424
def ValidateOutput(self, stdout, stderr, result)
Definition: QMTTest.py:46
def __init__(self, path=None)
Definition: QMTTest.py:9
def findReferenceBlock(self, reference=None, stdout=None, result=None, causes=None, signature_offset=0, signature=None, id=None)
Definition: BaseTest.py:271
def CheckHistosSummaries(self, stdout=None, result=None, causes=None, dict=None, ignore=None)
Definition: BaseTest.py:387
def CheckTTreesSummaries(self, stdout=None, result=None, causes=None, trees_dict=None, ignore=r"Basket|.*size|Compression")
Definition: BaseTest.py:350