59 lines
1.7 KiB
Python
59 lines
1.7 KiB
Python
from copy import copy
|
|
from threading import RLock
|
|
from unittest.mock import ANY
|
|
|
|
import pytest
|
|
|
|
|
|
class MockServer:
|
|
def __init__(self) -> None:
|
|
self.lock = RLock()
|
|
self.mock_data = {
|
|
"x": {"pos": 1.0},
|
|
"y": {"pos": 1.0},
|
|
"z": {"pos": 1.0},
|
|
"u": {"pos": 1.0},
|
|
"vel_u_deg_s": {"pos": 1.0},
|
|
}
|
|
|
|
def get(self, endpoint):
|
|
with self.lock:
|
|
return copy(self.mock_data)
|
|
|
|
def put(self, params: dict | None = None, body: dict | None = None):
|
|
with self.lock:
|
|
assert body is not None
|
|
for k, v in body.items():
|
|
self.mock_data[k]["pos"] = v
|
|
|
|
|
|
@pytest.fixture
|
|
def aerotech():
|
|
mock_server = MockServer()
|
|
from pxii_bec.devices.aerotech import Aerotech
|
|
|
|
s = Aerotech(name="aerotech", prefix="http://test-aerotech.psi.ch")
|
|
s.controller._rest_get = mock_server.get
|
|
s.controller._rest_post = mock_server.put
|
|
yield s
|
|
s.controller._stop_monitor_readback_event.set()
|
|
|
|
|
|
class TestAerotech:
|
|
def test_aerotech_read(self, aerotech):
|
|
aerotech.wait_for_connection()
|
|
reading = aerotech.read()
|
|
assert dict(reading) == {
|
|
"aerotech_x": {"value": 1.0, "timestamp": ANY},
|
|
"aerotech_y": {"value": 1.0, "timestamp": ANY},
|
|
"aerotech_z": {"value": 1.0, "timestamp": ANY},
|
|
"aerotech_u": {"value": 1.0, "timestamp": ANY},
|
|
"aerotech_vel_u_deg_s": {"value": 1.0, "timestamp": ANY},
|
|
}
|
|
|
|
def test_aerotech_set_with_status(self, aerotech):
|
|
aerotech.wait_for_connection()
|
|
st = aerotech.x.set(5.0)
|
|
st.wait(timeout=1)
|
|
assert aerotech.x.get() == 5.0
|