def test_analog_write_can_only_be_done_by_registered_component( test_arduino: Arduino, ) -> None: test_arduino.analog_write(2, 0) test_arduino.register_component("component_id_1", pins=(Pin(2), )) test_arduino.analog_write(2, 1, token="component_id_1") with pytest.raises(ProtectedPinError): test_arduino.analog_write(2, 1) with pytest.raises(ProtectedPinError): test_arduino.analog_write(2, 1, token="component_id_2")
def test_pin_mode_can_only_be_done_by_registered_component( test_arduino: Arduino, ) -> None: test_arduino.pin_mode(0, INPUT) test_arduino.register_component("component_id_1", pins=(Pin(0), )) test_arduino.pin_mode(0, INPUT, token="component_id_1") with pytest.raises(ProtectedPinError): test_arduino.pin_mode(0, INPUT) with pytest.raises(ProtectedPinError): test_arduino.pin_mode(0, INPUT, token="component_id_2")
def test_digital_write_can_only_be_done_by_registered_component( test_arduino: Arduino, ) -> None: test_arduino.digital_write(0, HIGH) test_arduino.register_component("component_id_1", pins=(Pin(0), )) test_arduino.digital_write(0, HIGH, token="component_id_1") with pytest.raises(ProtectedPinError): test_arduino.digital_write(0, HIGH) with pytest.raises(ProtectedPinError): test_arduino.digital_write(0, HIGH, token="component_id_2")
def test_component_can_be_re_registered_after_being_deregistered( test_arduino: Arduino, ) -> None: test_arduino.register_component("component_id_1", pins=(Pin(0), Pin(1))) test_arduino.deregister_component("component_id_1") test_arduino.register_component("component_id_1", pins=(Pin(2), Pin(3)))
def test_pins_must_be_compatible_when_registering_an_analog_pin( test_arduino: Arduino, ) -> None: with pytest.raises(NotAnalogPinError): test_arduino.register_component("component_id_1", pins=(Pin(0, is_analog=True), ))
def test_pins_must_exist_for_component_to_exist(test_arduino: Arduino) -> None: with pytest.raises(PinDoesNotExistError): test_arduino.register_component("component_id_1", pins=(Pin(6), ))
def test_component_can_only_be_registered_once(test_arduino: Arduino) -> None: test_arduino.register_component("component_id_1", pins=(Pin(0), Pin(1))) with pytest.raises(ComponentAlreadyRegisteredError): test_arduino.register_component("component_id_1", pins=(Pin(2), Pin(3)))
def test_pins_cannot_be_registered_to_a_reserved_pin( test_arduino: Arduino) -> None: with pytest.raises(PinIsReservedForSerialCommsError): test_arduino.register_component("component_id_1", pins=(Pin(4), ))
def test_pins_cannot_be_reused(test_arduino: Arduino) -> None: test_arduino.register_component("component_id_1", pins=(Pin(0), Pin(1))) with pytest.raises(PinAlreadyRegisteredError): test_arduino.register_component("component_id_2", pins=(Pin(1), Pin(2)))