Belle II Software development
SetModuleParameters Class Reference
Inheritance diagram for SetModuleParameters:

Public Member Functions

def setUp (self)
 
def check_parameters (self, module, **params)
 
def check_unset (self, module)
 
def test_simple (self)
 
def test_double (self)
 
def test_empty (self)
 
def test_missing (self)
 
def test_undefined_param (self)
 
def test_condition (self)
 
def test_condition_recursive (self)
 
def test_subevent (self)
 
def test_subevent_recursive (self)
 
def test_condition_subevent (self)
 

Public Attributes

 m1
 first test module
 
 m2
 second test module
 
 m3
 third test module
 
 path
 main test path
 
 subpath
 secondary test path
 

Detailed Description

Test fixture to check setting of parameters for modules in a path by name

Definition at line 17 of file module_setparameters.py.

Member Function Documentation

◆ check_parameters()

def check_parameters (   self,
  module,
**  params 
)
Check if the parameters of a module are set explicitly to a given value

module: basf2.Module instance
params: named parameters of to check for

Definition at line 39 of file module_setparameters.py.

39 def check_parameters(self, module, **params):
40 """Check if the parameters of a module are set explicitly to a given value
41
42 module: basf2.Module instance
43 params: named parameters of to check for
44 """
45 for p in module.available_params():
46 if p.name in params:
47 self.assertTrue(p.setInSteering)
48 self.assertEqual(p.values, params[p.name])
49

◆ check_unset()

def check_unset (   self,
  module 
)
Check that all parameters of a given module are not set explicitely

Definition at line 50 of file module_setparameters.py.

50 def check_unset(self, module):
51 """Check that all parameters of a given module are not set explicitely"""
52 for p in module.available_params():
53 self.assertFalse(p.setInSteering)
54

◆ setUp()

def setUp (   self)
Setup a path with a few EventInfoSetter modules with special names

Definition at line 20 of file module_setparameters.py.

20 def setUp(self):
21 """Setup a path with a few EventInfoSetter modules with special names"""
22
23 self.m1 = basf2.register_module("EventInfoSetter")
24 self.m1.set_name("evt1")
25
26 self.m2 = basf2.register_module("EventInfoSetter")
27 self.m2.set_name("evt2")
28
29 self.m3 = basf2.register_module("EventInfoSetter")
30 self.m3.set_name("evt1")
31
32 self.path = basf2.create_path()
33
34 self.subpath = basf2.create_path()
35 self.path.add_module(self.m1)
36 self.path.add_module(self.m2)
37 self.subpath.add_module(self.m3)
38

◆ test_condition()

def test_condition (   self)
check that modules in a condition sub path are not affected by default

Definition at line 90 of file module_setparameters.py.

90 def test_condition(self):
91 """check that modules in a condition sub path are not affected by default"""
92 self.m2.if_true(self.subpath)
93 basf2.set_module_parameters(self.path, "evt1", evtNumList=[1, 2, 3])
94 self.check_parameters(self.m1, evtNumList=[1, 2, 3])
95 self.check_unset(self.m2)
96 self.check_unset(self.m3)
97

◆ test_condition_recursive()

def test_condition_recursive (   self)
check that modules in a condition sub path are affected in recursive mode

Definition at line 98 of file module_setparameters.py.

98 def test_condition_recursive(self):
99 """check that modules in a condition sub path are affected in recursive mode"""
100 self.m2.if_true(self.subpath)
101 basf2.set_module_parameters(self.path, "evt1", evtNumList=[1, 2, 3], recursive=True)
102 self.check_parameters(self.m1, evtNumList=[1, 2, 3])
103 self.check_unset(self.m2)
104 self.check_parameters(self.m3, evtNumList=[1, 2, 3])
105

◆ test_condition_subevent()

def test_condition_subevent (   self)
check that it also works with a conditions and a for_each sub path in recursive mode

Definition at line 122 of file module_setparameters.py.

122 def test_condition_subevent(self):
123 """check that it also works with a conditions and a for_each sub path in recursive mode"""
124 sub2 = basf2.create_path()
125 m4 = sub2.add_module("EventInfoSetter")
126 m4.set_name("evt1")
127 self.m2.if_true(self.subpath)
128 self.path.for_each("foo", "foos", sub2)
129 basf2.set_module_parameters(self.path, "evt1", evtNumList=[1, 2, 3], recursive=True)
130 self.check_parameters(self.m1, evtNumList=[1, 2, 3])
131 self.check_unset(self.m2)
132 self.check_parameters(self.m3, evtNumList=[1, 2, 3])
133 self.check_parameters(m4, evtNumList=[1, 2, 3])
134
135

◆ test_double()

def test_double (   self)
Check that it also works if more than one module with the name exists

Definition at line 67 of file module_setparameters.py.

67 def test_double(self):
68 """Check that it also works if more than one module with the name exists"""
69 self.path.add_module(self.m3)
70 basf2.set_module_parameters(self.path, "evt1", evtNumList=[1, 2, 3])
71 self.check_parameters(self.m1, evtNumList=[1, 2, 3])
72 self.check_unset(self.m2)
73 self.check_parameters(self.m3, evtNumList=[1, 2, 3])
74

◆ test_empty()

def test_empty (   self)
Make sure that not supplying any parameters gives a ValueError

Definition at line 75 of file module_setparameters.py.

75 def test_empty(self):
76 """Make sure that not supplying any parameters gives a ValueError"""
77 with self.assertRaises(ValueError):
78 basf2.set_module_parameters(self.path, "evt1")
79

◆ test_missing()

def test_missing (   self)
Make sure that not finding any module of the given name raises a KeyError

Definition at line 80 of file module_setparameters.py.

80 def test_missing(self):
81 """Make sure that not finding any module of the given name raises a KeyError"""
82 with self.assertRaises(KeyError):
83 basf2.set_module_parameters(self.path, "evt3", evtNumList=[0])
84

◆ test_simple()

def test_simple (   self)
Check setting the parameters for one module and that it does not affect the other modules

Definition at line 55 of file module_setparameters.py.

55 def test_simple(self):
56 """Check setting the parameters for one module and that it does not affect the other modules"""
57 self.check_unset(self.m1)
58 basf2.set_module_parameters(self.path, "evt1", evtNumList=[1, 2, 3])
59 self.check_parameters(self.m1, evtNumList=[1, 2, 3])
60 self.check_unset(self.m2)
61 self.check_unset(self.m3)
62 basf2.set_module_parameters(self.path, "evt2", evtNumList=[4])
63 self.check_parameters(self.m1, evtNumList=[1, 2, 3])
64 self.check_parameters(self.m2, evtNumList=[4])
65 self.check_unset(self.m3)
66

◆ test_subevent()

def test_subevent (   self)
check that modules in a for_each sub path are not affected by default

Definition at line 106 of file module_setparameters.py.

106 def test_subevent(self):
107 """check that modules in a for_each sub path are not affected by default"""
108 self.path.for_each("foo", "foos", self.subpath)
109 basf2.set_module_parameters(self.path, "evt1", evtNumList=[1, 2, 3])
110 self.check_parameters(self.m1, evtNumList=[1, 2, 3])
111 self.check_unset(self.m2)
112 self.check_unset(self.m3)
113

◆ test_subevent_recursive()

def test_subevent_recursive (   self)
check that modules in a for_each sub path are affected in recursive mode

Definition at line 114 of file module_setparameters.py.

114 def test_subevent_recursive(self):
115 """check that modules in a for_each sub path are affected in recursive mode"""
116 self.path.for_each("foo", "foos", self.subpath)
117 basf2.set_module_parameters(self.path, "evt1", evtNumList=[1, 2, 3], recursive=True)
118 self.check_parameters(self.m1, evtNumList=[1, 2, 3])
119 self.check_unset(self.m2)
120 self.check_parameters(self.m3, evtNumList=[1, 2, 3])
121

◆ test_undefined_param()

def test_undefined_param (   self)
Make sure that being unable to set the parameter raises a RuntimeError

Definition at line 85 of file module_setparameters.py.

85 def test_undefined_param(self):
86 """Make sure that being unable to set the parameter raises a RuntimeError"""
87 with self.assertRaises(RuntimeError):
88 basf2.set_module_parameters(self.path, "evt1", foo="bar")
89

Member Data Documentation

◆ m1

m1

first test module

Definition at line 23 of file module_setparameters.py.

◆ m2

m2

second test module

Definition at line 26 of file module_setparameters.py.

◆ m3

m3

third test module

Definition at line 29 of file module_setparameters.py.

◆ path

path

main test path

Definition at line 32 of file module_setparameters.py.

◆ subpath

subpath

secondary test path

Definition at line 34 of file module_setparameters.py.


The documentation for this class was generated from the following file: