Belle II Software  release-08-01-10
test_std_v0.py
1 #!/usr/bin/env python3
2 
3 
10 
11 import unittest
12 from basf2 import create_path
13 import stdV0s
14 
15 
16 class TestStdV0(unittest.TestCase):
17  """Test case for standard V0 lists"""
18 
20  self,
21  std_function=stdV0s.stdKshorts,
22  expected_modules=[
23  "ParticleLoader",
24  "ParticleListManipulator",
25  "TreeFitter",
26  "ParticleSelector",
27  "ParticleLoader",
28  "ParticleCombiner",
29  "TreeFitter",
30  "ParticleSelector",
31  "ParticleListManipulator"],
32  expected_lists=['V0_ToFit', 'V0_ToFit', 'all', 'RD', 'merged']):
33  """check that a given function works"""
34  testpath = create_path()
35  std_function(path=testpath)
36 
37  loaded_modules = []
38  built_lists = []
39  for module in testpath.modules():
40  loaded_modules.append(module.type())
41  for param in module.available_params():
42  if module.type() == 'ParticleLoader' and param.name == 'decayStrings':
43  name = param.values[0].split(':')[1].split(' -> ')[0]
44  built_lists.append(name)
45  if module.type() == 'ParticleListManipulator' and param.name == 'outputListName':
46  name = str(param.values).split(':')[1].split(' -> ')[0]
47  built_lists.append(name)
48  if module.type() == 'ParticleCombiner' and param.name == 'decayString':
49  name = param.values.split(':')[1].split(' -> ')[0]
50  built_lists.append(name)
51 
52  # Check that we load the correct modules
53  self.assertListEqual(
54  loaded_modules, expected_modules,
55  f"Loaded modules do not match the expected ones (function {std_function.__name__})")
56 
57  # Check that we load the correct particle lists
58  self.assertListEqual(
59  built_lists, expected_lists,
60  f"Built particles lists do not match the expected ones (function {std_function.__name__})")
61 
63  """check that the builder function works with the stdKshorts list"""
64  self._check_list_check_list()
65 
66  def test_belle_list(self):
67  """check that the builder function works with the legacy Belle Kshorts list"""
68  expected_modules = ["ParticleLoader",
69  "ParticleListManipulator",
70  "ParticleSelector",
71  "ParticleVertexFitter",
72  "ParticleSelector"]
73  self._check_list_check_list(std_function=stdV0s.goodBelleKshort, expected_modules=expected_modules,
74  expected_lists=["legacyGoodKS", "legacyGoodKS"])
75 
77  """check that the builder function works with the stdLambdas list"""
78  expected_modules = ["ParticleLoader",
79  "ParticleListManipulator",
80  "TreeFitter",
81  "ParticleSelector",
82  "DuplicateVertexMarker",
83  "ParticleSelector",
84  "ParticleLoader",
85  "ParticleLoader",
86  "ParticleCombiner",
87  "TreeFitter",
88  "ParticleSelector",
89  "DuplicateVertexMarker",
90  "ParticleSelector",
91  "ParticleListManipulator"]
92  expected_lists = ['V0_ToFit', 'V0_ToFit', 'all', 'all', 'RD', 'merged']
93  self._check_list_check_list(std_function=stdV0s.stdLambdas, expected_modules=expected_modules, expected_lists=expected_lists)
94 
95 
96 if __name__ == '__main__':
97  unittest.main()
def _check_list(self, std_function=stdV0s.stdKshorts, expected_modules=["ParticleLoader", "ParticleListManipulator", "TreeFitter", "ParticleSelector", "ParticleLoader", "ParticleCombiner", "TreeFitter", "ParticleSelector", "ParticleListManipulator"], expected_lists=['V0_ToFit', 'V0_ToFit', 'all', 'RD', 'merged'])
Definition: test_std_v0.py:32
def test_stdlambdas_list(self)
Definition: test_std_v0.py:76
def test_stdkshorts_list(self)
Definition: test_std_v0.py:62
def test_belle_list(self)
Definition: test_std_v0.py:66