Belle II Software development
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"""
15test parsing of local database files
16"""
17
18from basf2 import logging, LogLevel, LogInfo
19from conditions_db.testing_payloads import parse_testing_payloads_file
20from b2test_utils import clean_working_directory, run_in_subprocess, configure_logging_for_tests
21import ROOT
22
23ROOT.gInterpreter.Declare("#include <framework/database/TestingPayloadStorage.h>")
24
25
26entries = """
27dbstore/empty 1 -1,-1,-1,-1
28dbstore/good 1 0,0,-1,-1
29dbstore/good_tabs\t1\t0,0,-1,-1
30dbstore/good_many_spaces 1\t\t\t\t\t\t\t0,1,2,3
31dbstore/good_with_comment 1 0,1,2,3 # comment
32dbstory/good_with_md5 0123456789ABCDEF 0,1,2,3
33dbstore/no_revision 0,1,2,3
34no_package 1 0,0,-1,-1
35dbstore/no_iov 1
36dbstore/iov_only_1 1 0
37dbstore/iov_only_2 1 0,0
38dbstore/iov_only_3 1 0,0,0
39dbstore/bad_with_spaces_02 1 0 ,1,2,3
40dbstore/bad_with_spaces_11 1 0, 1,2,3
41dbstore/bad_with_spaces_12 1 0,1 ,2,3
42dbstore/bad_with_spaces_21 1 0,1, 2,3
43dbstore/bad_with_spaces_22 1 0,1,2 ,3
44dbstore/bad_with_spaces_31 1 0,1,2, 3
45dbstore/bad_text_exp1 1 exp1,0,0,0
46dbstore/bad_text_run1 1 0,run1,0,0
47dbstore/bad_text_exp2 1 0,0,exp2,0
48dbstore/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
55for level in LogLevel.values.values():
56 logging.set_info(level, LogInfo.LEVEL | LogInfo.MESSAGE)
57
58logging.enable_summary(False)
59logging.log_level = LogLevel.DEBUG
60logging.debug_level = 39
61evt = ROOT.Belle2.EventMetaData(0, 0, 0)
62payload = ROOT.Belle2.Conditions.PayloadMetadata("test")
63
64with clean_working_directory():
65 configure_logging_for_tests()
66 for i, entry in enumerate(entries.splitlines(True)):
67 print("testing", repr(entry))
68 filename = f"database-{i:02}.txt"
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