def test_backend_get_button_state() -> None: """Test that we can get the button state.""" device = MockUSBPowerBoardDevice("SERIAL0") backend = SRV4PowerBoardHardwareBackend(device) assert not backend.get_button_state(0) with pytest.raises(ValueError): backend.get_button_state(1)
def test_backend_get_battery_sensor_current() -> None: """Test that we can get the battery sensor current.""" device = MockUSBPowerBoardDevice("SERIAL0") backend = SRV4PowerBoardHardwareBackend(device) assert backend.get_battery_sensor_current(0) == 0.567 with pytest.raises(ValueError): backend.get_battery_sensor_current(1)
def test_backend_get_battery_sensor_voltage(): """Test that we can get the battery sensor voltage.""" device = MockUSBPowerBoardDevice("SERIAL0") backend = SRV4PowerBoardHardwareBackend(device) assert backend.get_battery_sensor_voltage(MockBoard(), 0) == 0.982 with pytest.raises(ValueError): backend.get_battery_sensor_voltage(MockBoard(), 1)
def test_backend_get_led_states() -> None: """Get the LED states.""" device = MockUSBPowerBoardDevice("SERIAL0") backend = SRV4PowerBoardHardwareBackend(device) assert not any([backend.get_led_state(i) for i in [0, 1]]) # noqa: C407 with pytest.raises(KeyError): backend.get_led_state(7)
def test_backend_get_power_output_current() -> None: """Test that we can read the current on a PowerOutput.""" device = MockUSBPowerBoardDevice("SERIAL0") backend = SRV4PowerBoardHardwareBackend(device) for i in range(0, 6): assert 1.2 == backend.get_power_output_current(i) with pytest.raises(ValueError): backend.get_power_output_current(6)
def test_backend_set_power_output_enabled() -> None: """Test that we can read the enable status of a PowerOutput.""" device = MockUSBPowerBoardDevice("SERIAL0") backend = SRV4PowerBoardHardwareBackend(device) for i in range(0, 6): backend.set_power_output_enabled(i, True) with pytest.raises(ValueError): backend.set_power_output_enabled(6, True)
def test_backend_get_power_output_enabled(): """Test that we can read the enable status of a PowerOutput.""" device = MockUSBPowerBoardDevice("SERIAL0") backend = SRV4PowerBoardHardwareBackend(device) for i in range(0, 6): assert not backend.get_power_output_enabled(MockBoard(), i) with pytest.raises(ValueError): backend.get_power_output_enabled(MockBoard(), 6)
def test_backend_set_led_states() -> None: """Set the LED states.""" device = MockUSBPowerBoardDevice("SERIAL0") backend = SRV4PowerBoardHardwareBackend(device) for i in [0, 1]: backend.set_led_state(i, True) with pytest.raises(ValueError): backend.set_led_state(8, True)
def test_backend_initialisation() -> None: """Test that we can initialise a Backend.""" device = MockUSBPowerBoardDevice("SERIAL0") backend = SRV4PowerBoardHardwareBackend(device) assert type(backend) is SRV4PowerBoardHardwareBackend assert backend._usb_device is device assert len(backend._output_states) == 6 assert not any(backend._output_states.values()) # Check initially all false. assert len(backend._led_states) == 2 assert not any(backend._led_states.values()) # Check initially all false.
def test_backend_piezo_buzz(): """Test that we can buzz the Piezo.""" device = MockUSBPowerBoardDevice("SERIAL0") backend = SRV4PowerBoardHardwareBackend(device) # Buzz a Note backend.buzz(MockBoard(), 0, timedelta(seconds=10), Note.D7) # Buzz a frequency backend.buzz(MockBoard(), 0, timedelta(seconds=10), 100) # Buzz for too long. with pytest.raises(ValueError): backend.buzz(MockBoard(), 0, timedelta(seconds=100), 10) # Test non-existent buzzer with pytest.raises(ValueError): backend.buzz(MockBoard(), 1, timedelta(seconds=10), 0)
def test_backend_piezo_buzz() -> None: """Test that we can buzz the Piezo.""" device = MockUSBPowerBoardDevice("SERIAL0") backend = SRV4PowerBoardHardwareBackend(device) # Buzz a Note backend.buzz(0, timedelta(seconds=10), Note.D7) # Buzz a frequency backend.buzz(0, timedelta(seconds=10), 100) # Buzz for too long. with pytest.raises(NotSupportedByHardwareError): backend.buzz(0, timedelta(seconds=100), 10) # Buzz at a too high pitch. with pytest.raises(NotSupportedByHardwareError): backend.buzz(0, timedelta(seconds=10), 65536) # Test non-existent buzzer with pytest.raises(ValueError): backend.buzz(1, timedelta(seconds=10), 0)
def test_backend_serial_number() -> None: """Test that we can get the serial number.""" device = MockUSBPowerBoardDevice("SERIAL0") backend = SRV4PowerBoardHardwareBackend(device) assert backend.serial == "SERIAL0"
def test_backend_firmware_version() -> None: """Test that we can get the firmware version.""" device = MockUSBPowerBoardDevice("SERIAL0") backend = SRV4PowerBoardHardwareBackend(device) assert backend.firmware_version == "3"
def test_backend_cleanup() -> None: """Test that the backend cleans things up properly.""" device = MockUSBPowerBoardDevice("SERIAL0") backend = SRV4PowerBoardHardwareBackend(device) del backend
def test_backend_discover() -> None: """Test that the backend can discover boards.""" found_boards = SRV4PowerBoardHardwareBackend.discover(find=mock_find) assert len(found_boards) == 4 assert all(type(board) is PowerBoard for board in found_boards)
def test_backend_bad_firmware_version() -> None: """Test that we can get the firmware version.""" device = MockUSBPowerBoardDevice("SERIAL0", fw_version=2) with pytest.raises(NotImplementedError): SRV4PowerBoardHardwareBackend(device)
def test_backend_discover(): """Test that the backend can discover boards.""" found_boards = SRV4PowerBoardHardwareBackend.discover(find=mock_find) assert len(found_boards) == 4 assert type(found_boards[0]) is PowerBoard