from unittest import TestCase
from ..detector_condition import DetectorCondition
from ..operating_condition import OperatingCondition
[docs]class TestDetectorCondition(TestCase):
[docs] def test_defaults(self):
dc = DetectorCondition()
self.assertTrue(dc.available)
self.assertEqual(dc.parameters, [])
self.assertIsNone(dc.description)
self.assertIsNone(dc.name)
[docs] def test_setting_parameters(self):
dc = DetectorCondition()
with self.assertRaises(ValueError):
dc.parameters = ["Foo", "Bar"]
oc1 = OperatingCondition()
oc1.name = "Foo"
oc1.upper_deviation = 1.0
oc2 = OperatingCondition()
oc2.name = "Bar"
oc2.lower_deviation = 1.0
oc2.lower_deviation = True
dc.parameters = [oc1, oc2]
self.assertEqual(dc.parameters[0], oc1)
self.assertEqual(dc.parameters[1], oc2)
[docs] def test_to_dict(self):
dc = DetectorCondition()
with self.assertRaises(AttributeError):
d = dc.to_dict()
dc.name = "Bar"
self.assertEqual(dc.to_dict(),
{'name': 'Bar',
'parameters': [],
'flg_available': True})
oc1 = OperatingCondition()
oc1.name = "Foo"
oc1.upper_deviation = 1.0
oc1.lower_deviation = 4
oc1.logarithmic = True
oc1.value = 0
oc2 = OperatingCondition()
oc2.name = "Bar"
oc2.lower_deviation = 1.0
oc2.upper_deviation = 2.0
oc2.value = 1
dc.parameters = [oc1, oc2]
self.assertEqual(dc.to_dict(),
{'name': 'Bar', 'flg_available': True, 'parameters': [
{'value': 0.0, 'lower_deviation_value': 4.0,
'parameter_name': 'Foo',
'upper_deviation_value': 1.0,
'flg_available': True, 'flg_logarithmic': True},
{'value': 1.0, 'lower_deviation_value': 1.0,
'parameter_name': 'Bar',
'upper_deviation_value': 2.0,
'flg_available': True,
'flg_logarithmic': False}]}
)