Belle II Software development
stop_on_error.py
1#!/usr/bin/env python3
2
3
10
11import os
12import basf2
13
14basf2.set_random_seed("")
15
16
17class ErrorInInit(basf2.Module):
18 """test"""
19
20 def initialize(self):
21 """reimplementation of Module::initialize()."""
22 basf2.B2ERROR("In module " + self.name())
23
24
25class ErrorInEvent(basf2.Module):
26 """test"""
27
28 def event(self):
29 """reimplementation of Module::event()."""
30 # error level to check that this doesn't prevent execution
31 basf2.B2ERROR("In module " + self.name())
32
33
34noerrors = basf2.Path()
35noerrors.add_module('EventInfoSetter')
36
37# no errors at all
38basf2.process(noerrors)
39
40errorsinevent = basf2.Path()
41errorsinevent.add_module('EventInfoSetter')
42errorsinevent.add_module(ErrorInEvent())
43
44# no errors before event processing
45basf2.process(errorsinevent)
46
47# there were errors in event() of previous run
48basf2.process(noerrors)
49basf2.process(noerrors)
50basf2.process(errorsinevent)
51# there were some more errors in event() of previous run
52basf2.process(noerrors)
53
54# errors in initialize() -> fail
55if os.fork() == 0:
56 noerrors.add_module(ErrorInInit())
57 basf2.process(noerrors)
58else:
59 assert os.wait()[1] != 0
60
61# errors before process() -> fail
62if os.fork() == 0:
63 basf2.B2ERROR("htns")
64 basf2.process(noerrors)
65else:
66 assert os.wait()[1] != 0
67
68basf2.B2INFO('everything was OK.')