Ejemplo n.º 1
0
def test_motor_get_state_float() -> None:
    """Test that we can get the state of a motor."""
    motor0 = Motor(0, MockMotorDriver())
    motor1 = Motor(1, MockMotorDriver())

    assert type(motor0.power) is float
    assert type(motor1.power) is float

    assert motor0.power == 0
    assert motor1.power == 0.5
Ejemplo n.º 2
0
def test_motor_get_state_special() -> None:
    """Test that we can get the special state of a motor."""
    motor0 = Motor(2, MockMotorDriver())
    motor1 = Motor(3, MockMotorDriver())

    assert type(motor0.power) is MotorSpecialState
    assert type(motor1.power) is MotorSpecialState

    assert motor0.power == MotorSpecialState.COAST
    assert motor1.power == MotorSpecialState.BRAKE
Ejemplo n.º 3
0
    def __init__(self, serial: str, backend: Backend):
        self._serial = serial
        self._backend = backend

        self._outputs: List[Motor] = [
            Motor(output, cast(MotorInterface, self._backend))
            for output in range(0, 2)
        ]
Ejemplo n.º 4
0
    def __init__(
        self,
        serial: str,
        backend: Backend,
        *,
        safe_state: MotorState = MotorSpecialState.BRAKE,
    ):
        self._serial = serial
        self._backend = backend
        self._safe_state = safe_state

        self._outputs = ImmutableList[Motor](
            Motor(output, cast(MotorInterface, self._backend))
            for output in range(0, 2))
Ejemplo n.º 5
0
def test_motor_set_state() -> None:
    """Test that we can set the state of a motor."""
    motor = Motor(0, MockMotorDriver())

    motor.power = 0
    motor.power = 1
    motor.power = -1
    motor.power = 0.123

    motor.power = MotorSpecialState.COAST
    motor.power = MotorSpecialState.BRAKE
Ejemplo n.º 6
0
def test_motor_set_state_out_of_bounds() -> None:
    """Test that an error is thrown when the state is out of bounds."""
    motor = Motor(0, MockMotorDriver())

    with pytest.raises(ValueError):
        motor.power = 2
    with pytest.raises(ValueError):
        motor.power = 1.1
    with pytest.raises(ValueError):
        motor.power = -3
    with pytest.raises(ValueError):
        motor.power = -1.2
Ejemplo n.º 7
0
def test_motor_identifier() -> None:
    """Test the identifier attribute of the component."""
    component = Motor(0, MockMotorDriver())
    assert component.identifier == 0
Ejemplo n.º 8
0
def test_motor_instantiation() -> None:
    """Test that we can instantiate a Motor."""
    Motor(0, MockMotorDriver())
Ejemplo n.º 9
0
def test_motor_interface_class() -> None:
    """Test that the interface class is MotorInterface."""
    assert Motor.interface_class() is MotorInterface