Belle II Software  release-08-01-10
local_database_file.py
1 #!/usr/bin/env python3
2 
3 
10 
11 # this is a test executable, not a module so we don't need doxygen warnings
12 # @cond SUPPRESS_DOXYGEN
13 
14 """
15 test parsing of local database files
16 """
17 
18 from basf2 import logging, LogLevel, LogInfo
19 from conditions_db.testing_payloads import parse_testing_payloads_file
20 from b2test_utils import clean_working_directory, run_in_subprocess, configure_logging_for_tests
21 import ROOT
22 
23 ROOT.gInterpreter.Declare("#include <framework/database/TestingPayloadStorage.h>")
24 
25 
26 entries = """
27 dbstore/empty 1 -1,-1,-1,-1
28 dbstore/good 1 0,0,-1,-1
29 dbstore/good_tabs\t1\t0,0,-1,-1
30 dbstore/good_many_spaces 1\t\t\t\t\t\t\t0,1,2,3
31 dbstore/good_with_comment 1 0,1,2,3 # comment
32 dbstory/good_with_md5 0123456789ABCDEF 0,1,2,3
33 dbstore/no_revision 0,1,2,3
34 no_package 1 0,0,-1,-1
35 dbstore/no_iov 1
36 dbstore/iov_only_1 1 0
37 dbstore/iov_only_2 1 0,0
38 dbstore/iov_only_3 1 0,0,0
39 dbstore/bad_with_spaces_02 1 0 ,1,2,3
40 dbstore/bad_with_spaces_11 1 0, 1,2,3
41 dbstore/bad_with_spaces_12 1 0,1 ,2,3
42 dbstore/bad_with_spaces_21 1 0,1, 2,3
43 dbstore/bad_with_spaces_22 1 0,1,2 ,3
44 dbstore/bad_with_spaces_31 1 0,1,2, 3
45 dbstore/bad_text_exp1 1 exp1,0,0,0
46 dbstore/bad_text_run1 1 0,run1,0,0
47 dbstore/bad_text_exp2 1 0,0,exp2,0
48 dbstore/bad_text_run2 1 0,0,0,run2
49 #only comment
50  # and with whitespace
51 \t#including tabs
52 """
53 
54 # modify logging to remove the useless module: lines
55 for level in LogLevel.values.values():
56  logging.set_info(level, LogInfo.LEVEL | LogInfo.MESSAGE)
57 
58 logging.enable_summary(False)
59 logging.log_level = LogLevel.DEBUG
60 logging.debug_level = 39
61 evt = ROOT.Belle2.EventMetaData(0, 0, 0)
62 payload = ROOT.Belle2.Conditions.PayloadMetadata("test")
63 
64 with clean_working_directory():
65  configure_logging_for_tests()
66  for i, entry in enumerate(entries.splitlines(True)):
67  print("testing", repr(entry))
68  filename = "database-%02d.txt" % i
69  with open(filename, "w") as f:
70  f.write(entry)
71 
72  # parse in python
73  entries = parse_testing_payloads_file(filename, check_existing=False)
74  if entries:
75  print(entries)
76  # and parse in C++
77  storage = ROOT.Belle2.Conditions.TestingPayloadStorage(filename)
78  run_in_subprocess(evt, payload, target=storage.get)
79 
80 # @endcond