Belle II Software  release-06-02-00
test_globaltag_forwarding.py
1 #!/usr/bin/env python3
2 
3 
10 
11 # Test that globaltags are forwarded correclty to the output file even if the
12 # database isn't used (BII-5790)
13 
14 import basf2
15 import b2test_utils
16 from ROOT import Belle2
17 import json
18 import unittest
19 
20 
21 class TestGTForwarding(unittest.TestCase):
22  """Test that we forward globaltags correctly"""
23  def test_it(self):
24  """Only one test here ..."""
25  inputfile = b2test_utils.require_file("mdst12.root", "validation", self)
26  metadata = basf2.get_file_metadata(inputfile)
27  inputtags = metadata.getDatabaseGlobalTag()
28  self.assertNotEqual(inputtags, "")
29 
31  basf2.conditions.globaltags = ["A", "B", "C", "A", "B", "C", "C", "A"]
32  Belle2.MetadataService.Instance().setJsonFileName("info.json")
33  p = basf2.Path()
34  p.add_module("RootInput", inputFileName=inputfile)
35  p.add_module("RootOutput", outputFileName="test.root")
36  basf2.process(p, 3)
37  with open("info.json") as jobinfo:
38  data = json.load(jobinfo)
39 
40  self.assertIn('output_files', data, "Expecting output file info")
41  self.assertEqual(len(data['output_files']), 1, "Expecting exactly one output file")
42  fileinfo = data['output_files'][0]
43  # FIXME: Once we get rid of the legacy ip globaltag this will get nicer
44  self.assertEqual(fileinfo['metadata']['globalTag'], f"A,B,C,{inputtags},Legacy_IP_Information",
45  "Globaltags not forwarded correctly")
46  self.assertEqual(fileinfo['stats']['events'], 3, "Number of events is wrong")
47 
48 
49 if __name__ == '__main__':
50  unittest.main()
static MetadataService & Instance()
Static method to get a reference to the MetadataService instance.
def require_file(filename, data_type="", py_case=None)
Definition: __init__.py:54
def clean_working_directory()
Definition: __init__.py:185