Ejemplo n.º 1
0
 def test_set_state(self):
     relay_group = RelayGroup(2)
     relay0 = Relay('relay0', relay_group, 0)
     relay1 = Relay('relay1', relay_group, 1)
     assert relay0.state == Relay.OPEN
     assert relay1.state == Relay.OPEN
     relay0.state = Relay.CLOSED
     assert relay0.state == Relay.CLOSED
     assert relay1.state == Relay.OPEN
     relay1.state = Relay.CLOSED
     assert relay0.state == Relay.CLOSED
     assert relay1.state == Relay.CLOSED
Ejemplo n.º 2
0
    def test_write_states(self):
        hardware_device = Mock()
        relay_group = RelayGroup(8, hardware_device)
        relay0 = Relay('relay0', relay_group, 0)
        relay1 = Relay('relay1', relay_group, 1)
        relay2 = Relay('relay2', relay_group, 2)

        relay0.close()
        hardware_device.write.assert_called_with(1)
        relay1.close()
        hardware_device.write.assert_called_with(3)
        relay2.close()
        hardware_device.write.assert_called_with(7)
        relay1.open()
        hardware_device.write.assert_called_with(5)