refactor: add configurable timeout and ClassInitError

This commit is contained in:
2023-11-12 16:41:08 +01:00
parent c6e6737547
commit a7d713b50d
6 changed files with 32 additions and 22 deletions

View File

@ -105,6 +105,7 @@ def test_init_detector(
mock_det.cam.detector_state._read_pv.mock_data = detector_state
if expected_exception:
with pytest.raises(Exception):
mock_det.timeout = 0.1
mock_det._init_detector()
else:
mock_det._init_detector() # call the method you want to test
@ -183,6 +184,7 @@ def test_init_filewriter(mock_det, eacc, exp_url, daq_status, daq_cfg, expected_
# scaninfo.username.return_value = eacc
if expected_exception:
with pytest.raises(Exception):
mock_det.timeout = 0.1
mock_det._init_filewriter()
else:
mock_det._init_filewriter()
@ -270,6 +272,7 @@ def test_stage(
mock_det.filepath = scaninfo["filepath"]
if expected_exception:
with pytest.raises(Exception):
mock_det.timeout = 0.1
mock_det.stage()
else:
mock_det.stage()
@ -340,6 +343,7 @@ def test_prep_file_writer(mock_det, scaninfo, daq_status, expected_exception):
if expected_exception:
with pytest.raises(Exception):
mock_det.timeout = 0.1
mock_det._prep_file_writer()
mock_file_path_exists.assert_called_once()
assert mock_stop_file_writer.call_count == 2
@ -494,6 +498,7 @@ def test_finished(mock_det, stopped, cam_state, daq_status, scaninfo, expected_e
mock_det.scaninfo.frames_per_trigger = scaninfo["frames_per_trigger"]
if expected_exception:
with pytest.raises(Exception):
mock_det.timeout = 0.1
mock_det._finished()
assert mock_det._stopped == stopped
mock_stop_file_friter.assert_called()

View File

@ -75,6 +75,7 @@ def test_init_detector(
mock_det.state._read_pv.mock_data = detector_state
if expected_exception:
with pytest.raises(FalconTimeoutError):
mock_det.timeout = 0.1
mock_det._init_detector()
else:
mock_det._init_detector() # call the method you want to test
@ -241,6 +242,7 @@ def test_arm_acquisition(mock_det, detector_state, expected_exception):
mock_det.state._read_pv.mock_data = detector_state
if expected_exception:
with pytest.raises(FalconTimeoutError):
mock_det.timeout = 0.1
mock_det._arm_acquisition()
mock_stop.assert_called_once()
else:

View File

@ -120,6 +120,7 @@ def test_stage(
mock_det.filepath = scaninfo["filepath"]
if expected_exception:
with pytest.raises(Exception):
mock_det.timeout = 0.1
mock_det.stage()
else:
mock_det.stage()
@ -241,6 +242,7 @@ def test_stop_file_writer(mock_det, requests_state, expected_exception, url):
instance.raise_for_status.side_effect = Exception
if expected_exception:
with pytest.raises(Exception):
mock_det.timeout = 0.1
mock_det._stop_file_writer()
mock_send_requests_put.assert_called_once_with(url=url)
instance.raise_for_status.called_once()
@ -376,6 +378,7 @@ def test_prep_file_writer(mock_det, scaninfo, data_msgs, urls, requests_state, e
if expected_exception:
with pytest.raises(Exception):
mock_det.timeout = 0.1
mock_det._prep_file_writer()
mock_close_file_writer.assert_called_once()
mock_stop_file_writer.assert_called_once()
@ -490,6 +493,7 @@ def test_finished(mock_det, stopped, mcs_stage_state, expected_exception):
mock_det._stopped = stopped
if expected_exception:
with pytest.raises(Exception):
mock_det.timeout = 0.1
mock_det._finished()
assert mock_det._stopped == stopped
mock_stop_file_friter.assert_called()