Skip to content
Snippets Groups Projects
Commit ec3ffa89 authored by Manon Blanco's avatar Manon Blanco
Browse files

Check unicity of transcription entities

parent db16ff3b
No related branches found
No related tags found
1 merge request!424Check unicity of transcription entities
Pipeline #139653 passed
......@@ -3,6 +3,7 @@
ElementsWorker methods for entities.
"""
from operator import itemgetter
from typing import Dict, List, Optional, TypedDict, Union
from peewee import IntegrityError
......@@ -273,6 +274,10 @@ class EntityMixin(object):
isinstance(confidence, float) and 0 <= confidence <= 1
), f"Entity at index {index} in entities: confidence should be None or a float in [0..1] range"
assert len(entities) == len(
set(map(itemgetter("offset", "length", "name", "type_id"), entities))
), "entities should be unique"
if self.is_read_only:
logger.warning(
"Cannot create transcription entities in bulk as this worker is in read-only mode"
......
......@@ -864,11 +864,34 @@ def test_create_transcription_entities_wrong_transcription(
)
@pytest.mark.parametrize("entities", (None, "not a list of entities", 1))
def test_create_transcription_entities_wrong_entities(mock_elements_worker, entities):
with pytest.raises(
AssertionError, match="entities shouldn't be null and should be of type list"
):
@pytest.mark.parametrize(
"entities, error",
(
(None, "entities shouldn't be null and should be of type list"),
(
"not a list of entities",
"entities shouldn't be null and should be of type list",
),
(1, "entities shouldn't be null and should be of type list"),
(
[
{
"name": "A",
"type_id": "12341234-1234-1234-1234-123412341234",
"offset": 0,
"length": 1,
"confidence": 0.5,
}
]
* 2,
"entities should be unique",
),
),
)
def test_create_transcription_entities_wrong_entities(
mock_elements_worker, entities, error
):
with pytest.raises(AssertionError, match=error):
mock_elements_worker.create_transcription_entities(
transcription=Transcription(id="transcription_id"),
entities=entities,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment