ATLAS Offline Software
DataQuality/DQUtils/python/tests.py
Go to the documentation of this file.
1 # Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
2 
3 from pickle import dump, loads
4 from functools import wraps
5 from os import environ
6 from pkg_resources import resource_string
7 
8 def invariant(test_data_name):
9  def wrapper(func):
10  testfile = "%s.%s" % (func.__name__, test_data_name)
11  @wraps(func)
12  def check_invariant(*args, **kwargs):
13  result = func(*args, **kwargs)
14  if "DQU_UPDATE_TEST_DATA" in environ:
15  with open(test_data_name, "wb") as fd:
16  dump(result, fd)
17  print("Wrote updated test data")
18  else:
19  test_data = loads(resource_string("testdata", testfile))
20  assert result == test_data, "Data considered 'invariant' has changed"
21  return check_invariant
22 
23  return wrapper
python.tests.invariant
def invariant(test_data_name)
Definition: DataQuality/DQUtils/python/tests.py:8
run_Egamma1_LArStrip_Fex.dump
dump
Definition: run_Egamma1_LArStrip_Fex.py:88
Trk::open
@ open
Definition: BinningType.h:40
dbg::print
void print(std::FILE *stream, std::format_string< Args... > fmt, Args &&... args)
Definition: SGImplSvc.cxx:70