Exemplo n.º 1
0
 def test_notify(self):
     hardware_device = Mock()
     hardware_device.read = Mock(return_value=0)
     sensor_group = DigitalSensorGroup(1, hardware_device)
     sensor = DigitalSensor("test", sensor_group, 0)
     assert sensor.state == DigitalSensor.HIGH
     hardware_device.read = Mock(return_value=1)
     sensor_group.notify(self)
     assert sensor.state == DigitalSensor.LOW
Exemplo n.º 2
0
    def test_observer(self):
        hardware_device = Mock()
        hardware_device.read = Mock(return_value=0)
        observer = Mock()
        sensor_group = DigitalSensorGroup(8, hardware_device)
        sensor_group.register_observer(observer, 0)
        sensor_group.notify(hardware_device)
        sensor_group._get_state(0)

        hardware_device.read = Mock(return_value=1)
        sensor_group.notify(hardware_device)
        sensor_group._get_state(0)
        observer.notify.assert_called_once_with(sensor_group)
        observer.notify.reset_mock()

        hardware_device.read = Mock(return_value=4)
        sensor_group.notify(hardware_device)
        sensor_group._get_state(0)

        hardware_device.read = Mock(return_value=5)
        sensor_group.notify(hardware_device)
        sensor_group._get_state(0)

        hardware_device.read = Mock(return_value=7)
        sensor_group.notify(hardware_device)
        sensor_group._get_state(0)
        observer.notify.assert_called_once_with(sensor_group)
        observer.notify.reset_mock()