13 from ROOT.Belle2
import TestCalibrationAlgorithm
as TestAlgo
15 from caf.framework
import Calibration, CAF
18 from unittest
import TestCase
19 from pathlib
import Path
22 b2.set_log_level(b2.LogLevel.ERROR)
27 UnitTest for configuration of Calibration class
32 Create useful objects for each test
39 self.
col1col1 = b2.register_module(
'CaTest')
48 Test whether or not calibration is valid with incorrect setup.
50 cal =
Calibration(
'TestCalibrationClass_Configure_test1')
51 self.assertFalse(cal.is_valid())
55 Test whether or not calibration is valid with incorrect setup.
57 cal =
Calibration(
'TestCalibrationClass_Configure_test2')
58 cal.collector =
'CaTest'
59 self.assertFalse(cal.is_valid())
63 Test whether or not calibration is valid with incorrect setup.
65 cal =
Calibration(
'TestCalibrationClass_Configure_test3')
66 cal.collector = self.
col1col1
67 self.assertFalse(cal.is_valid())
71 Test whether or not calibration is valid with incorrect setup.
73 cal =
Calibration(
'TestCalibrationClass_Configure_test4')
74 cal.collector = self.
col1col1
75 cal.algorithms = [self.
alg1alg1, self.
alg2alg2]
76 self.assertFalse(cal.is_valid())
80 Test whether or not calibration is valid with correct setup.
82 cal =
Calibration(
'TestCalibrationClass_Configure_test5')
83 cal.collector = self.
col1col1
84 cal.algorithms = [self.
alg1alg1, self.
alg2alg2]
86 self.assertTrue(cal.is_valid())
90 Test whether or not calibration is valid with alternative correct setup.
92 cal =
Calibration(
'TestCalibrationClass_Configure_test6')
93 cal.collector = self.
col1col1
94 cal.algorithms = [self.
alg1alg1, self.
alg2alg2]
96 self.assertTrue(cal.is_valid())
105 UnitTest for validity of Calibration class when given arguments of different types
110 Create useful objects for each test
117 self.
col1col1 = b2.register_module(
'CaTest')
119 self.
namename =
'TestCalibration'
128 Test whether or not calibration is valid with correct setup and if name is stored correctly
132 collector=self.
col1col1,
137 self.assertTrue(cal.is_valid()
and cal.name == self.
namename)
141 Test whether or not calibration is valid with alternative correct setup and if name is stored correctly
144 self.assertTrue(cal.is_valid()
and cal.name == self.
namename)
148 Test that the default options are correctly applied to a calibration
150 defaults = {
"max_iterations": 4}
152 cal1._apply_calibration_defaults(defaults)
154 self.assertTrue(cal1.max_iterations == 4
and not cal2.max_iterations)
163 UnitTest for configuration and simple running of CAF
168 Create useful objects for each test and the teardown
171 self.
name1name1 =
'TestCalibration1'
173 self.
name2name2 =
'TestCalibration2'
175 self.
name3name3 =
'TestCalibration3'
177 col = b2.register_module(
'CaTest')
190 Test that add_calibration function results in correct output
193 fw.add_calibration(self.
cal1cal1)
194 fw.add_calibration(self.
cal2cal2)
195 self.assertTrue(fw.calibrations[self.
name1name1].name == self.
name1name1
and fw.calibrations[self.
name2name2].name == self.
name2name2)
199 Test that add_dependency function cannot add itself
201 self.
cal1cal1.depends_on(self.
cal1cal1)
202 self.assertFalse(self.
cal1cal1.dependencies)
206 Test that output_dir directory is created correctly
209 fw.output_dir =
'testCAF_outputdir'
210 fw._make_output_dir()
211 self.assertTrue(os.path.isdir(
'testCAF_outputdir'))
215 Test that config is correctly setting the default output path.
218 self.assertTrue(fw.output_dir ==
'calibration_results')
222 Removes files that were created during these tests
225 dirs = glob.glob(
'*testCAF_outputdir')
226 for directory
in dirs:
227 shutil.rmtree(directory)
234 if __name__ ==
'__main__':
def test_add_dependency_on_itself(self)
def test_make_output_dir(self)
name3
Calibration name for use in unittests.
def test_add_calibration(self)
def test_config_output_dir(self)
name1
Calibration name for use in unittests.
cal1
Calibration attribute for use in unittests.
cal3
Calibration attribute for use in unittests.
cal2
Calibration attribute for use in unittests.
example_file1
Path to an example file.
name2
Calibration name for use in unittests.
col1
Collector module attribute for use in unittests.
name
Calibration name for use in unittests.
example_file1
Path to an example file.
alg2
Calibration algorithm for use in unittests.
alg1
Calibration algorithm for use in unittests.
int main(int argc, char **argv)
Run all tests.