Belle II Software  release-05-01-25
test_std_v0.py
1 #!/usr/bin/env python3
2 # -*- coding: utf-8 -*-
3 
4 import unittest
5 from basf2 import create_path
6 import stdV0s
7 
8 
9 class TestStdV0(unittest.TestCase):
10  """Test case for standard V0 lists"""
11 
13  self,
14  std_function=stdV0s.stdKshorts,
15  expected_modules=[
16  "ParticleLoader",
17  "TreeFitter",
18  "ParticleSelector",
19  "ParticleLoader",
20  "ParticleCombiner",
21  "TreeFitter",
22  "ParticleSelector",
23  "ParticleListManipulator"],
24  expected_lists=['V0', 'all', 'RD', 'merged']):
25  """check that a given function works"""
26  testpath = create_path()
27  std_function(path=testpath)
28 
29  # verify that we load the correct amount of modules
30  self.assertEqual(
31  len(testpath.modules()), len(expected_modules),
32  "Function %s does not load the expected number of modules" % (std_function.__name__))
33 
34  #
35  loaded_modules = []
36  built_lists = []
37  for module in testpath.modules():
38  loaded_modules.append(module.type())
39  for param in module.available_params():
40  if module.type() == 'ParticleLoader' and param.name == 'decayStringsWithCuts':
41  name = param.values[0][0].split(':')[1].split(' -> ')[0]
42  built_lists.append(name)
43  if module.type() == 'ParticleListManipulator' and param.name == 'outputListName':
44  name = str(param.values).split(':')[1].split(' -> ')[0]
45  built_lists.append(name)
46  if module.type() == 'ParticleCombiner' and param.name == 'decayString':
47  name = param.values.split(':')[1].split(' -> ')[0]
48  built_lists.append(name)
49 
50  # we have the modules we expect
51  for a, b in zip(loaded_modules, expected_modules):
52  self.assertEqual(a, b, "Loaded module \'%s\' instead of \'%s\' with function %s" % (a, b, std_function.__name__))
53 
54  # we have the particle lists we expect
55  for a, b in zip(built_lists, expected_lists):
56  self.assertEqual(a, b, "Loaded list \'%s\' instead of \'%s\' with function %s" % (a, b, std_function.__name__))
57 
59  """check that the builder function works with the stdKshorts list"""
60  self._check_list()
61 
62  def test_belle_list(self):
63  """check that the builder function works with the legacy Belle Kshorts list"""
64  expected_modules = ["ParticleLoader",
65  "ParticleVertexFitter",
66  "ParticleSelector"]
67  self._check_list(std_function=stdV0s.goodBelleKshort, expected_modules=expected_modules, expected_lists=["legacyGoodKS"])
68 
70  """check that the builder function works with the stdLambdas list"""
71  expected_modules = ["ParticleLoader",
72  "TreeFitter",
73  "ParticleSelector",
74  "DuplicateVertexMarker",
75  "ParticleSelector",
76  "ParticleLoader",
77  "ParticleLoader",
78  "ParticleCombiner",
79  "TreeFitter",
80  "ParticleSelector",
81  "DuplicateVertexMarker",
82  "ParticleSelector",
83  "ParticleListManipulator"]
84  expected_lists = ['V0', 'all', 'all', 'RD', 'merged']
85  self._check_list(std_function=stdV0s.stdLambdas, expected_modules=expected_modules, expected_lists=expected_lists)
86 
87 
88 if __name__ == '__main__':
89  unittest.main()
test_std_v0.TestStdV0.test_stdkshorts_list
def test_stdkshorts_list(self)
Definition: test_std_v0.py:58
test_std_v0.TestStdV0.test_stdlambdas_list
def test_stdlambdas_list(self)
Definition: test_std_v0.py:69
test_std_v0.TestStdV0
Definition: test_std_v0.py:9
test_std_v0.TestStdV0.test_belle_list
def test_belle_list(self)
Definition: test_std_v0.py:62
test_std_v0.TestStdV0._check_list
def _check_list(self, std_function=stdV0s.stdKshorts, expected_modules=["ParticleLoader", "TreeFitter", "ParticleSelector", "ParticleLoader", "ParticleCombiner", "TreeFitter", "ParticleSelector", "ParticleListManipulator"], expected_lists=['V0', 'all', 'RD', 'merged'])
Definition: test_std_v0.py:12