Belle II Software light-2406-ragdoll
logsummary.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 if the log summary is shown correctly in all cases
16"""
17
18from basf2 import create_path, process, Module, logging, LogLevel, LogInfo, \
19 B2WARNING, B2FATAL, B2ERROR
20import multiprocessing
21
22
23def fork_process(*args, target=process):
24 """Run function in forked child to eliminate side effects"""
25 sub = multiprocessing.Process(target=target, args=args)
26 sub.start()
27 sub.join()
28
29
30class FatalError(Module):
31 """Simple module to just print a warning, an error and a fatal error"""
32
33 def event(self):
34 """print messages"""
35 B2WARNING("warning")
36 B2ERROR("error")
37 B2FATAL("fatal error")
38
39
40logging.log_level = LogLevel.WARNING
41for level in LogLevel.values.values():
42 logging.set_info(level, LogInfo.LEVEL | LogInfo.MODULE | LogInfo.PACKAGE | LogInfo.MESSAGE)
43
44main = create_path()
45main.add_module("EventInfoSetter")
46module = main.add_module(FatalError())
47
48print("run in default settings")
49fork_process(main)
50
51print("run with no warnings")
52logging.log_level = LogLevel.ERROR
53fork_process(main)
54logging.log_level = LogLevel.WARNING
55
56print("run with no framework warnings")
57logging.package("framework").log_level = LogLevel.ERROR
58fork_process(main)
59logging.package("framework").log_level = LogLevel.WARNING
60
61print("run with no module warnings")
62module.set_log_level(LogLevel.ERROR)
63fork_process(main)
64module.set_log_level(LogLevel.WARNING)
65
66print("run without summary")
67logging.enable_summary(False)
68fork_process(main)
69
70# @endcond