mirror of
https://github.com/bec-project/ophyd_devices.git
synced 2025-06-23 11:27:57 +02:00
refactor: cleanup and unifying galil classes
This commit is contained in:
30
tests/test_controller.py
Normal file
30
tests/test_controller.py
Normal file
@ -0,0 +1,30 @@
|
||||
from unittest import mock
|
||||
|
||||
from ophyd_devices.utils.controller import Controller
|
||||
|
||||
|
||||
def test_controller_off():
|
||||
controller = Controller(socket_cls=mock.MagicMock(), socket_host="dummy", socket_port=123)
|
||||
controller.on()
|
||||
with mock.patch.object(controller.sock, "close") as mock_close:
|
||||
controller.off()
|
||||
assert controller.sock is None
|
||||
assert controller.connected is False
|
||||
mock_close.assert_called_once()
|
||||
|
||||
# make sure it is indempotent
|
||||
controller.off()
|
||||
|
||||
|
||||
def test_controller_on():
|
||||
socket_cls = mock.MagicMock()
|
||||
Controller._controller_instances = {}
|
||||
controller = Controller(socket_cls=socket_cls, socket_host="dummy", socket_port=123)
|
||||
controller.on()
|
||||
assert controller.sock is not None
|
||||
assert controller.connected is True
|
||||
socket_cls().open.assert_called_once()
|
||||
|
||||
# make sure it is indempotent
|
||||
controller.on()
|
||||
socket_cls().open.assert_called_once()
|
@ -1,3 +1,5 @@
|
||||
from unittest import mock
|
||||
|
||||
import pytest
|
||||
from utils import SocketMock
|
||||
|
||||
@ -61,3 +63,129 @@ def test_axis_put(target_pos, socket_put_messages, socket_get_messages):
|
||||
leyey.controller.sock.buffer_recv = socket_get_messages
|
||||
leyey.user_setpoint.put(target_pos)
|
||||
assert leyey.controller.sock.buffer_put == socket_put_messages
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"axis_nr,direction,socket_put_messages,socket_get_messages",
|
||||
[
|
||||
(
|
||||
0,
|
||||
"forward",
|
||||
[
|
||||
b"naxis=0\r",
|
||||
b"ndir=1\r",
|
||||
b"XQ#NEWPAR\r",
|
||||
b"XQ#FES\r",
|
||||
b"MG_BGA\r",
|
||||
b"MGbcklact[axis]\r",
|
||||
b"MG_XQ0\r",
|
||||
b"MG_XQ2\r",
|
||||
b"MG _LRA, _LFA\r",
|
||||
],
|
||||
[
|
||||
b":",
|
||||
b":",
|
||||
b":",
|
||||
b":",
|
||||
b"0",
|
||||
b"0",
|
||||
b"-1",
|
||||
b"-1",
|
||||
b"1.000 0.000",
|
||||
],
|
||||
),
|
||||
(
|
||||
1,
|
||||
"reverse",
|
||||
[
|
||||
b"naxis=1\r",
|
||||
b"ndir=-1\r",
|
||||
b"XQ#NEWPAR\r",
|
||||
b"XQ#FES\r",
|
||||
b"MG_BGB\r",
|
||||
b"MGbcklact[axis]\r",
|
||||
b"MG_XQ0\r",
|
||||
b"MG_XQ2\r",
|
||||
b"MG _LRB, _LFB\r",
|
||||
],
|
||||
[
|
||||
b":",
|
||||
b":",
|
||||
b":",
|
||||
b":",
|
||||
b"0",
|
||||
b"0",
|
||||
b"-1",
|
||||
b"-1",
|
||||
b"0.000 1.000",
|
||||
],
|
||||
),
|
||||
],
|
||||
)
|
||||
def test_drive_axis_to_limit(axis_nr, direction, socket_put_messages, socket_get_messages):
|
||||
leyey = GalilMotor("A", name="leyey", host="mpc2680.psi.ch", port=8081, socket_cls=SocketMock)
|
||||
leyey.controller.on()
|
||||
leyey.controller.sock.flush_buffer()
|
||||
leyey.controller.sock.buffer_recv = socket_get_messages
|
||||
leyey.controller.drive_axis_to_limit(axis_nr, direction)
|
||||
assert leyey.controller.sock.buffer_put == socket_put_messages
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"axis_nr,socket_put_messages,socket_get_messages",
|
||||
[
|
||||
(
|
||||
0,
|
||||
[
|
||||
b"naxis=0\r",
|
||||
b"XQ#NEWPAR\r",
|
||||
b"XQ#FRM\r",
|
||||
b"MG_BGA\r",
|
||||
b"MGbcklact[axis]\r",
|
||||
b"MG_XQ0\r",
|
||||
b"MG_XQ2\r",
|
||||
b"MG axisref[0]\r",
|
||||
],
|
||||
[
|
||||
b":",
|
||||
b":",
|
||||
b":",
|
||||
b"0",
|
||||
b"0",
|
||||
b"-1",
|
||||
b"-1",
|
||||
b"1.00",
|
||||
],
|
||||
),
|
||||
(
|
||||
1,
|
||||
[
|
||||
b"naxis=1\r",
|
||||
b"XQ#NEWPAR\r",
|
||||
b"XQ#FRM\r",
|
||||
b"MG_BGB\r",
|
||||
b"MGbcklact[axis]\r",
|
||||
b"MG_XQ0\r",
|
||||
b"MG_XQ2\r",
|
||||
b"MG axisref[1]\r",
|
||||
],
|
||||
[
|
||||
b":",
|
||||
b":",
|
||||
b":",
|
||||
b"0",
|
||||
b"0",
|
||||
b"-1",
|
||||
b"-1",
|
||||
b"1.00",
|
||||
],
|
||||
),
|
||||
],
|
||||
)
|
||||
def test_find_reference(axis_nr, socket_put_messages, socket_get_messages):
|
||||
leyey = GalilMotor("A", name="leyey", host="mpc2680.psi.ch", port=8081, socket_cls=SocketMock)
|
||||
leyey.controller.on()
|
||||
leyey.controller.sock.flush_buffer()
|
||||
leyey.controller.sock.buffer_recv = socket_get_messages
|
||||
leyey.controller.find_reference(axis_nr)
|
||||
assert leyey.controller.sock.buffer_put == socket_put_messages
|
||||
|
@ -20,6 +20,7 @@ from ophyd_devices.smaract.smaract_ophyd import SmaractMotor
|
||||
],
|
||||
)
|
||||
def test_get_position(axis, position, get_message, return_msg):
|
||||
SmaractController._reset_controller()
|
||||
controller = SmaractController(socket_cls=SocketMock, socket_host="dummy", socket_port=123)
|
||||
controller.on()
|
||||
controller.sock.flush_buffer()
|
||||
@ -39,6 +40,7 @@ def test_get_position(axis, position, get_message, return_msg):
|
||||
],
|
||||
)
|
||||
def test_axis_is_referenced(axis, is_referenced, get_message, return_msg, exception):
|
||||
SmaractController._reset_controller()
|
||||
controller = SmaractController(socket_cls=SocketMock, socket_host="dummy", socket_port=123)
|
||||
controller.on()
|
||||
controller.sock.flush_buffer()
|
||||
@ -62,6 +64,7 @@ def test_axis_is_referenced(axis, is_referenced, get_message, return_msg, except
|
||||
],
|
||||
)
|
||||
def test_socket_put_and_receive_raises_exception(return_msg, exception, raised):
|
||||
SmaractController._reset_controller()
|
||||
controller = SmaractController(socket_cls=SocketMock, socket_host="dummy", socket_port=123)
|
||||
controller.on()
|
||||
controller.sock.flush_buffer()
|
||||
@ -87,6 +90,7 @@ def test_socket_put_and_receive_raises_exception(return_msg, exception, raised):
|
||||
],
|
||||
)
|
||||
def test_communication_mode(mode, get_message, return_msg):
|
||||
SmaractController._reset_controller()
|
||||
controller = SmaractController(socket_cls=SocketMock, socket_host="dummy", socket_port=123)
|
||||
controller.on()
|
||||
controller.sock.flush_buffer()
|
||||
@ -112,6 +116,7 @@ def test_communication_mode(mode, get_message, return_msg):
|
||||
],
|
||||
)
|
||||
def test_axis_is_moving(is_moving, get_message, return_msg):
|
||||
SmaractController._reset_controller()
|
||||
controller = SmaractController(socket_cls=SocketMock, socket_host="dummy", socket_port=123)
|
||||
controller.on()
|
||||
controller.sock.flush_buffer()
|
||||
@ -132,6 +137,7 @@ def test_axis_is_moving(is_moving, get_message, return_msg):
|
||||
],
|
||||
)
|
||||
def test_get_sensor_definition(sensor_id, axis, get_msg, return_msg):
|
||||
SmaractController._reset_controller()
|
||||
controller = SmaractController(socket_cls=SocketMock, socket_host="dummy", socket_port=123)
|
||||
controller.on()
|
||||
controller.sock.flush_buffer()
|
||||
@ -149,6 +155,7 @@ def test_get_sensor_definition(sensor_id, axis, get_msg, return_msg):
|
||||
],
|
||||
)
|
||||
def test_set_move_speed(move_speed, axis, get_msg, return_msg):
|
||||
SmaractController._reset_controller()
|
||||
controller = SmaractController(socket_cls=SocketMock, socket_host="dummy", socket_port=123)
|
||||
controller.on()
|
||||
controller.sock.flush_buffer()
|
||||
@ -166,6 +173,7 @@ def test_set_move_speed(move_speed, axis, get_msg, return_msg):
|
||||
],
|
||||
)
|
||||
def test_move_axis_to_absolute_position(pos, axis, hold_time, get_msg, return_msg):
|
||||
SmaractController._reset_controller()
|
||||
controller = SmaractController(socket_cls=SocketMock, socket_host="dummy", socket_port=123)
|
||||
controller.on()
|
||||
controller.sock.flush_buffer()
|
||||
@ -203,6 +211,7 @@ def test_move_axis_to_absolute_position(pos, axis, hold_time, get_msg, return_ms
|
||||
],
|
||||
)
|
||||
def test_move_axis(pos, get_msg, return_msg):
|
||||
SmaractController._reset_controller()
|
||||
lsmarA = SmaractMotor(
|
||||
"A",
|
||||
name="lsmarA",
|
||||
@ -230,6 +239,7 @@ def test_move_axis(pos, get_msg, return_msg):
|
||||
],
|
||||
)
|
||||
def test_stop_axis(num_axes, get_msg, return_msg):
|
||||
SmaractController._reset_controller()
|
||||
lsmarA = SmaractMotor(
|
||||
"A",
|
||||
name="lsmarA",
|
||||
|
Reference in New Issue
Block a user