Belle II Software light-2406-ragdoll
TestVariableUtilities Class Reference
Inheritance diagram for TestVariableUtilities:
Collaboration diagram for TestVariableUtilities:

Public Member Functions

def assertAliases (self, decaystring, expected, **argk)
 
def test_wrong_decaystring (self)
 to add to the tests here, please add a test_something_something for you favourite complicated decay string
 
def test_no_particle_selected (self)
 
def test_number_of_prefix_mismatch (self)
 
def test_prefixes_repeated (self)
 
def test_named_daughter (self)
 
def test_named_mother_and_daughters (self)
 
def test_unnamed_daughter (self)
 
def test_unnamed_mother (self)
 
def test_autonamed_granddaughter (self)
 
def test_multiple_autoname_granddaughters (self)
 
def test_autoindex (self)
 
def test_autoindex_relative (self)
 
def test_autoindex_allindexed (self)
 
def test_autoindex_allindexed_relative (self)
 
def test_indexed (self)
 
def test_indexed_relativeignored (self)
 
def test_threedkp (self)
 
def test_fourdkp (self)
 
def test_ohsomany_autonamed (self)
 
def test_ohsomany_autonamed_relative (self)
 
def test_ohsomany_indexed (self)
 
def test_inclusive (self)
 
def test_zfinal (self)
 

Protected Member Functions

def _expand_expected (self, expected)
 

Static Protected Attributes

list _list_of_variables = ['M', 'p']
 list of variables to test
 

Detailed Description

Test case for the variables.utils functions

Definition at line 16 of file test_variables_utils.py.

Member Function Documentation

◆ _expand_expected()

def _expand_expected (   self,
  expected 
)
protected
Expand the list of expected aliases by appending _{name} for each variable in the _list_of_variables

Definition at line 22 of file test_variables_utils.py.

22 def _expand_expected(self, expected):
23 """Expand the list of expected aliases by appending _{name} for each variable in the _list_of_variables"""
24 result = []
25 for p in expected:
26 if p:
27 result += [f"{p}_{e}" for e in self._list_of_variables]
28 else:
29 result += self._list_of_variables
30 return result
31

◆ assertAliases()

def assertAliases (   self,
  decaystring,
  expected,
**  argk 
)
Make sure the aliases created for given decaystring are as expected
Also, pass any additional keyword arguments to the create_aliases_for_selected function

Definition at line 32 of file test_variables_utils.py.

32 def assertAliases(self, decaystring, expected, **argk):
33 """Make sure the aliases created for given decaystring are as expected
34 Also, pass any additional keyword arguments to the create_aliases_for_selected function
35 """
36 expected = self._expand_expected(expected)
37 actual = create_aliases_for_selected(self._list_of_variables, decaystring, **argk)
38 self.assertEqual(expected, actual, f"decaystring: {decaystring}, arguments: {argk}")
39

◆ test_autoindex()

def test_autoindex (   self)
 check decay-string-of-doom with automatic names 

Definition at line 100 of file test_variables_utils.py.

100 def test_autoindex(self):
101 """ check decay-string-of-doom with automatic names """
102 self.assertAliases(
103 "^B0 -> [D0 -> ^pi+ ^pi-] [D+ -> ^pi+ pi0] [D0 -> ^pi+ ^pi-] [K- -> ^pi+ ^pi-] ^pi+ ^pi- pi0",
104 [
105 "",
106 "D0_0_pi_0",
107 "D0_0_pi_1",
108 "D_pi",
109 "D0_2_pi_0",
110 "D0_2_pi_1",
111 "K_pi_0",
112 "K_pi_1",
113 "pi_4",
114 "pi_5",
115 ])
116

◆ test_autoindex_allindexed()

def test_autoindex_allindexed (   self)
 check decay-string-of-doom with automatic names and forced indices

Definition at line 134 of file test_variables_utils.py.

134 def test_autoindex_allindexed(self):
135 """ check decay-string-of-doom with automatic names and forced indices"""
136 self.assertAliases(
137 "^B0 -> [D0 -> ^pi+ ^pi-] [D+ -> ^pi+ pi0] [D0 -> ^pi+ ^pi-] [K- -> ^pi+ ^pi-] ^pi+ ^pi- pi0",
138 [
139 "",
140 "D0_0_pi_0",
141 "D0_0_pi_1",
142 "D_1_pi_0",
143 "D0_2_pi_0",
144 "D0_2_pi_1",
145 "K_3_pi_0",
146 "K_3_pi_1",
147 "pi_4",
148 "pi_5",
149 ], always_include_indices=True)
150

◆ test_autoindex_allindexed_relative()

def test_autoindex_allindexed_relative (   self)
 check decay-string-of-doom with automatic names, relative indexing and forced indices

Definition at line 151 of file test_variables_utils.py.

151 def test_autoindex_allindexed_relative(self):
152 """ check decay-string-of-doom with automatic names, relative indexing and forced indices"""
153 self.assertAliases(
154 "^B0 -> [D0 -> ^pi+ ^pi-] [D+ -> ^pi+ pi0] [D0 -> ^pi+ ^pi-] [K- -> ^pi+ ^pi-] ^pi+ ^pi- pi0",
155 [
156 "",
157 "D0_0_pi_0",
158 "D0_0_pi_1",
159 "D_0_pi_0",
160 "D0_1_pi_0",
161 "D0_1_pi_1",
162 "K_0_pi_0",
163 "K_0_pi_1",
164 "pi_0",
165 "pi_1",
166 ], use_relative_indices=True, always_include_indices=True)
167

◆ test_autoindex_relative()

def test_autoindex_relative (   self)
 check decay-string-of-doom with automatic names and relative indexing

Definition at line 117 of file test_variables_utils.py.

117 def test_autoindex_relative(self):
118 """ check decay-string-of-doom with automatic names and relative indexing"""
119 self.assertAliases(
120 "^B0 -> [D0 -> ^pi+ ^pi-] [D+ -> ^pi+ pi0] [D0 -> ^pi+ ^pi-] [K- -> ^pi+ ^pi-] ^pi+ ^pi- pi0",
121 [
122 "",
123 "D0_0_pi_0",
124 "D0_0_pi_1",
125 "D_pi",
126 "D0_1_pi_0",
127 "D0_1_pi_1",
128 "K_pi_0",
129 "K_pi_1",
130 "pi_0",
131 "pi_1",
132 ], use_relative_indices=True)
133

◆ test_autonamed_granddaughter()

def test_autonamed_granddaughter (   self)
Check granddaughter can be selected for an automatic name alias

Definition at line 85 of file test_variables_utils.py.

85 def test_autonamed_granddaughter(self):
86 """Check granddaughter can be selected for an automatic name alias"""
87 self.assertAliases('B0 -> [D0 -> ^pi+ K-] pi0', ['D0_pi'])
88

◆ test_fourdkp()

def test_fourdkp (   self)
 check if the indexing works with more than two ... 

Definition at line 212 of file test_variables_utils.py.

212 def test_fourdkp(self):
213 """ check if the indexing works with more than two ... """
214 self.assertAliases(
215 "B0 -> [D+ -> [K+ -> ^pi+]] [D+ -> [K+ -> ^pi+]] [D+ -> [K+ -> ^pi+]] [D+ -> [K+ -> ^pi+]]",
216 [
217 "D_0_K_pi",
218 "D_1_K_pi",
219 "D_2_K_pi",
220 "D_3_K_pi",
221 ])
222 self.assertAliases(
223 "B0 -> [D+ -> [K+ -> pi+]] [D+ -> [K+ -> ^pi+]] [D+ -> [^K+ -> pi+]] [D+ -> [K+ -> ^pi+]]",
224 [
225 "D_1_K_pi",
226 "D_2_K",
227 "D_3_K_pi",
228 ])
229 self.assertAliases(
230 "B0 -> [D+ -> [K+ -> pi+]] [D+ -> [K+ -> ^pi+]] [D+ -> [^K+ -> pi+]] [D+ -> [K+ -> ^pi+]]",
231 [
232 "D_0_K_pi",
233 "D_1_K",
234 "D_2_K_pi",
235 ], use_relative_indices=True)
236

◆ test_inclusive()

def test_inclusive (   self)
Select a decay with the inclusive particle marker

Definition at line 284 of file test_variables_utils.py.

284 def test_inclusive(self):
285 """Select a decay with the inclusive particle marker"""
286 self.assertAliases("B0 -> ^Xsd e+:loose e-:loose", ["Xsd"])
287

◆ test_indexed()

def test_indexed (   self)
 check decay-string-of-doom w/o automatic names 

Definition at line 168 of file test_variables_utils.py.

168 def test_indexed(self):
169 """ check decay-string-of-doom w/o automatic names """
170 self.assertAliases(
171 "^B0 -> [D0 -> ^pi+ ^pi-] [D+ -> ^pi+ pi0] [D0 -> ^pi+ ^pi-] [K- -> ^pi+ ^pi-] ^pi+ ^pi- pi0",
172 [
173 "",
174 "d0_d0",
175 "d0_d1",
176 "d1_d0",
177 "d2_d0",
178 "d2_d1",
179 "d3_d0",
180 "d3_d1",
181 "d4",
182 "d5",
183 ], use_names=False)
184

◆ test_indexed_relativeignored()

def test_indexed_relativeignored (   self)
 check decay-string-of-doom w/o automatic names and make sure relative indexing is **not** honored

Definition at line 185 of file test_variables_utils.py.

185 def test_indexed_relativeignored(self):
186 """ check decay-string-of-doom w/o automatic names and make sure relative indexing is **not** honored"""
187 self.assertAliases(
188 "^B0 -> [D0 -> ^pi+ ^pi-] [D+ -> ^pi+ pi0] [D0 -> ^pi+ ^pi-] [K- -> ^pi+ ^pi-] ^pi+ ^pi- pi0",
189 [
190 "",
191 "d0_d0",
192 "d0_d1",
193 "d1_d0",
194 "d2_d0",
195 "d2_d1",
196 "d3_d0",
197 "d3_d1",
198 "d4",
199 "d5",
200 ], use_names=False, use_relative_indices=True)
201

◆ test_multiple_autoname_granddaughters()

def test_multiple_autoname_granddaughters (   self)
Check multiple granddaughters can be selected for automatic name aliases

Definition at line 89 of file test_variables_utils.py.

89 def test_multiple_autoname_granddaughters(self):
90 """Check multiple granddaughters can be selected for automatic name aliases"""
91 self.assertAliases(
92 'B0 -> [D0 -> ^pi+ ^pi- ^pi0] ^pi0',
93 [
94 'D0_pi_0',
95 'D0_pi_1',
96 'D0_pi0',
97 'pi0',
98 ])
99

◆ test_named_daughter()

def test_named_daughter (   self)
Check daughter can be selected for an specific named alias

Definition at line 67 of file test_variables_utils.py.

67 def test_named_daughter(self):
68 """Check daughter can be selected for an specific named alias"""
69 self.assertAliases('B0 -> [^D0 -> pi+ K-] pi0', ['dzero'], prefix='dzero')
70

◆ test_named_mother_and_daughters()

def test_named_mother_and_daughters (   self)
Check mother and daughter can be selected for an specific named alias

Definition at line 71 of file test_variables_utils.py.

71 def test_named_mother_and_daughters(self):
72 """Check mother and daughter can be selected for an specific named alias"""
73 self.assertAliases('^B0 -> [^D0 -> pi+ ^K-] pi0', ['MyB', 'MyD', 'MyK'], prefix=['MyB', 'MyD', 'MyK'])
74

◆ test_no_particle_selected()

def test_no_particle_selected (   self)
Make sure we get an error if o particle is selected

Definition at line 49 of file test_variables_utils.py.

49 def test_no_particle_selected(self):
50 """Make sure we get an error if o particle is selected"""
51 with self.assertRaises(ValueError):
52 create_aliases_for_selected(["p"], "B0 -> pi0")
53

◆ test_number_of_prefix_mismatch()

def test_number_of_prefix_mismatch (   self)
Make sure we get an error if the number of supplied prefixes doesn't
match the number of selected particles

Definition at line 54 of file test_variables_utils.py.

54 def test_number_of_prefix_mismatch(self):
55 """Make sure we get an error if the number of supplied prefixes doesn't
56 match the number of selected particles"""
57 with self.assertRaises(ValueError):
58 create_aliases_for_selected(["p"], "^B0 -> ^pi0", prefix="one")
59 with self.assertRaises(ValueError):
60 create_aliases_for_selected(["p"], "B0 -> ^pi0", prefix=["one", "two"])
61

◆ test_ohsomany_autonamed()

def test_ohsomany_autonamed (   self)
Test many many children

Definition at line 237 of file test_variables_utils.py.

237 def test_ohsomany_autonamed(self):
238 """Test many many children"""
239 self.assertAliases(
240 "B0 -> e+:0 ^e+:1 ^e+:2 e+:3 ^e+:4 e+:5 ^e+:6 mu+:7 ^mu+:8 mu+:9 ^mu+:10 ^mu+:11 mu+:12",
241 [
242 "e_1",
243 "e_2",
244 "e_4",
245 "e_6",
246 "mu_8",
247 "mu_10",
248 "mu_11",
249 ])
250

◆ test_ohsomany_autonamed_relative()

def test_ohsomany_autonamed_relative (   self)
Test many many children with relative indices

Definition at line 251 of file test_variables_utils.py.

251 def test_ohsomany_autonamed_relative(self):
252 """Test many many children with relative indices"""
253 self.assertAliases(
254 "B0 -> e+:0 ^e+:1 ^e+:2 e+:3 ^e+:4 e+:5 ^e+:6 mu+:7 ^mu+:8 mu+:9 ^mu+:10 ^mu+:11 mu+:12",
255 [
256 "e_0",
257 "e_1",
258 "e_2",
259 "e_3",
260 "mu_0",
261 "mu_1",
262 "mu_2",
263 ], use_relative_indices=True)
264

◆ test_ohsomany_indexed()

def test_ohsomany_indexed (   self)
Test many many children without names

Definition at line 265 of file test_variables_utils.py.

265 def test_ohsomany_indexed(self):
266 """Test many many children without names"""
267 for use_relative_indices in True, False:
268 for always_include_indices in True, False:
269 self.assertAliases(
270 "B0 -> e+:0 ^e+:1 ^e+:2 e+:3 ^e+:4 e+:5 ^e+:6 mu+:7 ^mu+:8 mu+:9 ^mu+:10 ^mu+:11 mu+:12",
271 [
272 "d1",
273 "d2",
274 "d4",
275 "d6",
276 "d8",
277 "d10",
278 "d11",
279 ], use_names=False,
280 use_relative_indices=use_relative_indices,
281 always_include_indices=always_include_indices,
282 )
283

◆ test_prefixes_repeated()

def test_prefixes_repeated (   self)
Make sure we got an error if the supplied provided prefixes are not unique

Definition at line 62 of file test_variables_utils.py.

62 def test_prefixes_repeated(self):
63 """Make sure we got an error if the supplied provided prefixes are not unique"""
64 with self.assertRaises(ValueError):
65 create_aliases_for_selected(["p"], "^B0 -> ^pi0", prefix=["mine", "mine"])
66

◆ test_threedkp()

def test_threedkp (   self)
 check if the indexing works with more than two ... 

Definition at line 202 of file test_variables_utils.py.

202 def test_threedkp(self):
203 """ check if the indexing works with more than two ... """
204 self.assertAliases(
205 "B0 -> [D+ -> [K+ -> ^pi+]] [D+ -> [K+ -> ^pi+]] [D+ -> [K+ -> ^pi+]]",
206 [
207 "D_0_K_pi",
208 "D_1_K_pi",
209 "D_2_K_pi",
210 ])
211

◆ test_unnamed_daughter()

def test_unnamed_daughter (   self)
Check daughter can be selected w/o an specific named alias

Definition at line 75 of file test_variables_utils.py.

75 def test_unnamed_daughter(self):
76 """Check daughter can be selected w/o an specific named alias"""
77 self.assertAliases('B0 -> [^D0 -> ^pi+ ^K-] pi0', ['d0', 'd0_d0', 'd0_d1'], use_names=False)
78

◆ test_unnamed_mother()

def test_unnamed_mother (   self)
Check daughter can be selected w/o an specific named alias

Definition at line 79 of file test_variables_utils.py.

79 def test_unnamed_mother(self):
80 """Check daughter can be selected w/o an specific named alias"""
81 self.assertAliases('^B0 -> pi0 ^pi0', ['', 'd1'], use_names=False)
82 # also make sure we ignore ``use_relative_indices``
83 self.assertAliases('^B0 -> pi0 ^pi0', ['', 'd1'], use_names=False, use_relative_indices=True)
84

◆ test_wrong_decaystring()

def test_wrong_decaystring (   self)

to add to the tests here, please add a test_something_something for you favourite complicated decay string

Make sure we get an error if the decaystring is not valid

Definition at line 44 of file test_variables_utils.py.

44 def test_wrong_decaystring(self):
45 """Make sure we get an error if the decaystring is not valid"""
46 with self.assertRaises(ValueError):
47 create_aliases_for_selected(["p"], "eeh <- ok")
48

◆ test_zfinal()

def test_zfinal (   self)
Print all aliases as a final check

Definition at line 288 of file test_variables_utils.py.

288 def test_zfinal(self):
289 """Print all aliases as a final check"""
290 vm.printAliases()
291
292

Member Data Documentation

◆ _list_of_variables

list _list_of_variables = ['M', 'p']
staticprotected

list of variables to test

Definition at line 20 of file test_variables_utils.py.


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