Skip to content

Commit

Permalink
Add some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
GDYendell committed Aug 19, 2024
1 parent ddd9e7e commit f37ad65
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
9 changes: 9 additions & 0 deletions tests/system/test_introspection.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
from time import sleep

import pytest
from fastcs.attributes import AttrR
from fastcs.datatypes import Float

from eiger_fastcs.eiger_controller import EigerController, EigerParameter

Expand Down Expand Up @@ -78,4 +80,11 @@ async def test_introspection(sim_eiger_controller: EigerController):

assert parameters == expected_parameters, "Detector API does not match"

attributes = controller._create_attributes(_parameters)

assert len(attributes) == 91
assert isinstance(attributes["humidity"], AttrR)
assert isinstance(attributes["humidity"].datatype, Float)
assert attributes["humidity"]._group == "DetectorStatus"

await controller.connection.close()
45 changes: 45 additions & 0 deletions tests/test_controller.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import pytest
from pytest_mock import MockerFixture

from eiger_fastcs.eiger_controller import EigerController


@pytest.mark.asyncio
async def test_initialise(mocker: MockerFixture):
controller = EigerController("127.0.0.1", 80)

connection = mocker.patch.object(controller, "connection")
connection.get = mocker.AsyncMock()
connection.get.return_value = {"value": "idle"}
initialize = mocker.patch.object(controller, "initialize")
introspect = mocker.patch.object(controller, "_introspect_detector")
create_attributes = mocker.patch.object(controller, "_create_attributes")
attr = mocker.MagicMock()
create_attributes.return_value = {"attr_name": attr}

await controller.initialise()

connection.get.assert_called_once_with("detector/api/1.8.0/status/state")
initialize.assert_not_called()
introspect.assert_awaited_once_with()
create_attributes.assert_called_once_with(introspect.return_value)
assert controller.attr_name == attr, "Attribute not added to controller"


@pytest.mark.asyncio
async def test_initialise_state_na(mocker: MockerFixture):
controller = EigerController("127.0.0.1", 80)

connection = mocker.patch.object(controller, "connection")
connection.get = mocker.AsyncMock()
connection.get.return_value = {"value": "na"}
initialize = mocker.patch.object(controller, "initialize")
introspect = mocker.patch.object(controller, "_introspect_detector")
create_attributes = mocker.patch.object(controller, "_create_attributes")

await controller.initialise()

connection.get.assert_called_once_with("detector/api/1.8.0/status/state")
initialize.assert_awaited_once_with()
introspect.assert_awaited_once_with()
create_attributes.assert_called_once_with(introspect.return_value)

0 comments on commit f37ad65

Please sign in to comment.