From 7a9e5d8164014abaf1485f5b90f0e99a0f159d06 Mon Sep 17 00:00:00 2001
From: Erwan Rouchet <rouchet@teklia.com>
Date: Tue, 24 Nov 2020 16:49:38 +0100
Subject: [PATCH] Deprecate TranscriptionType

---
 arkindex_worker/reporting.py  |  36 +++++++----
 arkindex_worker/worker.py     |  52 +++++++++++----
 tests/test_elements_worker.py | 117 ++++++++++------------------------
 tests/test_reporting.py       |  68 ++++++++++++++------
 4 files changed, 143 insertions(+), 130 deletions(-)

diff --git a/arkindex_worker/reporting.py b/arkindex_worker/reporting.py
index 1f0736f1..caa80aaf 100644
--- a/arkindex_worker/reporting.py
+++ b/arkindex_worker/reporting.py
@@ -1,6 +1,7 @@
 # -*- coding: utf-8 -*-
 import json
 import traceback
+import warnings
 from collections import Counter
 from datetime import datetime
 
@@ -30,8 +31,8 @@ class Reporter(object):
                 "started": datetime.utcnow().isoformat(),
                 # Created element counts, by type slug
                 "elements": {},
-                # Created transcription counts, by type
-                "transcriptions": {},
+                # Created transcriptions count
+                "transcriptions": 0,
                 # Created classification counts, by class
                 "classifications": {},
                 # Created entities ({"id": "", "type": "", "name": ""}) from this element
@@ -80,26 +81,35 @@ class Reporter(object):
         )
         element["classifications"] = dict(counter)
 
-    def add_transcription(self, element_id, type, type_count=1):
+    def add_transcription(self, element_id, type=None, type_count=None):
         """
         Report creating a transcription on an element.
-        Multiple transcriptions with the same type and parent can be declared with the type_count parameter.
+        Multiple transcriptions with the same parent can be declared with the type_count parameter.
         """
-        transcriptions = self._get_element(element_id)["transcriptions"]
-        transcriptions.setdefault(type, 0)
-        transcriptions[type] += type_count
+        if type_count is None:
+            if isinstance(type, int):
+                type_count, type = type, None
+            else:
+                type_count = 1
+
+        if type is not None:
+            warnings.warn(
+                "Transcription types have been deprecated and will be removed in the next release.",
+                FutureWarning,
+            )
+
+        self._get_element(element_id)["transcriptions"] += type_count
 
     def add_transcriptions(self, element_id, transcriptions):
         """
         Report one or more transcriptions at once.
         """
         assert isinstance(transcriptions, list), "A list is required for transcriptions"
-        element = self._get_element(element_id)
-        # Retrieve the previous existing transcription counts, if any
-        counter = Counter(**element["transcriptions"])
-        # Add the new ones
-        counter.update([transcription["type"] for transcription in transcriptions])
-        element["transcriptions"] = dict(counter)
+        warnings.warn(
+            "Reporter.add_transcriptions is deprecated due to transcription types being removed. Please use Reporter.add_transcription(element_id, count) instead.",
+            FutureWarning,
+        )
+        self.add_transcription(element_id, len(transcriptions))
 
     def add_entity(self, element_id, entity_id, type, name):
         """
diff --git a/arkindex_worker/worker.py b/arkindex_worker/worker.py
index 7e7dfb37..6a089f1c 100644
--- a/arkindex_worker/worker.py
+++ b/arkindex_worker/worker.py
@@ -5,6 +5,7 @@ import logging
 import os
 import sys
 import uuid
+import warnings
 from enum import Enum
 from pathlib import Path
 
@@ -366,22 +367,36 @@ class ElementsWorker(BaseWorker):
 
         return sub_element["id"]
 
-    def create_transcription(self, element, text, type, score):
+    def create_transcription(self, element, text, type=None, score=None):
         """
-        Create a transcription on the given element through API
+        Create a transcription on the given element through the API.
+
+        Transcription types are deprecated; please call this method using
+        `create_transcription(element, text, score)` instead of
+        `create_transcription(element, text, type, score)`.
         """
         assert element and isinstance(
             element, Element
         ), "element shouldn't be null and should be of type Element"
-        assert type and isinstance(
-            type, TranscriptionType
-        ), "type shouldn't be null and should be of type TranscriptionType"
         assert text and isinstance(
             text, str
         ), "text shouldn't be null and should be of type str"
+
+        # When score is not set and type is not a transcription type, grab the score from `type`.
+        # Allows create_transcription(element, text, score) and (element, text, type, score)
+        # for forwards compatibility after transcription types get deleted.
+        if score is None and not isinstance(type, TranscriptionType):
+            score, type = type, None
+        elif isinstance(type, TranscriptionType):
+            warnings.warn(
+                "Transcription types are deprecated and will be removed in the next release.",
+                FutureWarning,
+            )
+
         assert (
             isinstance(score, float) and 0 <= score <= 1
         ), "score shouldn't be null and should be a float in [0..1] range"
+
         if self.is_read_only:
             logger.warning(
                 "Cannot create transcription as this worker is in read-only mode"
@@ -393,12 +408,11 @@ class ElementsWorker(BaseWorker):
             id=element.id,
             body={
                 "text": text,
-                "type": type.value,
                 "worker_version": self.worker_version_id,
                 "score": score,
             },
         )
-        self.report.add_transcription(element.id, type.value)
+        self.report.add_transcription(element.id)
 
     def create_classification(
         self, element, ml_class, confidence, high_confidence=False
@@ -495,10 +509,14 @@ class ElementsWorker(BaseWorker):
         return entity["id"]
 
     def create_element_transcriptions(
-        self, element, sub_element_type, transcription_type, transcriptions
+        self, element, sub_element_type, transcription_type=None, transcriptions=None
     ):
         """
         Create multiple sub elements with their transcriptions on the given element through API
+
+        Transcription types are deprecated; please call this method using
+        `create_element_transcriptions(element, sub_element_type, transcriptions)` instead of
+        `create_element_transcriptions(element, sub_element_type, transcription_type, transcriptions)`.
         """
         assert element and isinstance(
             element, Element
@@ -506,9 +524,20 @@ class ElementsWorker(BaseWorker):
         assert sub_element_type and isinstance(
             sub_element_type, str
         ), "sub_element_type shouldn't be null and should be of type str"
-        assert transcription_type and isinstance(
+
+        # When transcriptions are not set and transcription_type is not a valid transcription type,
+        # take transcriptions from `transcription_type`.
+        # Allows for forwards compatibility after transcription types get deleted.
+        if transcriptions is None and not isinstance(
             transcription_type, TranscriptionType
-        ), "transcription_type shouldn't be null and should be of type TranscriptionType"
+        ):
+            transcriptions, transcription_type = transcription_type, None
+        elif isinstance(transcription_type, TranscriptionType):
+            warnings.warn(
+                "Transcription types are deprecated and will be removed in the next release.",
+                FutureWarning,
+            )
+
         assert transcriptions and isinstance(
             transcriptions, list
         ), "transcriptions shouldn't be null and should be of type list"
@@ -548,7 +577,6 @@ class ElementsWorker(BaseWorker):
             id=element.id,
             body={
                 "element_type": sub_element_type,
-                "transcription_type": transcription_type.value,
                 "worker_version": self.worker_version_id,
                 "transcriptions": transcriptions,
                 "return_elements": True,
@@ -560,7 +588,7 @@ class ElementsWorker(BaseWorker):
                     f"A sub_element of {element.id} with type {sub_element_type} was created during transcriptions bulk creation"
                 )
                 self.report.add_element(element.id, sub_element_type)
-            self.report.add_transcription(annotation["id"], transcription_type.value)
+            self.report.add_transcription(annotation["id"])
 
         return annotations
 
diff --git a/tests/test_elements_worker.py b/tests/test_elements_worker.py
index e0b7dd49..1eea89a4 100644
--- a/tests/test_elements_worker.py
+++ b/tests/test_elements_worker.py
@@ -649,7 +649,6 @@ def test_create_transcription_wrong_element(mock_elements_worker):
         mock_elements_worker.create_transcription(
             element=None,
             text="i am a line",
-            type=TranscriptionType.Line,
             score=0.42,
         )
     assert str(e.value) == "element shouldn't be null and should be of type Element"
@@ -658,47 +657,37 @@ def test_create_transcription_wrong_element(mock_elements_worker):
         mock_elements_worker.create_transcription(
             element="not element type",
             text="i am a line",
-            type=TranscriptionType.Line,
             score=0.42,
         )
     assert str(e.value) == "element shouldn't be null and should be of type Element"
 
 
-def test_create_transcription_wrong_type(mock_elements_worker):
+def test_create_transcription_type_warning(responses, mock_elements_worker):
     elt = Element({"id": "12341234-1234-1234-1234-123412341234"})
-
-    with pytest.raises(AssertionError) as e:
-        mock_elements_worker.create_transcription(
-            element=elt,
-            text="i am a line",
-            type=None,
-            score=0.42,
-        )
-    assert (
-        str(e.value) == "type shouldn't be null and should be of type TranscriptionType"
+    responses.add(
+        responses.POST,
+        f"http://testserver/api/v1/element/{elt.id}/transcription/",
+        status=200,
     )
 
-    with pytest.raises(AssertionError) as e:
+    with pytest.warns(FutureWarning) as w:
         mock_elements_worker.create_transcription(
             element=elt,
             text="i am a line",
-            type=1234,
+            type=TranscriptionType.Word,
             score=0.42,
         )
+    assert len(w) == 1
     assert (
-        str(e.value) == "type shouldn't be null and should be of type TranscriptionType"
+        w[0].message.args[0]
+        == "Transcription types are deprecated and will be removed in the next release."
     )
 
-    with pytest.raises(AssertionError) as e:
-        mock_elements_worker.create_transcription(
-            element=elt,
-            text="i am a line",
-            type="not_a_transcription_type",
-            score=0.42,
-        )
-    assert (
-        str(e.value) == "type shouldn't be null and should be of type TranscriptionType"
-    )
+    assert len(responses.calls) == 2
+    assert [call.request.url for call in responses.calls] == [
+        "http://testserver/api/v1/workers/versions/12341234-1234-1234-1234-123412341234/",
+        f"http://testserver/api/v1/element/{elt.id}/transcription/",
+    ]
 
 
 def test_create_transcription_wrong_text(mock_elements_worker):
@@ -730,7 +719,6 @@ def test_create_transcription_wrong_score(mock_elements_worker):
         mock_elements_worker.create_transcription(
             element=elt,
             text="i am a line",
-            type=TranscriptionType.Line,
             score=None,
         )
     assert (
@@ -741,7 +729,6 @@ def test_create_transcription_wrong_score(mock_elements_worker):
         mock_elements_worker.create_transcription(
             element=elt,
             text="i am a line",
-            type=TranscriptionType.Line,
             score="wrong score",
         )
     assert (
@@ -752,7 +739,6 @@ def test_create_transcription_wrong_score(mock_elements_worker):
         mock_elements_worker.create_transcription(
             element=elt,
             text="i am a line",
-            type=TranscriptionType.Line,
             score=0,
         )
     assert (
@@ -763,7 +749,6 @@ def test_create_transcription_wrong_score(mock_elements_worker):
         mock_elements_worker.create_transcription(
             element=elt,
             text="i am a line",
-            type=TranscriptionType.Line,
             score=2.00,
         )
     assert (
@@ -783,7 +768,6 @@ def test_create_transcription_api_error(responses, mock_elements_worker):
         mock_elements_worker.create_transcription(
             element=elt,
             text="i am a line",
-            type=TranscriptionType.Line,
             score=0.42,
         )
 
@@ -805,7 +789,6 @@ def test_create_transcription(responses, mock_elements_worker):
     mock_elements_worker.create_transcription(
         element=elt,
         text="i am a line",
-        type=TranscriptionType.Line,
         score=0.42,
     )
 
@@ -817,7 +800,6 @@ def test_create_transcription(responses, mock_elements_worker):
 
     assert json.loads(responses.calls[1].request.body) == {
         "text": "i am a line",
-        "type": "line",
         "worker_version": "12341234-1234-1234-1234-123412341234",
         "score": 0.42,
     }
@@ -1313,7 +1295,6 @@ def test_create_element_transcriptions_wrong_element(mock_elements_worker):
         mock_elements_worker.create_element_transcriptions(
             element=None,
             sub_element_type="page",
-            transcription_type=TranscriptionType.Word,
             transcriptions=TRANSCRIPTIONS_SAMPLE,
         )
     assert str(e.value) == "element shouldn't be null and should be of type Element"
@@ -1322,7 +1303,6 @@ def test_create_element_transcriptions_wrong_element(mock_elements_worker):
         mock_elements_worker.create_element_transcriptions(
             element="not element type",
             sub_element_type="page",
-            transcription_type=TranscriptionType.Word,
             transcriptions=TRANSCRIPTIONS_SAMPLE,
         )
     assert str(e.value) == "element shouldn't be null and should be of type Element"
@@ -1335,7 +1315,6 @@ def test_create_element_transcriptions_wrong_sub_element_type(mock_elements_work
         mock_elements_worker.create_element_transcriptions(
             element=elt,
             sub_element_type=None,
-            transcription_type=TranscriptionType.Word,
             transcriptions=TRANSCRIPTIONS_SAMPLE,
         )
     assert (
@@ -1346,7 +1325,6 @@ def test_create_element_transcriptions_wrong_sub_element_type(mock_elements_work
         mock_elements_worker.create_element_transcriptions(
             element=elt,
             sub_element_type=1234,
-            transcription_type=TranscriptionType.Word,
             transcriptions=TRANSCRIPTIONS_SAMPLE,
         )
     assert (
@@ -1354,43 +1332,32 @@ def test_create_element_transcriptions_wrong_sub_element_type(mock_elements_work
     )
 
 
-def test_create_element_transcriptions_wrong_transcription_type(mock_elements_worker):
+def test_create_element_transcriptions_transcription_type_warning(
+    responses, mock_elements_worker
+):
     elt = Element({"id": "12341234-1234-1234-1234-123412341234"})
-
-    with pytest.raises(AssertionError) as e:
-        mock_elements_worker.create_element_transcriptions(
-            element=elt,
-            sub_element_type="page",
-            transcription_type=None,
-            transcriptions=TRANSCRIPTIONS_SAMPLE,
-        )
-    assert (
-        str(e.value)
-        == "transcription_type shouldn't be null and should be of type TranscriptionType"
-    )
-
-    with pytest.raises(AssertionError) as e:
-        mock_elements_worker.create_element_transcriptions(
-            element=elt,
-            sub_element_type="page",
-            transcription_type=1234,
-            transcriptions=TRANSCRIPTIONS_SAMPLE,
-        )
-    assert (
-        str(e.value)
-        == "transcription_type shouldn't be null and should be of type TranscriptionType"
+    responses.add(
+        responses.POST,
+        f"http://testserver/api/v1/element/{elt.id}/transcriptions/bulk/",
+        status=200,
+        json=[
+            {"id": "word1_1_1", "created": False},
+            {"id": "word1_1_2", "created": False},
+            {"id": "word1_1_3", "created": False},
+        ],
     )
 
-    with pytest.raises(AssertionError) as e:
+    with pytest.warns(FutureWarning) as w:
         mock_elements_worker.create_element_transcriptions(
             element=elt,
             sub_element_type="page",
-            transcription_type="not_a_transcription_type",
+            transcription_type=TranscriptionType.Word,
             transcriptions=TRANSCRIPTIONS_SAMPLE,
         )
+    assert len(w) == 1
     assert (
-        str(e.value)
-        == "transcription_type shouldn't be null and should be of type TranscriptionType"
+        w[0].message.args[0]
+        == "Transcription types are deprecated and will be removed in the next release."
     )
 
 
@@ -1401,7 +1368,6 @@ def test_create_element_transcriptions_wrong_transcriptions(mock_elements_worker
         mock_elements_worker.create_element_transcriptions(
             element=elt,
             sub_element_type="page",
-            transcription_type=TranscriptionType.Word,
             transcriptions=None,
         )
     assert str(e.value) == "transcriptions shouldn't be null and should be of type list"
@@ -1410,7 +1376,6 @@ def test_create_element_transcriptions_wrong_transcriptions(mock_elements_worker
         mock_elements_worker.create_element_transcriptions(
             element=elt,
             sub_element_type="page",
-            transcription_type=TranscriptionType.Word,
             transcriptions=1234,
         )
     assert str(e.value) == "transcriptions shouldn't be null and should be of type list"
@@ -1419,7 +1384,6 @@ def test_create_element_transcriptions_wrong_transcriptions(mock_elements_worker
         mock_elements_worker.create_element_transcriptions(
             element=elt,
             sub_element_type="page",
-            transcription_type=TranscriptionType.Word,
             transcriptions=[
                 {
                     "polygon": [[0, 0], [2000, 0], [2000, 3000], [0, 3000]],
@@ -1441,7 +1405,6 @@ def test_create_element_transcriptions_wrong_transcriptions(mock_elements_worker
         mock_elements_worker.create_element_transcriptions(
             element=elt,
             sub_element_type="page",
-            transcription_type=TranscriptionType.Word,
             transcriptions=[
                 {
                     "polygon": [[0, 0], [2000, 0], [2000, 3000], [0, 3000]],
@@ -1464,7 +1427,6 @@ def test_create_element_transcriptions_wrong_transcriptions(mock_elements_worker
         mock_elements_worker.create_element_transcriptions(
             element=elt,
             sub_element_type="page",
-            transcription_type=TranscriptionType.Word,
             transcriptions=[
                 {
                     "polygon": [[0, 0], [2000, 0], [2000, 3000], [0, 3000]],
@@ -1487,7 +1449,6 @@ def test_create_element_transcriptions_wrong_transcriptions(mock_elements_worker
         mock_elements_worker.create_element_transcriptions(
             element=elt,
             sub_element_type="page",
-            transcription_type=TranscriptionType.Word,
             transcriptions=[
                 {
                     "polygon": [[0, 0], [2000, 0], [2000, 3000], [0, 3000]],
@@ -1509,7 +1470,6 @@ def test_create_element_transcriptions_wrong_transcriptions(mock_elements_worker
         mock_elements_worker.create_element_transcriptions(
             element=elt,
             sub_element_type="page",
-            transcription_type=TranscriptionType.Word,
             transcriptions=[
                 {
                     "polygon": [[0, 0], [2000, 0], [2000, 3000], [0, 3000]],
@@ -1532,7 +1492,6 @@ def test_create_element_transcriptions_wrong_transcriptions(mock_elements_worker
         mock_elements_worker.create_element_transcriptions(
             element=elt,
             sub_element_type="page",
-            transcription_type=TranscriptionType.Word,
             transcriptions=[
                 {
                     "polygon": [[0, 0], [2000, 0], [2000, 3000], [0, 3000]],
@@ -1555,7 +1514,6 @@ def test_create_element_transcriptions_wrong_transcriptions(mock_elements_worker
         mock_elements_worker.create_element_transcriptions(
             element=elt,
             sub_element_type="page",
-            transcription_type=TranscriptionType.Word,
             transcriptions=[
                 {
                     "polygon": [[0, 0], [2000, 0], [2000, 3000], [0, 3000]],
@@ -1578,7 +1536,6 @@ def test_create_element_transcriptions_wrong_transcriptions(mock_elements_worker
         mock_elements_worker.create_element_transcriptions(
             element=elt,
             sub_element_type="page",
-            transcription_type=TranscriptionType.Word,
             transcriptions=[
                 {
                     "polygon": [[0, 0], [2000, 0], [2000, 3000], [0, 3000]],
@@ -1601,7 +1558,6 @@ def test_create_element_transcriptions_wrong_transcriptions(mock_elements_worker
         mock_elements_worker.create_element_transcriptions(
             element=elt,
             sub_element_type="page",
-            transcription_type=TranscriptionType.Word,
             transcriptions=[
                 {
                     "polygon": [[0, 0], [2000, 0], [2000, 3000], [0, 3000]],
@@ -1620,7 +1576,6 @@ def test_create_element_transcriptions_wrong_transcriptions(mock_elements_worker
         mock_elements_worker.create_element_transcriptions(
             element=elt,
             sub_element_type="page",
-            transcription_type=TranscriptionType.Word,
             transcriptions=[
                 {
                     "polygon": [[0, 0], [2000, 0], [2000, 3000], [0, 3000]],
@@ -1639,7 +1594,6 @@ def test_create_element_transcriptions_wrong_transcriptions(mock_elements_worker
         mock_elements_worker.create_element_transcriptions(
             element=elt,
             sub_element_type="page",
-            transcription_type=TranscriptionType.Word,
             transcriptions=[
                 {
                     "polygon": [[0, 0], [2000, 0], [2000, 3000], [0, 3000]],
@@ -1658,7 +1612,6 @@ def test_create_element_transcriptions_wrong_transcriptions(mock_elements_worker
         mock_elements_worker.create_element_transcriptions(
             element=elt,
             sub_element_type="page",
-            transcription_type=TranscriptionType.Word,
             transcriptions=[
                 {
                     "polygon": [[0, 0], [2000, 0], [2000, 3000], [0, 3000]],
@@ -1677,7 +1630,6 @@ def test_create_element_transcriptions_wrong_transcriptions(mock_elements_worker
         mock_elements_worker.create_element_transcriptions(
             element=elt,
             sub_element_type="page",
-            transcription_type=TranscriptionType.Word,
             transcriptions=[
                 {
                     "polygon": [[0, 0], [2000, 0], [2000, 3000], [0, 3000]],
@@ -1700,7 +1652,6 @@ def test_create_element_transcriptions_wrong_transcriptions(mock_elements_worker
         mock_elements_worker.create_element_transcriptions(
             element=elt,
             sub_element_type="page",
-            transcription_type=TranscriptionType.Word,
             transcriptions=[
                 {
                     "polygon": [[0, 0], [2000, 0], [2000, 3000], [0, 3000]],
@@ -1719,7 +1670,6 @@ def test_create_element_transcriptions_wrong_transcriptions(mock_elements_worker
         mock_elements_worker.create_element_transcriptions(
             element=elt,
             sub_element_type="page",
-            transcription_type=TranscriptionType.Word,
             transcriptions=[
                 {
                     "polygon": [[0, 0], [2000, 0], [2000, 3000], [0, 3000]],
@@ -1751,7 +1701,6 @@ def test_create_element_transcriptions_api_error(responses, mock_elements_worker
         mock_elements_worker.create_element_transcriptions(
             element=elt,
             sub_element_type="page",
-            transcription_type=TranscriptionType.Word,
             transcriptions=TRANSCRIPTIONS_SAMPLE,
         )
 
@@ -1778,7 +1727,6 @@ def test_create_element_transcriptions(responses, mock_elements_worker):
     annotations = mock_elements_worker.create_element_transcriptions(
         element=elt,
         sub_element_type="page",
-        transcription_type=TranscriptionType.Word,
         transcriptions=TRANSCRIPTIONS_SAMPLE,
     )
 
@@ -1790,7 +1738,6 @@ def test_create_element_transcriptions(responses, mock_elements_worker):
 
     assert json.loads(responses.calls[1].request.body) == {
         "element_type": "page",
-        "transcription_type": "word",
         "worker_version": "12341234-1234-1234-1234-123412341234",
         "transcriptions": TRANSCRIPTIONS_SAMPLE,
         "return_elements": True,
diff --git a/tests/test_reporting.py b/tests/test_reporting.py
index 7f1c1cb2..c88ea6bf 100644
--- a/tests/test_reporting.py
+++ b/tests/test_reporting.py
@@ -21,7 +21,7 @@ def test_process():
     del element_data["started"]
     assert element_data == {
         "elements": {},
-        "transcriptions": {},
+        "transcriptions": 0,
         "classifications": {},
         "entities": [],
         "errors": [],
@@ -36,7 +36,7 @@ def test_add_element():
     del element_data["started"]
     assert element_data == {
         "elements": {"text_line": 1},
-        "transcriptions": {},
+        "transcriptions": 0,
         "classifications": {},
         "entities": [],
         "errors": [],
@@ -54,7 +54,7 @@ def test_add_element_count():
     del element_data["started"]
     assert element_data == {
         "elements": {"text_line": 42},
-        "transcriptions": {},
+        "transcriptions": 0,
         "classifications": {},
         "entities": [],
         "errors": [],
@@ -69,7 +69,7 @@ def test_add_classification():
     del element_data["started"]
     assert element_data == {
         "elements": {},
-        "transcriptions": {},
+        "transcriptions": 0,
         "classifications": {"three": 1},
         "entities": [],
         "errors": [],
@@ -98,7 +98,7 @@ def test_add_classifications():
     del element_data["started"]
     assert element_data == {
         "elements": {},
-        "transcriptions": {},
+        "transcriptions": 0,
         "classifications": {"three": 3, "two": 2},
         "entities": [],
         "errors": [],
@@ -107,13 +107,36 @@ def test_add_classifications():
 
 def test_add_transcription():
     reporter = Reporter("worker")
-    reporter.add_transcription("myelement", "word")
+    reporter.add_transcription("myelement")
     assert "myelement" in reporter.report_data["elements"]
     element_data = reporter.report_data["elements"]["myelement"]
     del element_data["started"]
     assert element_data == {
         "elements": {},
-        "transcriptions": {"word": 1},
+        "transcriptions": 1,
+        "classifications": {},
+        "entities": [],
+        "errors": [],
+    }
+
+
+def test_add_transcription_warning():
+    reporter = Reporter("worker")
+
+    with pytest.warns(FutureWarning) as w:
+        reporter.add_transcription("myelement", "word")
+    assert len(w) == 1
+    assert (
+        w[0].message.args[0]
+        == "Transcription types have been deprecated and will be removed in the next release."
+    )
+
+    assert "myelement" in reporter.report_data["elements"]
+    element_data = reporter.report_data["elements"]["myelement"]
+    del element_data["started"]
+    assert element_data == {
+        "elements": {},
+        "transcriptions": 1,
         "classifications": {},
         "entities": [],
         "errors": [],
@@ -125,13 +148,13 @@ def test_add_transcription_count():
     Report multiple transcriptions with the same element and type
     """
     reporter = Reporter("worker")
-    reporter.add_transcription("myelement", "word", type_count=1337)
+    reporter.add_transcription("myelement", type_count=1337)
     assert "myelement" in reporter.report_data["elements"]
     element_data = reporter.report_data["elements"]["myelement"]
     del element_data["started"]
     assert element_data == {
         "elements": {},
-        "transcriptions": {"word": 1337},
+        "transcriptions": 1337,
         "classifications": {},
         "entities": [],
         "errors": [],
@@ -143,22 +166,27 @@ def test_add_transcriptions():
     with pytest.raises(AssertionError):
         reporter.add_transcriptions("myelement", {"not": "a list"})
 
-    reporter.add_transcriptions("myelement", [{"type": "word"}, {"type": "line"}])
-    reporter.add_transcriptions(
-        "myelement",
-        [
-            {"type": "word"},
-            {"type": "line", "text": "something"},
-            {"type": "word", "confidence": 0.42},
-        ],
-    )
+    with pytest.warns(FutureWarning) as w:
+        reporter.add_transcriptions("myelement", [{"type": "word"}, {"type": "line"}])
+        reporter.add_transcriptions(
+            "myelement",
+            [
+                {"type": "word"},
+                {"type": "line", "text": "something"},
+                {"type": "word", "confidence": 0.42},
+            ],
+        )
+    assert len(w) == 2
+    assert set(warning.message.args[0] for warning in w) == {
+        "Reporter.add_transcriptions is deprecated due to transcription types being removed. Please use Reporter.add_transcription(element_id, count) instead."
+    }
 
     assert "myelement" in reporter.report_data["elements"]
     element_data = reporter.report_data["elements"]["myelement"]
     del element_data["started"]
     assert element_data == {
         "elements": {},
-        "transcriptions": {"word": 3, "line": 2},
+        "transcriptions": 5,
         "classifications": {},
         "entities": [],
         "errors": [],
@@ -175,7 +203,7 @@ def test_add_entity():
     del element_data["started"]
     assert element_data == {
         "elements": {},
-        "transcriptions": {},
+        "transcriptions": 0,
         "classifications": {},
         "entities": [
             {
-- 
GitLab