The Gaudi Framework  master (594c33fa)
GaudiTesting.BaseTest.JSONOutputValidator Class Reference

Public Member Functions

def __call__ (self, ref, out, result, detailed=True)
 

Detailed Description

Definition at line 1542 of file BaseTest.py.

Member Function Documentation

◆ __call__()

def GaudiTesting.BaseTest.JSONOutputValidator.__call__ (   self,
  ref,
  out,
  result,
  detailed = True 
)
Validate JSON output.
returns -- A list of strings giving causes of failure.

Definition at line 1543 of file BaseTest.py.

1543  def __call__(self, ref, out, result, detailed=True):
1544  """Validate JSON output.
1545  returns -- A list of strings giving causes of failure."""
1546 
1547  causes = []
1548  try:
1549  with open(ref) as f:
1550  expected = json.load(f)
1551  except json.JSONDecodeError as err:
1552  causes.append("json parser error")
1553  result["reference_parse_error"] = f"json parser error in {ref}: {err}"
1554  return causes
1555 
1556  if not detailed:
1557  if expected != out:
1558  causes.append("json content")
1559  result["json_diff"] = "detailed diff was turned off"
1560  return causes
1561 
1562  # piggyback on TestCase dict diff report
1563  t = TestCase()
1564  # sort both lists (these are list of entities) as the order is not supposed to matter
1565  # indeed, the JSONSink implementation does not garantee any particular order
1566  # but as JSON does not have sets, we get back a sorted list here
1567  expected = sorted(expected, key=lambda item: (item["component"], item["name"]))
1568  out = sorted(out, key=lambda item: (item["component"], item["name"]))
1569  try:
1570  t.assertEqual(expected, out)
1571  except AssertionError as err:
1572  causes.append("json content")
1573  result["json_diff"] = str(err).splitlines()[0]
1574 
1575  return causes

The documentation for this class was generated from the following file: