示例#1
0
    def test_set_health(self):
        self.o.update_health(self.part,
                             Alarm(severity=AlarmSeverity.MINOR_ALARM))
        self.o.update_health(self.part2,
                             Alarm(severity=AlarmSeverity.MAJOR_ALARM))
        assert self.o.health.alarm.severity == AlarmSeverity.MAJOR_ALARM

        self.o.update_health(self.part,
                             Alarm(severity=AlarmSeverity.UNDEFINED_ALARM))
        self.o.update_health(self.part2,
                             Alarm(severity=AlarmSeverity.INVALID_ALARM))
        assert self.o.health.alarm.severity == AlarmSeverity.UNDEFINED_ALARM

        self.o.update_health(self.part)
        self.o.update_health(self.part2)
        assert self.o.health.value == "OK"
示例#2
0
 def setUp(self):
     self.serialized = OrderedDict()
     self.serialized["typeid"] = "epics:nt/NTScalar:1.0"
     self.serialized["meta"] = StringMeta("desc").to_dict()
     self.serialized["value"] = "some string"
     self.serialized["alarm"] = Alarm().to_dict()
     self.serialized["timeStamp"] = TimeStamp().to_dict()
示例#3
0
 def side_effect(post, typ, kwargs):
     if kwargs["endpoint"] == "D":
         self.post = post
         bit = dict(type=VInt, descriptor="Desc", value=3,
                    alarm=Alarm.ok().to_dict(), timeStamp=43.2)
         post(SType.Return, value=dict(attributes=dict(bit=bit)))
     elif kwargs["endpoint"] == "D.attributes.bit":
         self.spost = post
示例#4
0
 def test_to_dict(self):
     d = self.s.to_dict()
     self.assertEqual(d.keys(), ['type', 'descriptor'])
     self.assertEqual(d.values(), ['str', 'The String'])
     self.s.update("wow", timeStamp=3.2)
     d = self.s.to_dict()
     self.assertEqual(d.keys(), ['value', 'type', 'descriptor', 'alarm', 'timeStamp'])
     self.assertEqual(d.values(), ['wow', 'str', 'The String', Alarm.ok(), 3.2])
 def side_effect(post, typ, kwargs):
     if kwargs["endpoint"] == "D":
         sm = dict(
             state=DState.Running.to_dict(), message="foo", timeStamp=43.2)
         run = dict(descriptor="Run")
         bit = dict(type="int", descriptor="Desc", value=3,
                    alarm=Alarm.ok().to_dict(), timeStamp=43.2)
         post(SType.Return, value=dict(
             attributes=dict(bit=bit), stateMachine=sm, methods=dict(run=run)))
示例#6
0
 def test_compare_vtables(self):
     a = Attribute(VTable, "Positions")
     a.notify_listeners = MagicMock()
     t1 = [("x", VLong, numpy.arange(5, dtype=numpy.int64), ''), 
           ("y", VLong, numpy.arange(5, dtype=numpy.int64) + 2, 'mm')]
     a.update(t1, None, 1.0)
     a.notify_listeners.assert_called_with(
         dict(value=t1, alarm=Alarm.ok(), timeStamp=1.0))
     a.update(t1, None, 1.0)
     a.notify_listeners.assert_called_with(dict())
     t2 = [("x", VLong, numpy.arange(5, dtype=numpy.int64) + 3, ''),
           ("y", VLong, numpy.arange(5, dtype=numpy.int64) + 2, '')]
     a.update(t2, None, 1.0)
     a.notify_listeners.assert_called_with(dict(value=t2))
示例#7
0
 def test_attribute_monitors(self):
     def side_effect(post, typ, kwargs):
         if kwargs["endpoint"] == "D":
             self.post = post
             bit = dict(type=VInt, descriptor="Desc", value=3,
                        alarm=Alarm.ok().to_dict(), timeStamp=43.2)
             post(SType.Return, value=dict(attributes=dict(bit=bit)))
         elif kwargs["endpoint"] == "D.attributes.bit":
             self.spost = post
     self.sock.request.side_effect = side_effect
     self.d.loop_run()
     self.assertEqual(len(self.sock.mock_calls), 2)
     self.assertEqual(self.sock.request.call_args_list[0], call(
         self.post, SType.Get, dict(endpoint="D")))
     self.assertEqual(self.sock.request.call_args_list[1], call(
         self.spost, SType.Subscribe, dict(endpoint="D.attributes.bit")))
     self.assertEqual(self.d.bit, 3)
     self.assertEqual(type(self.d.attributes["bit"].typ), VInt)
     self.assertEqual(self.d.attributes["bit"].descriptor, "Desc")
     self.assertEqual(self.d.attributes["bit"].value, 3)
     self.assertEqual(self.d.attributes["bit"].alarm, Alarm.ok())
     self.assertEqual(self.d.attributes["bit"].timeStamp, 43.2)
示例#8
0
 def test_eq(self):
     ok = Alarm.ok()
     also_ok = Alarm(AlarmSeverity.noAlarm, AlarmStatus.noStatus, "No alarm")
     self.assertEqual(ok, also_ok)
示例#9
0
 def test_ok(self):
     ok = Alarm.ok()
     self.assertEqual(ok.status, AlarmStatus.noStatus)
     self.assertEqual(ok.severity, AlarmSeverity.noAlarm)
     self.assertEqual(ok.message, "No alarm")
示例#10
0
 def test_no_alarm(self):
     o = Alarm()
     assert o.severity == AlarmSeverity.NO_ALARM
     assert o.status == AlarmStatus.NO_STATUS
     assert o.message == ""
示例#11
0
 def test_bad_number(self):
     with self.assertRaises(ValueError):
         Alarm(33, 33, "")
示例#12
0
 def __next__(self):
     self.i += 1
     return Alarm(message=f"Alarm #{self.i}")
示例#13
0
 def __next__(self):
     self.i += 1
     return Alarm(message="Alarm #%s" % self.i)
示例#14
0
 def test_set_alarm(self):
     alarm = Alarm(AlarmSeverity.MAJOR_ALARM, AlarmStatus.DEVICE_STATUS,
                   "bad")
     self.o.set_alarm(alarm)
     assert self.o.alarm == alarm