Skip to content

Commit

Permalink
fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vegano1 committed Aug 7, 2024
1 parent 69d3a58 commit 35b4a60
Showing 1 changed file with 21 additions and 21 deletions.
42 changes: 21 additions & 21 deletions api/tests/opentrons/drivers/absorbance_reader/test_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ def mock_device() -> MagicMock:


class MockErrorCode(Enum):
BYONOY_ERROR_NO_ERROR = "no_error"
BYONOY_ERROR = "error"
ERROR_NO_ERROR = "no_error"
ERROR = "error"


@pytest.fixture
Expand All @@ -50,20 +50,20 @@ async def test_driver_connect_disconnect(
mock_interface: MagicMock,
driver: AbsorbanceReaderDriver,
) -> None:
mock_interface.byonoy_open_device.return_value = (
MockErrorCode.BYONOY_ERROR_NO_ERROR,
mock_interface.open_device.return_value = (
MockErrorCode.ERROR_NO_ERROR,
1,
)

assert not await driver.is_connected()
await driver.connect()

mock_interface.byonoy_open_device.assert_called_once()
mock_interface.open_device.assert_called_once()
assert await driver.is_connected()
assert driver._connection._verify_device_handle()
assert driver._connection._device_handle == 1

mock_interface.byonoy_free_device.return_value = MockErrorCode.BYONOY_ERROR_NO_ERROR
mock_interface.free_device.return_value = MockErrorCode.ERROR_NO_ERROR
await driver.disconnect()

assert not await driver.is_connected()
Expand All @@ -80,14 +80,14 @@ async def test_driver_get_device_info(
DEVICE_INFO.sn = "SN: BYOMAA00013 REF: DE MAA 001"
DEVICE_INFO.version = "Absorbance V1.0.2 2024-04-18"

mock_interface.byonoy_get_device_information.return_value = (
MockErrorCode.BYONOY_ERROR_NO_ERROR,
mock_interface.get_device_information.return_value = (
MockErrorCode.ERROR_NO_ERROR,
DEVICE_INFO,
)

info = await connected_driver.get_device_info()

mock_interface.byonoy_get_device_information.assert_called_once()
mock_interface.get_device_information.assert_called_once()
assert info == {"serial": "BYOMAA00013", "model": "ABS96", "version": "v1.0.2"}


Expand All @@ -102,14 +102,14 @@ async def test_driver_get_lid_status(
module_status: AbsorbanceReaderLidStatus,
) -> None:

mock_interface.byonoy_get_device_parts_aligned.return_value = (
MockErrorCode.BYONOY_ERROR_NO_ERROR,
mock_interface.get_device_parts_aligned.return_value = (
MockErrorCode.ERROR_NO_ERROR,
parts_aligned,
)

status = await connected_driver.get_lid_status()

mock_interface.byonoy_get_device_parts_aligned.assert_called_once()
mock_interface.get_device_parts_aligned.assert_called_once()
assert status == module_status


Expand All @@ -118,16 +118,16 @@ async def test_driver_get_supported_wavelengths(
connected_driver: AbsorbanceReaderDriver,
) -> None:
SUPPORTED_WAVELENGTHS = [450, 500]
mock_interface.byonoy_abs96_get_available_wavelengths.return_value = (
MockErrorCode.BYONOY_ERROR_NO_ERROR,
mock_interface.abs96_get_available_wavelengths.return_value = (
MockErrorCode.ERROR_NO_ERROR,
SUPPORTED_WAVELENGTHS,
)

assert not connected_driver._connection._supported_wavelengths

wavelengths = await connected_driver.get_available_wavelengths()

mock_interface.byonoy_abs96_get_available_wavelengths.assert_called_once()
mock_interface.abs96_get_available_wavelengths.assert_called_once()
assert connected_driver._connection._supported_wavelengths == SUPPORTED_WAVELENGTHS
assert wavelengths == SUPPORTED_WAVELENGTHS

Expand All @@ -138,8 +138,8 @@ async def test_driver_initialize_and_read(
) -> None:
# set up mock interface
connected_driver._connection._supported_wavelengths = [450, 500]
mock_interface.byonoy_abs96_initialize_single_measurement.return_value = (
MockErrorCode.BYONOY_ERROR_NO_ERROR
mock_interface.abs96_initialize_single_measurement.return_value = (
MockErrorCode.ERROR_NO_ERROR
)
mock_interface.ByonoyAbs96SingleMeasurementConfig = MagicMock(
spec=AbsorbanceHidInterface.MeasurementConfig
Expand All @@ -151,18 +151,18 @@ async def test_driver_initialize_and_read(

conf = connected_driver._connection._current_config
assert conf and conf.sample_wavelength == 450
mock_interface.byonoy_abs96_initialize_single_measurement.assert_called_once_with(
mock_interface.abs96_initialize_single_measurement.assert_called_once_with(
1, conf
)

# setup up mock interface
MEASURE_RESULT = [0.1] * 96
mock_interface.byonoy_abs96_single_measure.return_value = (
MockErrorCode.BYONOY_ERROR_NO_ERROR,
mock_interface.abs96_single_measure.return_value = (
MockErrorCode.ERROR_NO_ERROR,
MEASURE_RESULT,
)

result = await connected_driver.get_single_measurement(450)
mock_interface.byonoy_abs96_single_measure.assert_called_once_with(1, conf)
mock_interface.abs96_single_measure.assert_called_once_with(1, conf)

assert result == MEASURE_RESULT

0 comments on commit 35b4a60

Please sign in to comment.