arkindex-base-worker 0.4.0rc2__py3-none-any.whl → 0.4.0rc4__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {arkindex_base_worker-0.4.0rc2.dist-info → arkindex_base_worker-0.4.0rc4.dist-info}/METADATA +15 -14
- arkindex_base_worker-0.4.0rc4.dist-info/RECORD +60 -0
- {arkindex_base_worker-0.4.0rc2.dist-info → arkindex_base_worker-0.4.0rc4.dist-info}/WHEEL +1 -1
- arkindex_worker/cache.py +1 -1
- arkindex_worker/worker/__init__.py +1 -2
- arkindex_worker/worker/base.py +1 -1
- arkindex_worker/worker/classification.py +1 -1
- arkindex_worker/worker/corpus.py +21 -6
- arkindex_worker/worker/entity.py +1 -1
- arkindex_worker/worker/task.py +1 -2
- arkindex_worker/worker/training.py +1 -1
- tests/test_dataset_worker.py +1 -1
- tests/test_elements_worker/{test_classifications.py → test_classification.py} +87 -1
- tests/test_elements_worker/test_corpus.py +32 -1
- tests/test_elements_worker/test_dataset.py +1 -1
- tests/test_elements_worker/test_element.py +427 -0
- tests/test_elements_worker/test_element_create_multiple.py +715 -0
- tests/test_elements_worker/test_element_create_single.py +528 -0
- tests/test_elements_worker/test_element_list_children.py +969 -0
- tests/test_elements_worker/test_element_list_parents.py +530 -0
- tests/test_elements_worker/{test_entities.py → test_entity_create.py} +1 -154
- tests/test_elements_worker/test_entity_list_and_check.py +160 -0
- tests/test_elements_worker/test_image.py +2 -1
- tests/test_elements_worker/test_metadata.py +1 -1
- tests/test_elements_worker/test_task.py +1 -1
- tests/test_elements_worker/test_transcription_create.py +873 -0
- tests/test_elements_worker/test_transcription_create_with_elements.py +951 -0
- tests/test_elements_worker/test_transcription_list.py +450 -0
- tests/test_elements_worker/test_version.py +60 -0
- tests/test_elements_worker/test_worker.py +526 -89
- tests/test_image.py +181 -198
- arkindex_base_worker-0.4.0rc2.dist-info/RECORD +0 -52
- tests/test_elements_worker/test_elements.py +0 -3704
- tests/test_elements_worker/test_transcriptions.py +0 -2252
- {arkindex_base_worker-0.4.0rc2.dist-info → arkindex_base_worker-0.4.0rc4.dist-info}/LICENSE +0 -0
- {arkindex_base_worker-0.4.0rc2.dist-info → arkindex_base_worker-0.4.0rc4.dist-info}/top_level.txt +0 -0
{arkindex_base_worker-0.4.0rc2.dist-info → arkindex_base_worker-0.4.0rc4.dist-info}/METADATA
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: arkindex-base-worker
|
|
3
|
-
Version: 0.4.
|
|
3
|
+
Version: 0.4.0rc4
|
|
4
4
|
Summary: Base Worker to easily build Arkindex ML workflows
|
|
5
5
|
Author-email: Teklia <contact@teklia.com>
|
|
6
6
|
Maintainer-email: Teklia <contact@teklia.com>
|
|
@@ -37,24 +37,25 @@ Classifier: License :: OSI Approved :: MIT License
|
|
|
37
37
|
Classifier: Programming Language :: Python :: 3 :: Only
|
|
38
38
|
Classifier: Programming Language :: Python :: 3.10
|
|
39
39
|
Classifier: Programming Language :: Python :: 3.11
|
|
40
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
40
41
|
Requires-Python: >=3.10
|
|
41
42
|
Description-Content-Type: text/markdown
|
|
42
43
|
License-File: LICENSE
|
|
43
|
-
Requires-Dist: humanize
|
|
44
|
-
Requires-Dist: peewee
|
|
45
|
-
Requires-Dist: Pillow
|
|
46
|
-
Requires-Dist: python-gnupg
|
|
47
|
-
Requires-Dist: shapely
|
|
48
|
-
Requires-Dist: teklia-toolbox
|
|
49
|
-
Requires-Dist: zstandard
|
|
44
|
+
Requires-Dist: humanize==4.10.0
|
|
45
|
+
Requires-Dist: peewee~=3.17
|
|
46
|
+
Requires-Dist: Pillow==10.4.0
|
|
47
|
+
Requires-Dist: python-gnupg==0.5.2
|
|
48
|
+
Requires-Dist: shapely==2.0.6
|
|
49
|
+
Requires-Dist: teklia-toolbox==0.1.7b1
|
|
50
|
+
Requires-Dist: zstandard==0.22.0
|
|
50
51
|
Provides-Extra: docs
|
|
51
|
-
Requires-Dist: black
|
|
52
|
-
Requires-Dist: mkdocs-material
|
|
53
|
-
Requires-Dist: mkdocstrings-python
|
|
52
|
+
Requires-Dist: black==24.4.2; extra == "docs"
|
|
53
|
+
Requires-Dist: mkdocs-material==9.5.33; extra == "docs"
|
|
54
|
+
Requires-Dist: mkdocstrings-python==1.11.1; extra == "docs"
|
|
54
55
|
Provides-Extra: tests
|
|
55
|
-
Requires-Dist: pytest
|
|
56
|
-
Requires-Dist: pytest-mock
|
|
57
|
-
Requires-Dist: pytest-responses
|
|
56
|
+
Requires-Dist: pytest==8.3.2; extra == "tests"
|
|
57
|
+
Requires-Dist: pytest-mock==3.14.0; extra == "tests"
|
|
58
|
+
Requires-Dist: pytest-responses==0.5.1; extra == "tests"
|
|
58
59
|
|
|
59
60
|
# Arkindex base Worker
|
|
60
61
|
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
arkindex_worker/__init__.py,sha256=OlgCtTC9MaWeejviY0a3iQpALcRQGMVArFVVYwTF6I8,162
|
|
2
|
+
arkindex_worker/cache.py,sha256=qTblc_zKdYC47Wip6_O9Jf5qBkQW2ozQQrg-nsx1WuY,11221
|
|
3
|
+
arkindex_worker/image.py,sha256=oEgVCrSHiGh3D5-UXfM6PvT17TttSxC0115irpvB3Dw,18581
|
|
4
|
+
arkindex_worker/models.py,sha256=bPQzGZNs5a6z6DEcygsa8T33VOqPlMUbwKzHqlKzwbw,9923
|
|
5
|
+
arkindex_worker/utils.py,sha256=q1EeLdC6ebYIH-C0LOAqw2cNpjCjVoP-Vbr-39mF4w0,9884
|
|
6
|
+
arkindex_worker/worker/__init__.py,sha256=tcqxrox9EpOjaN2EQgXumiABKpWHLsJiynPC2_sZuOQ,15880
|
|
7
|
+
arkindex_worker/worker/base.py,sha256=7Pmw-UQSxV-xkW8NO5cXsxJ8W8szzyppMaNjq_az81A,19844
|
|
8
|
+
arkindex_worker/worker/classification.py,sha256=zECSNzGCZFzoPoDVZN4kuGYRNLzMQLBaRt3q1jnBSaA,10952
|
|
9
|
+
arkindex_worker/worker/corpus.py,sha256=0TQFOwZ6Te-CZi6lgkZY1wzyJ5wO9LAmcVQtqHvZpPk,2291
|
|
10
|
+
arkindex_worker/worker/dataset.py,sha256=LwzKwNFX4FqfLxh29LSvJydPwRw3VHaB1wjuFhUshsE,5267
|
|
11
|
+
arkindex_worker/worker/element.py,sha256=Qvvq9kJnAHNATHW7zi96eIY1x-0MsR-T5rrSJg6e9Y4,45309
|
|
12
|
+
arkindex_worker/worker/entity.py,sha256=ThhP22xOYR5Z4P1VH_pOl_y_uDKZFeQVDqxO6aRkIhg,15227
|
|
13
|
+
arkindex_worker/worker/image.py,sha256=t_Az6IGnj0EZyvcA4XxfPikOUjn_pztgsyxTkFZhaXU,621
|
|
14
|
+
arkindex_worker/worker/metadata.py,sha256=VRajtd2kaBvar9GercX4knvR6l1WFYjoCdJWU9ccKgk,7291
|
|
15
|
+
arkindex_worker/worker/process.py,sha256=I1rBt3Y8bV4zcPr8N1E2NRZ0UClSTqhExsO9CPcP41E,1012
|
|
16
|
+
arkindex_worker/worker/task.py,sha256=r1j7_qbdNu2Z8H8HbGzO3P3qdx-2N1pBbUPFDca0rqg,1519
|
|
17
|
+
arkindex_worker/worker/training.py,sha256=H8FmCdzGcDW-WMMwcgvmZPlN5tPHwGo0BXn12qmzj8g,10875
|
|
18
|
+
arkindex_worker/worker/transcription.py,sha256=52RY9kYsiR1sz9FxOigyo12Ker3VDbQ4U42gK9DpR3g,21146
|
|
19
|
+
arkindex_worker/worker/version.py,sha256=JIT7OI3Mo7RPkNrjOB9hfqrsG-FYygz_zi4l8PbkuAo,1960
|
|
20
|
+
hooks/pre_gen_project.py,sha256=xQJERv3vv9VzIqcBHI281eeWLWREXUF4mMw7PvJHHXM,269
|
|
21
|
+
tests/__init__.py,sha256=DG--S6IpGl399rzSAjDdHL76CkOIeZIjajCcyUSDhOQ,241
|
|
22
|
+
tests/conftest.py,sha256=2ocZ2x-mZQrNe9zvWwhWk2_4ExdaBHIB74SvtDlExRE,21580
|
|
23
|
+
tests/test_base_worker.py,sha256=2EIYcd_3f9O0zB5WiGIQV0Cn9wndLvnEnSfcAE1qWWU,30607
|
|
24
|
+
tests/test_cache.py,sha256=ii0gyr0DrG7ChEs7pmT8hMdSguAOAcCze4bRMiFQxuk,10640
|
|
25
|
+
tests/test_dataset_worker.py,sha256=gApYz0LArHr1cNn079_fa_BQABF6RVQYuM1Tc4m3NsQ,22089
|
|
26
|
+
tests/test_element.py,sha256=2G9M15TLxQRmvrWM9Kw2ucnElh4kSv_oF_5FYwwAxTY,13181
|
|
27
|
+
tests/test_image.py,sha256=03E24JVa7TZJfuwQyfVEBe3RAq3R993IMl1AHXRr7zY,25497
|
|
28
|
+
tests/test_merge.py,sha256=TuOeUS0UCz66DPOQFFhc4NQBxIjZL9f5czi4XnvGrr4,8270
|
|
29
|
+
tests/test_utils.py,sha256=_WJUPnt-pM_TQ0er4yjPZy-u_LePrHq1lxwk_teky7M,2544
|
|
30
|
+
tests/test_elements_worker/__init__.py,sha256=Fh4nkbbyJSMv_VtjQxnWrOqTnxXaaWI8S9WU0VrzCHs,179
|
|
31
|
+
tests/test_elements_worker/test_classification.py,sha256=nya7veSPR_O9G41Enodp2-o6AifMBcaSTWJP2vXSSJ4,30133
|
|
32
|
+
tests/test_elements_worker/test_cli.py,sha256=a23i1pUDbXi23MUtbWwGEcLLrmc_YlrbDgOG3h66wLM,2620
|
|
33
|
+
tests/test_elements_worker/test_corpus.py,sha256=kscJyM8k1njYJJFGuvliVzn89lWh41mEyDCCawnp3W8,5483
|
|
34
|
+
tests/test_elements_worker/test_dataset.py,sha256=00IlOZv9YFlZ23rGXyR-HLbKLQxGelZ1Bf9lEZYA0IY,11412
|
|
35
|
+
tests/test_elements_worker/test_element.py,sha256=lb5tLjl0jsixX0OWVhBAaKLE9GKkBw79kFHDNGommaQ,12535
|
|
36
|
+
tests/test_elements_worker/test_element_create_multiple.py,sha256=arYFGmxc0517ZUii6k__G_UQQatuNIASTC8MXvUrSwk,21887
|
|
37
|
+
tests/test_elements_worker/test_element_create_single.py,sha256=Fa9zm12J2rQ3VrUe3yIlHAc7Vty_eQYb_YGnNPQB3IE,16697
|
|
38
|
+
tests/test_elements_worker/test_element_list_children.py,sha256=2zH4h663w3EduqpzQr-7bf9zIDzO1x2WxdUYYHsIHkI,31358
|
|
39
|
+
tests/test_elements_worker/test_element_list_parents.py,sha256=TXeGW-a3W-7GmB2QrhJH9mMnvxuybeAwQ4tL3iIxwXo,16734
|
|
40
|
+
tests/test_elements_worker/test_entity_create.py,sha256=TkEoQDmwuP1AlSYf42WXJVMMa0lIEPMn6PGy5ExA_5c,31343
|
|
41
|
+
tests/test_elements_worker/test_entity_list_and_check.py,sha256=ENBLaqbXlRUDbHRvQla3080a0HJltrWAPYWNohUA9NU,4992
|
|
42
|
+
tests/test_elements_worker/test_image.py,sha256=BljMNKgec_9a5bzNzFpYZIvSbuvwsWDfdqLHVJaTa7M,2079
|
|
43
|
+
tests/test_elements_worker/test_metadata.py,sha256=Xfggy-vxw5DZ3hFKx3sB7OYb2d1tu1RiNK8fvKJIaBs,22294
|
|
44
|
+
tests/test_elements_worker/test_task.py,sha256=wTUWqN9UhfKmJn3IcFY75EW4I1ulRhisflmY1kmP47s,5574
|
|
45
|
+
tests/test_elements_worker/test_training.py,sha256=Qxi9EzGr_uKcn2Fh5aE6jNrq1K8QKLiOiSew4upASPs,8721
|
|
46
|
+
tests/test_elements_worker/test_transcription_create.py,sha256=yznO9B_BVsOR0Z_VY5ZL8gJp0ZPCz_4sPUs5dXtixAg,29281
|
|
47
|
+
tests/test_elements_worker/test_transcription_create_with_elements.py,sha256=tmcyglgssEqMnt1Mdy_u6X1m2wgLWTo_HdWst3GrK2k,33056
|
|
48
|
+
tests/test_elements_worker/test_transcription_list.py,sha256=ikz7HYPCoQWTdTRCd382SB-y-T2BbigPLlIcx5Eow-I,15324
|
|
49
|
+
tests/test_elements_worker/test_version.py,sha256=xqCgcgukTFJzkMgYfQG-8mTbu0o2fdYjWC07FktThfw,2125
|
|
50
|
+
tests/test_elements_worker/test_worker.py,sha256=fnFwkcDb6tx5i7lbelifeHD-BrGz6o5UBEojPCdtuAo,23474
|
|
51
|
+
worker-demo/tests/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
52
|
+
worker-demo/tests/conftest.py,sha256=XzNMNeg6pmABUAH8jN6eZTlZSFGLYjS3-DTXjiRN6Yc,1002
|
|
53
|
+
worker-demo/tests/test_worker.py,sha256=3DLd4NRK4bfyatG5P_PK4k9P9tJHx9XQq5_ryFEEFVg,304
|
|
54
|
+
worker-demo/worker_demo/__init__.py,sha256=2BPomV8ZMNf3YXJgloatKeHQCE6QOkwmsHGkO6MkQuM,125
|
|
55
|
+
worker-demo/worker_demo/worker.py,sha256=Rt-DjWa5iBP08k58NDZMfeyPuFbtNcbX6nc5jFX7GNo,440
|
|
56
|
+
arkindex_base_worker-0.4.0rc4.dist-info/LICENSE,sha256=NVshRi1efwVezMfW7xXYLrdDr2Li1AfwfGOd5WuH1kQ,1063
|
|
57
|
+
arkindex_base_worker-0.4.0rc4.dist-info/METADATA,sha256=Du-kBAZ-QL6SjvASaOK1Nxsw8yqN8Efx4L1JR-dA720,3338
|
|
58
|
+
arkindex_base_worker-0.4.0rc4.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
|
|
59
|
+
arkindex_base_worker-0.4.0rc4.dist-info/top_level.txt,sha256=58NuslgxQC2vT4DiqZEgO4JqJRrYa2yeNI9QvkbfGQU,40
|
|
60
|
+
arkindex_base_worker-0.4.0rc4.dist-info/RECORD,,
|
arkindex_worker/cache.py
CHANGED
|
@@ -380,7 +380,7 @@ def unsupported_cache(func):
|
|
|
380
380
|
def wrapper(self, *args, **kwargs):
|
|
381
381
|
results = func(self, *args, **kwargs)
|
|
382
382
|
|
|
383
|
-
if
|
|
383
|
+
if self.use_cache:
|
|
384
384
|
logger.warning(
|
|
385
385
|
f"This API helper `{func.__name__}` did not update the cache database"
|
|
386
386
|
)
|
|
@@ -10,8 +10,7 @@ from collections.abc import Iterable
|
|
|
10
10
|
from itertools import chain
|
|
11
11
|
from pathlib import Path
|
|
12
12
|
|
|
13
|
-
from
|
|
14
|
-
|
|
13
|
+
from arkindex.exceptions import ErrorResponse
|
|
15
14
|
from arkindex_worker import logger
|
|
16
15
|
from arkindex_worker.cache import CachedElement
|
|
17
16
|
from arkindex_worker.models import Dataset, Element, Set
|
arkindex_worker/worker/base.py
CHANGED
|
@@ -12,9 +12,9 @@ from tempfile import mkdtemp
|
|
|
12
12
|
|
|
13
13
|
import gnupg
|
|
14
14
|
import yaml
|
|
15
|
-
from apistar.exceptions import ErrorResponse
|
|
16
15
|
|
|
17
16
|
from arkindex import options_from_env
|
|
17
|
+
from arkindex.exceptions import ErrorResponse
|
|
18
18
|
from arkindex_worker import logger
|
|
19
19
|
from arkindex_worker.cache import (
|
|
20
20
|
check_version,
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
ElementsWorker methods for classifications and ML classes.
|
|
3
3
|
"""
|
|
4
4
|
|
|
5
|
-
from apistar.exceptions import ErrorResponse
|
|
6
5
|
from peewee import IntegrityError
|
|
7
6
|
|
|
7
|
+
from arkindex.exceptions import ErrorResponse
|
|
8
8
|
from arkindex_worker import logger
|
|
9
9
|
from arkindex_worker.cache import CachedClassification, CachedElement
|
|
10
10
|
from arkindex_worker.models import Element
|
arkindex_worker/worker/corpus.py
CHANGED
|
@@ -5,6 +5,7 @@ BaseWorker methods for corpora.
|
|
|
5
5
|
from enum import Enum
|
|
6
6
|
from operator import itemgetter
|
|
7
7
|
from tempfile import _TemporaryFileWrapper
|
|
8
|
+
from uuid import UUID
|
|
8
9
|
|
|
9
10
|
from arkindex_worker import logger
|
|
10
11
|
|
|
@@ -36,6 +37,25 @@ class CorpusExportState(Enum):
|
|
|
36
37
|
|
|
37
38
|
|
|
38
39
|
class CorpusMixin:
|
|
40
|
+
def download_export(self, export_id: str) -> _TemporaryFileWrapper:
|
|
41
|
+
"""
|
|
42
|
+
Download an export.
|
|
43
|
+
|
|
44
|
+
:param export_id: UUID of the export to download
|
|
45
|
+
:returns: The downloaded export stored in a temporary file.
|
|
46
|
+
"""
|
|
47
|
+
try:
|
|
48
|
+
UUID(export_id)
|
|
49
|
+
except ValueError as e:
|
|
50
|
+
raise ValueError("export_id is not a valid uuid.") from e
|
|
51
|
+
|
|
52
|
+
logger.info(f"Downloading export ({export_id})...")
|
|
53
|
+
export: _TemporaryFileWrapper = self.api_client.request(
|
|
54
|
+
"DownloadExport", id=export_id
|
|
55
|
+
)
|
|
56
|
+
logger.info(f"Downloaded export ({export_id}) @ `{export.name}`")
|
|
57
|
+
return export
|
|
58
|
+
|
|
39
59
|
def download_latest_export(self) -> _TemporaryFileWrapper:
|
|
40
60
|
"""
|
|
41
61
|
Download the latest export in `done` state of the current corpus.
|
|
@@ -62,10 +82,5 @@ class CorpusMixin:
|
|
|
62
82
|
|
|
63
83
|
# Download latest export
|
|
64
84
|
export_id: str = exports[0]["id"]
|
|
65
|
-
logger.info(f"Downloading export ({export_id})...")
|
|
66
|
-
export: _TemporaryFileWrapper = self.api_client.request(
|
|
67
|
-
"DownloadExport", id=export_id
|
|
68
|
-
)
|
|
69
|
-
logger.info(f"Downloaded export ({export_id}) @ `{export.name}`")
|
|
70
85
|
|
|
71
|
-
return
|
|
86
|
+
return self.download_export(export_id)
|
arkindex_worker/worker/entity.py
CHANGED
|
@@ -302,7 +302,7 @@ class EntityMixin:
|
|
|
302
302
|
|
|
303
303
|
created_entities = [
|
|
304
304
|
created_entity
|
|
305
|
-
for batch in make_batches(entities, "
|
|
305
|
+
for batch in make_batches(entities, "entity", batch_size)
|
|
306
306
|
for created_entity in self.api_client.request(
|
|
307
307
|
"CreateTranscriptionEntities",
|
|
308
308
|
id=transcription.id,
|
arkindex_worker/worker/task.py
CHANGED
|
@@ -9,8 +9,8 @@ from typing import NewType
|
|
|
9
9
|
from uuid import UUID
|
|
10
10
|
|
|
11
11
|
import requests
|
|
12
|
-
from apistar.exceptions import ErrorResponse
|
|
13
12
|
|
|
13
|
+
from arkindex.exceptions import ErrorResponse
|
|
14
14
|
from arkindex_worker import logger
|
|
15
15
|
from arkindex_worker.utils import close_delete_file, create_tar_zst_archive
|
|
16
16
|
|
tests/test_dataset_worker.py
CHANGED
|
@@ -3,8 +3,8 @@ import uuid
|
|
|
3
3
|
from argparse import ArgumentTypeError
|
|
4
4
|
|
|
5
5
|
import pytest
|
|
6
|
-
from apistar.exceptions import ErrorResponse
|
|
7
6
|
|
|
7
|
+
from arkindex.exceptions import ErrorResponse
|
|
8
8
|
from arkindex_worker.models import Dataset, Set
|
|
9
9
|
from arkindex_worker.worker.dataset import (
|
|
10
10
|
DatasetState,
|
|
@@ -3,8 +3,8 @@ import re
|
|
|
3
3
|
from uuid import UUID
|
|
4
4
|
|
|
5
5
|
import pytest
|
|
6
|
-
from apistar.exceptions import ErrorResponse
|
|
7
6
|
|
|
7
|
+
from arkindex.exceptions import ErrorResponse
|
|
8
8
|
from arkindex_worker.cache import CachedClassification, CachedElement
|
|
9
9
|
from arkindex_worker.models import Element
|
|
10
10
|
from arkindex_worker.utils import DEFAULT_BATCH_SIZE
|
|
@@ -17,6 +17,92 @@ from . import BASE_API_CALLS
|
|
|
17
17
|
DELETE_PARAMETER = "DELETE_PARAMETER"
|
|
18
18
|
|
|
19
19
|
|
|
20
|
+
def test_load_corpus_classes_api_error(responses, mock_elements_worker):
|
|
21
|
+
responses.add(
|
|
22
|
+
responses.GET,
|
|
23
|
+
f"http://testserver/api/v1/corpus/{CORPUS_ID}/classes/",
|
|
24
|
+
status=418,
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
assert not mock_elements_worker.classes
|
|
28
|
+
with pytest.raises(
|
|
29
|
+
Exception, match="Stopping pagination as data will be incomplete"
|
|
30
|
+
):
|
|
31
|
+
mock_elements_worker.load_corpus_classes()
|
|
32
|
+
|
|
33
|
+
assert len(responses.calls) == len(BASE_API_CALLS) + 5
|
|
34
|
+
assert [
|
|
35
|
+
(call.request.method, call.request.url) for call in responses.calls
|
|
36
|
+
] == BASE_API_CALLS + [
|
|
37
|
+
# We do 5 retries
|
|
38
|
+
(
|
|
39
|
+
"GET",
|
|
40
|
+
f"http://testserver/api/v1/corpus/{CORPUS_ID}/classes/",
|
|
41
|
+
),
|
|
42
|
+
(
|
|
43
|
+
"GET",
|
|
44
|
+
f"http://testserver/api/v1/corpus/{CORPUS_ID}/classes/",
|
|
45
|
+
),
|
|
46
|
+
(
|
|
47
|
+
"GET",
|
|
48
|
+
f"http://testserver/api/v1/corpus/{CORPUS_ID}/classes/",
|
|
49
|
+
),
|
|
50
|
+
(
|
|
51
|
+
"GET",
|
|
52
|
+
f"http://testserver/api/v1/corpus/{CORPUS_ID}/classes/",
|
|
53
|
+
),
|
|
54
|
+
(
|
|
55
|
+
"GET",
|
|
56
|
+
f"http://testserver/api/v1/corpus/{CORPUS_ID}/classes/",
|
|
57
|
+
),
|
|
58
|
+
]
|
|
59
|
+
assert not mock_elements_worker.classes
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def test_load_corpus_classes(responses, mock_elements_worker):
|
|
63
|
+
responses.add(
|
|
64
|
+
responses.GET,
|
|
65
|
+
f"http://testserver/api/v1/corpus/{CORPUS_ID}/classes/",
|
|
66
|
+
status=200,
|
|
67
|
+
json={
|
|
68
|
+
"count": 3,
|
|
69
|
+
"next": None,
|
|
70
|
+
"results": [
|
|
71
|
+
{
|
|
72
|
+
"id": "0000",
|
|
73
|
+
"name": "good",
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
"id": "1111",
|
|
77
|
+
"name": "average",
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
"id": "2222",
|
|
81
|
+
"name": "bad",
|
|
82
|
+
},
|
|
83
|
+
],
|
|
84
|
+
},
|
|
85
|
+
)
|
|
86
|
+
|
|
87
|
+
assert not mock_elements_worker.classes
|
|
88
|
+
mock_elements_worker.load_corpus_classes()
|
|
89
|
+
|
|
90
|
+
assert len(responses.calls) == len(BASE_API_CALLS) + 1
|
|
91
|
+
assert [
|
|
92
|
+
(call.request.method, call.request.url) for call in responses.calls
|
|
93
|
+
] == BASE_API_CALLS + [
|
|
94
|
+
(
|
|
95
|
+
"GET",
|
|
96
|
+
f"http://testserver/api/v1/corpus/{CORPUS_ID}/classes/",
|
|
97
|
+
),
|
|
98
|
+
]
|
|
99
|
+
assert mock_elements_worker.classes == {
|
|
100
|
+
"good": "0000",
|
|
101
|
+
"average": "1111",
|
|
102
|
+
"bad": "2222",
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
|
|
20
106
|
def test_get_ml_class_id_load_classes(responses, mock_elements_worker):
|
|
21
107
|
responses.add(
|
|
22
108
|
responses.GET,
|
|
@@ -2,13 +2,44 @@ import re
|
|
|
2
2
|
import uuid
|
|
3
3
|
|
|
4
4
|
import pytest
|
|
5
|
-
from apistar.exceptions import ErrorResponse
|
|
6
5
|
|
|
6
|
+
from arkindex.exceptions import ErrorResponse
|
|
7
7
|
from arkindex_worker.worker.corpus import CorpusExportState
|
|
8
8
|
from tests import CORPUS_ID
|
|
9
9
|
from tests.test_elements_worker import BASE_API_CALLS
|
|
10
10
|
|
|
11
11
|
|
|
12
|
+
def test_download_export_not_a_uuid(responses, mock_elements_worker):
|
|
13
|
+
with pytest.raises(ValueError, match="export_id is not a valid uuid."):
|
|
14
|
+
mock_elements_worker.download_export("mon export")
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def test_download_export(responses, mock_elements_worker):
|
|
18
|
+
responses.add(
|
|
19
|
+
responses.GET,
|
|
20
|
+
"http://testserver/api/v1/export/aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeffff/",
|
|
21
|
+
status=302,
|
|
22
|
+
body=b"some SQLite export",
|
|
23
|
+
content_type="application/x-sqlite3",
|
|
24
|
+
stream=True,
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
export = mock_elements_worker.download_export(
|
|
28
|
+
"aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeffff"
|
|
29
|
+
)
|
|
30
|
+
assert export.name == "/tmp/aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeffff"
|
|
31
|
+
|
|
32
|
+
assert len(responses.calls) == len(BASE_API_CALLS) + 1
|
|
33
|
+
assert [
|
|
34
|
+
(call.request.method, call.request.url) for call in responses.calls
|
|
35
|
+
] == BASE_API_CALLS + [
|
|
36
|
+
(
|
|
37
|
+
"GET",
|
|
38
|
+
"http://testserver/api/v1/export/aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeffff/",
|
|
39
|
+
),
|
|
40
|
+
]
|
|
41
|
+
|
|
42
|
+
|
|
12
43
|
def mock_list_exports_call(responses, export_id):
|
|
13
44
|
responses.add(
|
|
14
45
|
responses.GET,
|
|
@@ -2,8 +2,8 @@ import json
|
|
|
2
2
|
import logging
|
|
3
3
|
|
|
4
4
|
import pytest
|
|
5
|
-
from apistar.exceptions import ErrorResponse
|
|
6
5
|
|
|
6
|
+
from arkindex.exceptions import ErrorResponse
|
|
7
7
|
from arkindex_worker.models import Dataset, Element, Set
|
|
8
8
|
from arkindex_worker.worker.dataset import DatasetState
|
|
9
9
|
from tests import PROCESS_ID
|