diff --git a/workers/annotations/connect_timelapse/entrypoint.py b/workers/annotations/connect_timelapse/entrypoint.py index 75bdc6e..a09b486 100644 --- a/workers/annotations/connect_timelapse/entrypoint.py +++ b/workers/annotations/connect_timelapse/entrypoint.py @@ -170,14 +170,16 @@ def compute(datasetId, apiUrl, token, params): assignment, channel, connectTo, tags, tile, workerInterface = itemgetter( *keys)(params) - object_tag = list(set(workerInterface.get('Object to connect tag', None))) + object_tags_raw = workerInterface.get('Object to connect tag', None) + if not object_tags_raw or len(object_tags_raw) == 0: + sendError("No object tag specified", + info="Please specify an 'Object to connect tag' in the worker interface") + return + + object_tag = list(set(object_tags_raw)) max_distance = float(workerInterface['Max distance']) gap_size = int(workerInterface['Connect across gaps']) - if not object_tag or len(object_tag) == 0: - sendError("No object tag specified") - raise ValueError("No object tag specified") - print( f"Connecting {object_tag} objects across {gap_size} time slices " f"with a max distance of {max_distance} pixels") diff --git a/workers/annotations/connect_timelapse/tests/test_connect_timelapse.py b/workers/annotations/connect_timelapse/tests/test_connect_timelapse.py index 62e997a..05034d6 100644 --- a/workers/annotations/connect_timelapse/tests/test_connect_timelapse.py +++ b/workers/annotations/connect_timelapse/tests/test_connect_timelapse.py @@ -167,14 +167,55 @@ def test_basic_compute(mock_get_annotations, mock_send_progress, mock_annotation assert all('tags' in conn for conn in connections) -def test_compute_no_object_tag(mock_annotation_client, sample_params): - """Test error handling when no object tag is specified""" - # Remove object tag from params +@patch('entrypoint.sendError') +def test_compute_no_object_tag_empty_list(mock_send_error, mock_annotation_client, sample_params): + """Test error handling when object tag is an empty list""" + # Set object tag to empty list sample_params['workerInterface']['Object to connect tag'] = [] - # Should raise ValueError - with pytest.raises(ValueError, match="No object tag specified"): - compute('test_dataset', 'http://test-api', 'test-token', sample_params) + # Should call sendError and return gracefully + compute('test_dataset', 'http://test-api', 'test-token', sample_params) + + mock_send_error.assert_called_once_with( + "No object tag specified", + info="Please specify an 'Object to connect tag' in the worker interface" + ) + # Should not proceed to fetch annotations + mock_annotation_client.getAnnotationsByDatasetId.assert_not_called() + + +@patch('entrypoint.sendError') +def test_compute_no_object_tag_none(mock_send_error, mock_annotation_client, sample_params): + """Test error handling when object tag is None""" + # Set object tag to None + sample_params['workerInterface']['Object to connect tag'] = None + + # Should call sendError and return gracefully + compute('test_dataset', 'http://test-api', 'test-token', sample_params) + + mock_send_error.assert_called_once_with( + "No object tag specified", + info="Please specify an 'Object to connect tag' in the worker interface" + ) + # Should not proceed to fetch annotations + mock_annotation_client.getAnnotationsByDatasetId.assert_not_called() + + +@patch('entrypoint.sendError') +def test_compute_no_object_tag_missing_key(mock_send_error, mock_annotation_client, sample_params): + """Test error handling when Object to connect tag key is missing from workerInterface""" + # Remove the key entirely + del sample_params['workerInterface']['Object to connect tag'] + + # Should call sendError and return gracefully + compute('test_dataset', 'http://test-api', 'test-token', sample_params) + + mock_send_error.assert_called_once_with( + "No object tag specified", + info="Please specify an 'Object to connect tag' in the worker interface" + ) + # Should not proceed to fetch annotations + mock_annotation_client.getAnnotationsByDatasetId.assert_not_called() @patch('annotation_client.utils.sendProgress')