tests: fixed errros with DataCollectionParameter assumptions in tests
This commit is contained in:
@@ -6,8 +6,12 @@ from aare.common.models import DataCollectionParameters
|
||||
|
||||
def test_directory_defaults_when_missing():
|
||||
params = DataCollectionParameters()
|
||||
assert params.directory == None
|
||||
#TODO What should the defaults be? Do we want it to be "{date}/{prefix}"?
|
||||
assert params.directory is None
|
||||
|
||||
|
||||
def test_directory_blank_defaults_to_macro_path():
|
||||
params = DataCollectionParameters(directory="")
|
||||
assert params.directory == "{date}/{prefix}"
|
||||
|
||||
|
||||
def test_directory_spaces_are_replaced():
|
||||
@@ -20,15 +24,16 @@ def test_directory_rejects_invalid_characters():
|
||||
DataCollectionParameters(directory="bad|path")
|
||||
|
||||
|
||||
def test_exposure_must_be_between_0_and_1():
|
||||
with pytest.raises(ValidationError):
|
||||
DataCollectionParameters(exposure=1.5)
|
||||
def test_exposure_accepts_values_above_1_after_refactor():
|
||||
params = DataCollectionParameters(exposure=1.5)
|
||||
assert params.exposure == 1.5
|
||||
|
||||
|
||||
def test_cloud_blank_defaults_to_true():
|
||||
params = DataCollectionParameters(cloud="")
|
||||
assert params.cloud is True
|
||||
|
||||
|
||||
def test_directory_accepts_valid_macros():
|
||||
params = DataCollectionParameters(directory="{date}/{prefix}/run")
|
||||
assert params.directory == "{date}/{prefix}/run"
|
||||
@@ -39,6 +44,6 @@ def test_aperture_accepts_float_string():
|
||||
assert params.aperture == 2
|
||||
|
||||
|
||||
def test_processingpipeline_rejects_unknown_value():
|
||||
with pytest.raises(ValidationError):
|
||||
DataCollectionParameters(processingpipeline="xia2")
|
||||
def test_processingpipeline_accepts_unknown_value_after_refactor():
|
||||
params = DataCollectionParameters(processingpipeline="xia2")
|
||||
assert params.processingpipeline == "xia2"
|
||||
@@ -5,46 +5,51 @@ from aare.common.beamline import MXBeamline
|
||||
from aare.common.coordinate import AerotechCoordinate, Coordinate
|
||||
from aare.common.exception_handler import AerotechCommunicationError
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def mock_aerotech_api():
|
||||
with patch('aarescan_client.ApiClient'), \
|
||||
patch('aarescan_client.DefaultApi') as mock_api_class, \
|
||||
patch('aarescan_client.Configuration'):
|
||||
patch('aarescan_client.DefaultApi') as mock_api_class, \
|
||||
patch('aarescan_client.Configuration'):
|
||||
mock_api = mock_api_class.return_value
|
||||
yield mock_api
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def aerotech_controller(mock_aerotech_api):
|
||||
# Set environment variable before initialization
|
||||
with patch.dict("os.environ", {"BEAMLINE": "X10SA"}):
|
||||
with patch("aare.devices.aerotech.cfg_get", return_value="http://mx-x10sa-queue-01.psi.ch:5234"):
|
||||
controller = AerotechController(MXBeamline.X10SA)
|
||||
|
||||
# Manually inject the mocked API into the controller's private attribute
|
||||
# This ensures that calls to self.__api go to our mock.
|
||||
|
||||
controller._AerotechController__api = mock_aerotech_api
|
||||
controller._AerotechController__simulated = False
|
||||
return controller
|
||||
|
||||
|
||||
def test_init_x10sa(mock_aerotech_api):
|
||||
controller = AerotechController(MXBeamline.X10SA)
|
||||
with patch("aare.devices.aerotech.cfg_get", return_value="http://mx-x10sa-queue-01.psi.ch:5234"):
|
||||
controller = AerotechController(MXBeamline.X10SA)
|
||||
assert controller._AerotechController__base == "http://mx-x10sa-queue-01.psi.ch:5234"
|
||||
assert controller._AerotechController__simulated is False
|
||||
|
||||
|
||||
def test_init_simulated():
|
||||
controller = AerotechController(MXBeamline.SIMULATED)
|
||||
assert controller._AerotechController__simulated is True
|
||||
|
||||
|
||||
def test_cancel(aerotech_controller, mock_aerotech_api):
|
||||
aerotech_controller.cancel()
|
||||
mock_aerotech_api.cancel_post.assert_called_once()
|
||||
|
||||
|
||||
def test_is_idle(aerotech_controller, mock_aerotech_api):
|
||||
mock_aerotech_api.status_get.return_value.state = 'Idle'
|
||||
assert aerotech_controller.is_idle() is True
|
||||
|
||||
|
||||
mock_aerotech_api.status_get.return_value.state = 'Busy'
|
||||
assert aerotech_controller.is_idle() is False
|
||||
|
||||
|
||||
def test_get_position(aerotech_controller, mock_aerotech_api):
|
||||
status = MagicMock()
|
||||
status.x.pos = 1.0
|
||||
@@ -52,35 +57,42 @@ def test_get_position(aerotech_controller, mock_aerotech_api):
|
||||
status.z.pos = 3.0
|
||||
status.u.pos = 90.0
|
||||
mock_aerotech_api.status_get.return_value = status
|
||||
|
||||
|
||||
pos = aerotech_controller.get_position()
|
||||
assert pos.at_mm.x == 1.0
|
||||
assert pos.at_mm.y == 2.0
|
||||
assert pos.at_mm.z == 3.0
|
||||
assert pos.omega_deg == 90.0
|
||||
|
||||
|
||||
def test_move_home(aerotech_controller, mock_aerotech_api):
|
||||
aerotech_controller.move_home()
|
||||
mock_aerotech_api.position_post.assert_called_once()
|
||||
|
||||
|
||||
def test_position(aerotech_controller, mock_aerotech_api):
|
||||
target = AerotechCoordinate(at_mm=Coordinate(x=1, y=2, z=3), omega_deg=45)
|
||||
aerotech_controller.position(target)
|
||||
mock_aerotech_api.position_post.assert_called_once()
|
||||
|
||||
|
||||
def test_rotation_scan(aerotech_controller, mock_aerotech_api):
|
||||
aerotech_controller.rotation_scan(rotation_deg=360, time_sec=10, start_pos_deg=0)
|
||||
mock_aerotech_api.rotation_scan_post.assert_called_once()
|
||||
|
||||
|
||||
def test_grid_scan(aerotech_controller, mock_aerotech_api):
|
||||
aerotech_controller.grid_scan(grid_elem_count_y=10, grid_elem_size_y_um=10, grid_elem_count_x=10, grid_elem_size_x_um=10, time_sec=5)
|
||||
aerotech_controller.grid_scan(grid_elem_count_y=10, grid_elem_size_y_um=10, grid_elem_count_x=10,
|
||||
grid_elem_size_x_um=10, time_sec=5)
|
||||
mock_aerotech_api.grid_scan_post.assert_called_once()
|
||||
|
||||
|
||||
def test_screening_scan(aerotech_controller, mock_aerotech_api):
|
||||
aerotech_controller.screening_scan(rotation_deg=10, wedge_deg=2, time_sec=1, steps=5)
|
||||
mock_aerotech_api.screening_post.assert_called_once()
|
||||
|
||||
|
||||
def test_api_error(aerotech_controller, mock_aerotech_api):
|
||||
mock_aerotech_api.status_get.side_effect = Exception("API Error")
|
||||
with pytest.raises(AerotechCommunicationError):
|
||||
aerotech_controller.is_idle()
|
||||
aerotech_controller.is_idle()
|
||||
@@ -45,7 +45,7 @@ def test_sample_queue_model_init(sample_list):
|
||||
model = SampleQueueSpreadsheet(samples=sample_list[:2])
|
||||
assert model.rowCount() == 2
|
||||
assert model.columnCount() == 3
|
||||
assert model.data(model.index(0, 0), Qt.ItemDataRole.DisplayRole) == "U1"
|
||||
assert model.data(model.index(0, 0), Qt.ItemDataRole.DisplayRole) == "D1"
|
||||
assert model.data(model.index(1, 2), Qt.ItemDataRole.DisplayRole) == "S2"
|
||||
|
||||
def test_sample_queue_model_update(sample_list):
|
||||
@@ -75,10 +75,10 @@ def test_sample_queue_model_set_running(sample_list):
|
||||
|
||||
def test_sample_queue_model_header(sample_list):
|
||||
model = SampleQueueSpreadsheet(samples=sample_list[:2])
|
||||
assert model.headerData(0, Qt.Orientation.Horizontal, Qt.ItemDataRole.DisplayRole) == "User"
|
||||
assert model.headerData(0, Qt.Orientation.Horizontal, Qt.ItemDataRole.DisplayRole) == "Dewar"
|
||||
assert model.headerData(1, Qt.Orientation.Vertical, Qt.ItemDataRole.DisplayRole) == "2"
|
||||
|
||||
def test_sample_queue_model_flags(sample_list):
|
||||
model = SampleQueueSpreadsheet(samples=sample_list[:2])
|
||||
flags = model.flags(model.index(0, 0))
|
||||
assert flags & Qt.ItemFlag.ItemIsDropEnabled
|
||||
assert flags & Qt.ItemFlag.ItemIsDropEnabled
|
||||
Reference in New Issue
Block a user