13from caf.framework
import Calibration, CAF
16from unittest
import TestCase
17from pathlib
import Path
20b2.set_log_level(b2.LogLevel.ERROR)
25 UnitTest for configuration of Calibration class
30 Create useful objects for each test
32 from ROOT
import Belle2
33 from ROOT.Belle2
import TestCalibrationAlgorithm
as TestAlgo
39 self.
col1 = b2.register_module(
'CaTest')
49 Test whether or not calibration is valid with incorrect setup.
51 cal = Calibration(
'TestCalibrationClass_Configure_test1')
52 self.assertFalse(cal.is_valid())
56 Test whether or not calibration is valid with incorrect setup.
58 cal = Calibration(
'TestCalibrationClass_Configure_test2')
59 cal.collector =
'CaTest'
60 self.assertFalse(cal.is_valid())
64 Test whether or not calibration is valid with incorrect setup.
66 cal = Calibration(
'TestCalibrationClass_Configure_test3')
67 cal.collector = self.
col1
68 self.assertFalse(cal.is_valid())
72 Test whether or not calibration is valid with incorrect setup.
74 cal = Calibration(
'TestCalibrationClass_Configure_test4')
75 cal.collector = self.
col1
76 cal.algorithms = [self.
alg1, self.
alg2]
77 self.assertFalse(cal.is_valid())
81 Test whether or not calibration is valid with correct setup.
83 cal = Calibration(
'TestCalibrationClass_Configure_test5')
84 cal.collector = self.
col1
85 cal.algorithms = [self.
alg1, self.
alg2]
87 self.assertTrue(cal.is_valid())
91 Test whether or not calibration is valid with alternative correct setup.
93 cal = Calibration(
'TestCalibrationClass_Configure_test6')
94 cal.collector = self.
col1
95 cal.algorithms = [self.
alg1, self.
alg2]
97 self.assertTrue(cal.is_valid())
109 UnitTest for validity of Calibration class when given arguments of different types
114 Create useful objects for each test
116 from ROOT
import Belle2
117 from ROOT.Belle2
import TestCalibrationAlgorithm
as TestAlgo
124 self.
col1 = b2.register_module(
'CaTest')
136 Test whether or not calibration is valid with correct setup and if name is stored correctly
145 self.assertTrue(cal.is_valid()
and cal.name == self.
name)
149 Test whether or not calibration is valid with alternative correct setup and if name is stored correctly
152 self.assertTrue(cal.is_valid()
and cal.name == self.
name)
156 Test that the default options are correctly applied to a calibration
158 defaults = {
"max_iterations": 4}
160 cal1._apply_calibration_defaults(defaults)
162 self.assertTrue(cal1.max_iterations == 4
and not cal2.max_iterations)
174 UnitTest for configuration and simple running of CAF
179 Create useful objects for each test and the teardown
181 from ROOT
import Belle2
182 from ROOT.Belle2
import TestCalibrationAlgorithm
as TestAlgo
191 col = b2.register_module(
'CaTest')
204 Test that add_calibration function results in correct output
207 fw.add_calibration(self.
cal1)
208 fw.add_calibration(self.
cal2)
209 self.assertTrue(fw.calibrations[self.
name1].name == self.
name1 and fw.calibrations[self.
name2].name == self.
name2)
213 Test that add_dependency function cannot add itself
216 self.assertFalse(self.
cal1.dependencies)
220 Test that output_dir directory is created correctly
223 fw.output_dir =
'testCAF_outputdir'
224 fw._make_output_dir()
225 self.assertTrue(os.path.isdir(
'testCAF_outputdir'))
229 Test that config is correctly setting the default output path.
232 self.assertTrue(fw.output_dir ==
'calibration_results')
236 Removes files that were created during these tests
239 dirs = glob.glob(
'*testCAF_outputdir')
240 for directory
in dirs:
241 shutil.rmtree(directory)
248if __name__ ==
'__main__':
str name3
Calibration name for use in unittests.
cal1
Calibration attribute for use in unittests.
str name2
Calibration name for use in unittests.
test_add_calibration(self)
test_add_dependency_on_itself(self)
cal3
Calibration attribute for use in unittests.
test_config_output_dir(self)
cal2
Calibration attribute for use in unittests.
str name1
Calibration name for use in unittests.
test_make_output_dir(self)
example_file1
Path to an example file.
col1
Collector module attribute for use in unittests.
example_file2
Path to a second example file.
example_file1
Path to an example file.
alg2
Calibration algorithm for use in unittests.
str name
Calibration name for use in unittests.
alg1
Calibration algorithm for use in unittests.