The Gaudi Framework  master (37c0b60a)
QMTTest.py
Go to the documentation of this file.
1 
11 import logging
12 import os
13 
14 from GaudiTesting.BaseTest import * # noqa: F401 F403 (to bring validators into scope)
15 from GaudiTesting.BaseTest import BaseTest
16 
17 
19  def __init__(self, path=None):
20  BaseTest.__init__(self)
21  self.validator = ""
22  if path:
23  self.XMLParser(path)
24 
25  def XMLParser(self, path):
26  """
27  Parse a QMTest XML test description (.qmt file) to initialize the test
28  instance.
29  """
30  from string import Template
31 
32  log = logging.getLogger("QMTest.XMLParser")
33  import xml.etree.ElementTree as ET
34 
35  log.debug("parsing %s", path)
36 
37  self.name = ".".join(
38  os.path.relpath(path, self.basedir)
39  .replace(".qmt", "")
40  .replace(".qms", "")
41  .split(os.sep)
42  )
43 
44  tree = ET.parse(path)
45  for child in tree.getroot():
46  name = child.attrib["name"]
47  if hasattr(self, name):
48  log.debug("setting %s", name)
49  value = child[0]
50  if name in ("args", "unsupported_platforms"):
51  setattr(self, name, [el.text for el in value.findall("text")])
52  elif name == "environment":
53  for el in value.findall("text"):
54  key, value = el.text.split("=", 1)
55  self.environment[key] = Template(value).safe_substitute(
56  self.environment
57  )
58  else:
59  data = value.text
60  if data is not None:
61  if value.tag == "integer":
62  data = int(data)
63  setattr(self, name, data)
64 
65  def ValidateOutput(self, stdout, stderr, result):
66  if self.validator:
67 
68  class CallWrapper(object):
69  """
70  Small wrapper class to dynamically bind some default arguments
71  to a callable.
72  """
73 
74  def __init__(self, callable, extra_args={}):
75  self.callable = callable
76  self.extra_args = extra_args
77  # get the list of names of positional arguments
78  try:
79  # Removed in Python 3.11
80  from inspect import getargspec
81 
82  self.args_order = getargspec(callable)[0]
83  except ImportError:
84  import inspect
85 
86  self.args_order = [
87  param.name
88  for param in inspect.signature(callable).parameters.values()
89  if param.kind == inspect.Parameter.POSITIONAL_OR_KEYWORD
90  ]
91  # Remove "self" from the list of positional arguments
92  # since it is added automatically
93  if self.args_order[0] == "self":
94  del self.args_order[0]
95 
96  def __call__(self, *args, **kwargs):
97  # Check which positional arguments are used
98  positional = self.args_order[: len(args)]
99 
100  kwargs = dict(kwargs) # copy the arguments dictionary
101  for a in self.extra_args:
102  # use "extra_args" for the arguments not specified as
103  # positional or keyword
104  if a not in positional and a not in kwargs:
105  kwargs[a] = self.extra_args[a]
106  return self.callable(*args, **kwargs)
107 
108  # local names to be exposed in the script
109  stdout_ref = self._expandReferenceFileName(self.reference)
110  stderr_ref = self._expandReferenceFileName(self.error_reference)
111  exported_symbols = {
112  "self": self,
113  "stdout": stdout,
114  "stderr": stderr,
115  "result": result,
116  "causes": self.causes,
117  "reference": stdout_ref,
118  "error_reference": stderr_ref,
119  "findReferenceBlock": CallWrapper(
120  self.findReferenceBlock,
121  {"stdout": stdout, "result": result, "causes": self.causes},
122  ),
123  "validateWithReference": CallWrapper(
125  {
126  "stdout": stdout,
127  "stderr": stderr,
128  "result": result,
129  "causes": self.causes,
130  },
131  ),
132  "validateJSONWithReference": CallWrapper(
134  {
135  "result": result,
136  "causes": self.causes,
137  },
138  ),
139  "countErrorLines": CallWrapper(
140  self.countErrorLines,
141  {"stdout": stdout, "result": result, "causes": self.causes},
142  ),
143  "checkTTreesSummaries": CallWrapper(
145  {"stdout": stdout, "result": result, "causes": self.causes},
146  ),
147  "checkHistosSummaries": CallWrapper(
149  {"stdout": stdout, "result": result, "causes": self.causes},
150  ),
151  }
152  # print self.validator
153  exec(self.validator, globals(), exported_symbols)
154  return result, self.causes
155  else:
156  return super(QMTTest, self).ValidateOutput(stdout, stderr, result)
GaudiTesting.BaseTest.BaseTest.causes
causes
Definition: BaseTest.py:122
GaudiTesting.BaseTest.BaseTest.CheckHistosSummaries
def CheckHistosSummaries(self, stdout=None, result=None, causes=None, dict=None, ignore=None)
Definition: BaseTest.py:542
GaudiTesting.BaseTest.BaseTest.reference
reference
Definition: BaseTest.py:108
GaudiTesting.BaseTest.BaseTest.validateWithReference
def validateWithReference(self, stdout=None, stderr=None, result=None, causes=None, preproc=None)
Definition: BaseTest.py:584
GaudiTesting.BaseTest.BaseTest.environment
environment
Definition: BaseTest.py:114
GaudiTesting.BaseTest.BaseTest.validateJSONWithReference
def validateJSONWithReference(self, output_file, reference_file, result=None, causes=None, detailed=True)
Definition: BaseTest.py:667
GaudiTesting.QMTTest.QMTTest
Definition: QMTTest.py:18
GaudiTesting.QMTTest.QMTTest.ValidateOutput
def ValidateOutput(self, stdout, stderr, result)
Definition: QMTTest.py:65
GaudiTesting.BaseTest.BaseTest.basedir
basedir
Definition: BaseTest.py:129
GaudiTesting.QMTTest.QMTTest.extra_args
extra_args
Definition: QMTTest.py:76
GaudiTesting.BaseTest.BaseTest.name
name
Definition: BaseTest.py:121
GaudiTesting.QMTTest.QMTTest.validator
validator
Definition: QMTTest.py:21
GaudiTesting.BaseTest.BaseTest._expandReferenceFileName
def _expandReferenceFileName(self, reffile)
Definition: BaseTest.py:721
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:395
GaudiTesting.QMTTest.QMTTest.callable
callable
Definition: QMTTest.py:75
GaudiTesting.BaseTest
Definition: BaseTest.py:1
GaudiTesting.BaseTest.BaseTest.CheckTTreesSummaries
def CheckTTreesSummaries(self, stdout=None, result=None, causes=None, trees_dict=None, ignore=r"Basket|.*size|Compression")
Definition: BaseTest.py:496
GaudiTesting.BaseTest.BaseTest
Definition: BaseTest.py:102
GaudiTesting.BaseTest.BaseTest.countErrorLines
def countErrorLines(self, expected={"ERROR":0, "FATAL":0}, stdout=None, result=None, causes=None)
Definition: BaseTest.py:452
GaudiTesting.BaseTest.BaseTest.error_reference
error_reference
Definition: BaseTest.py:109
GaudiTesting.QMTTest.QMTTest.XMLParser
def XMLParser(self, path)
Definition: QMTTest.py:25
GaudiTesting.QMTTest.QMTTest.args_order
args_order
Definition: QMTTest.py:82
GaudiTesting.QMTTest.QMTTest.__init__
def __init__(self, path=None)
Definition: QMTTest.py:19