arkindex-base-worker 0.4.0rc3__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.0rc3.dist-info → arkindex_base_worker-0.4.0rc4.dist-info}/METADATA +15 -14
- {arkindex_base_worker-0.4.0rc3.dist-info → arkindex_base_worker-0.4.0rc4.dist-info}/RECORD +21 -13
- {arkindex_base_worker-0.4.0rc3.dist-info → arkindex_base_worker-0.4.0rc4.dist-info}/WHEEL +1 -1
- arkindex_worker/cache.py +1 -1
- tests/test_elements_worker/{test_classifications.py → test_classification.py} +86 -0
- tests/test_elements_worker/test_corpus.py +31 -31
- 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} +0 -153
- tests/test_elements_worker/test_entity_list_and_check.py +160 -0
- 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 +525 -88
- tests/test_image.py +181 -198
- tests/test_elements_worker/test_elements.py +0 -3704
- tests/test_elements_worker/test_transcriptions.py +0 -2252
- {arkindex_base_worker-0.4.0rc3.dist-info → arkindex_base_worker-0.4.0rc4.dist-info}/LICENSE +0 -0
- {arkindex_base_worker-0.4.0rc3.dist-info → arkindex_base_worker-0.4.0rc4.dist-info}/top_level.txt +0 -0
tests/test_image.py
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import logging
|
|
2
2
|
import math
|
|
3
|
-
import unittest
|
|
4
3
|
import uuid
|
|
5
4
|
from io import BytesIO
|
|
6
5
|
from operator import attrgetter
|
|
@@ -219,74 +218,33 @@ def test_open_image_rotate_mirror(rotation_angle, mirrored, expected_path):
|
|
|
219
218
|
assert _root_mean_square(expected, actual) <= 15.0
|
|
220
219
|
|
|
221
220
|
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
[
|
|
248
|
-
|
|
249
|
-
[197, 206],
|
|
250
|
-
[99, 200],
|
|
251
|
-
]
|
|
252
|
-
assert (
|
|
253
|
-
trim_polygon(bad_polygon, TEST_IMAGE["width"], TEST_IMAGE["height"])
|
|
254
|
-
== expected_polygon
|
|
255
|
-
)
|
|
256
|
-
|
|
257
|
-
def test_trim_polygon_good_polygon(self):
|
|
258
|
-
good_polygon = (
|
|
259
|
-
(12, 56),
|
|
260
|
-
(29, 60),
|
|
261
|
-
(35, 61),
|
|
262
|
-
(42, 59),
|
|
263
|
-
(58, 57),
|
|
264
|
-
(65, 61),
|
|
265
|
-
(72, 57),
|
|
266
|
-
(12, 56),
|
|
267
|
-
)
|
|
268
|
-
expected_polygon = [
|
|
269
|
-
[12, 56],
|
|
270
|
-
[29, 60],
|
|
271
|
-
[35, 61],
|
|
272
|
-
[42, 59],
|
|
273
|
-
[58, 57],
|
|
274
|
-
[65, 61],
|
|
275
|
-
[72, 57],
|
|
276
|
-
[12, 56],
|
|
277
|
-
]
|
|
278
|
-
assert (
|
|
279
|
-
trim_polygon(good_polygon, TEST_IMAGE["width"], TEST_IMAGE["height"])
|
|
280
|
-
== expected_polygon
|
|
281
|
-
)
|
|
282
|
-
|
|
283
|
-
def test_trim_polygon_invalid_polygon(self):
|
|
284
|
-
"""
|
|
285
|
-
An assertion error is raised the polygon input isn't a list or tuple
|
|
286
|
-
"""
|
|
287
|
-
bad_polygon = {
|
|
288
|
-
"polygon": [
|
|
289
|
-
[99, 200],
|
|
221
|
+
@pytest.mark.parametrize(
|
|
222
|
+
("polygon", "error"),
|
|
223
|
+
[
|
|
224
|
+
# Polygon input isn't a list or tuple
|
|
225
|
+
(
|
|
226
|
+
{
|
|
227
|
+
"polygon": [
|
|
228
|
+
[99, 200],
|
|
229
|
+
[25, 224],
|
|
230
|
+
[0, 0],
|
|
231
|
+
[0, 300],
|
|
232
|
+
[102, 300],
|
|
233
|
+
[260, 300],
|
|
234
|
+
[288, 295],
|
|
235
|
+
[296, 260],
|
|
236
|
+
[352, 259],
|
|
237
|
+
[106, 210],
|
|
238
|
+
[197, 206],
|
|
239
|
+
[99, 208],
|
|
240
|
+
]
|
|
241
|
+
},
|
|
242
|
+
"Input polygon must be a valid list or tuple of points.",
|
|
243
|
+
),
|
|
244
|
+
# Point coordinates are not integers
|
|
245
|
+
(
|
|
246
|
+
[
|
|
247
|
+
[9.9, 200],
|
|
290
248
|
[25, 224],
|
|
291
249
|
[0, 0],
|
|
292
250
|
[0, 300],
|
|
@@ -297,136 +255,161 @@ class TestTrimPolygon(unittest.TestCase):
|
|
|
297
255
|
[352, 259],
|
|
298
256
|
[106, 210],
|
|
299
257
|
[197, 206],
|
|
300
|
-
[99,
|
|
301
|
-
]
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
[
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
[
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
258
|
+
[99, 20.8],
|
|
259
|
+
],
|
|
260
|
+
"Polygon point coordinates must be integers.",
|
|
261
|
+
),
|
|
262
|
+
# Point coordinates are not lists or tuples
|
|
263
|
+
(
|
|
264
|
+
[
|
|
265
|
+
[12, 56],
|
|
266
|
+
[29, 60],
|
|
267
|
+
[35, 61],
|
|
268
|
+
"[42, 59]",
|
|
269
|
+
[58, 57],
|
|
270
|
+
[65, 61],
|
|
271
|
+
[72, 57],
|
|
272
|
+
[12, 56],
|
|
273
|
+
],
|
|
274
|
+
"Polygon points must be tuples or lists.",
|
|
275
|
+
),
|
|
276
|
+
# Point coordinates are not lists or tuples of length 2
|
|
277
|
+
(
|
|
278
|
+
[
|
|
279
|
+
[12, 56],
|
|
280
|
+
[29, 60, 3],
|
|
281
|
+
[35, 61],
|
|
282
|
+
[42, 59],
|
|
283
|
+
[58, 57],
|
|
284
|
+
[65, 61],
|
|
285
|
+
[72, 57],
|
|
286
|
+
[12, 56],
|
|
287
|
+
],
|
|
288
|
+
"Polygon points must be tuples or lists of 2 elements.",
|
|
289
|
+
),
|
|
290
|
+
# None of the polygon's points are inside the image
|
|
291
|
+
(
|
|
292
|
+
[
|
|
293
|
+
[999, 200],
|
|
294
|
+
[1097, 224],
|
|
295
|
+
[1020, 251],
|
|
296
|
+
[1232, 350],
|
|
297
|
+
[1312, 364],
|
|
298
|
+
[1325, 310],
|
|
299
|
+
[1318, 295],
|
|
300
|
+
[1296, 260],
|
|
301
|
+
[1352, 259],
|
|
302
|
+
[1006, 210],
|
|
303
|
+
[997, 206],
|
|
304
|
+
[999, 200],
|
|
305
|
+
],
|
|
306
|
+
"This polygon is entirely outside the image's bounds.",
|
|
307
|
+
),
|
|
308
|
+
],
|
|
309
|
+
)
|
|
310
|
+
def test_trim_polygon_errors(polygon, error):
|
|
311
|
+
with pytest.raises(AssertionError, match=error):
|
|
312
|
+
trim_polygon(polygon, TEST_IMAGE["width"], TEST_IMAGE["height"])
|
|
345
313
|
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
]
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
]
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
)
|
|
429
|
-
|
|
314
|
+
|
|
315
|
+
def test_trim_polygon_negative_coordinates():
|
|
316
|
+
"""
|
|
317
|
+
Negative coordinates are ignored and replaced by 0 with no error being thrown
|
|
318
|
+
"""
|
|
319
|
+
polygon = [
|
|
320
|
+
[99, 200],
|
|
321
|
+
[25, 224],
|
|
322
|
+
[-8, -52],
|
|
323
|
+
[-12, 350],
|
|
324
|
+
[102, 364],
|
|
325
|
+
[260, 310],
|
|
326
|
+
[288, 295],
|
|
327
|
+
[296, 260],
|
|
328
|
+
[352, 259],
|
|
329
|
+
[106, 210],
|
|
330
|
+
[197, 206],
|
|
331
|
+
[99, 200],
|
|
332
|
+
]
|
|
333
|
+
expected_polygon = [
|
|
334
|
+
[99, 200],
|
|
335
|
+
[25, 224],
|
|
336
|
+
[0, 0],
|
|
337
|
+
[0, 300],
|
|
338
|
+
[102, 300],
|
|
339
|
+
[260, 300],
|
|
340
|
+
[288, 295],
|
|
341
|
+
[296, 260],
|
|
342
|
+
[352, 259],
|
|
343
|
+
[106, 210],
|
|
344
|
+
[197, 206],
|
|
345
|
+
[99, 200],
|
|
346
|
+
]
|
|
347
|
+
assert (
|
|
348
|
+
trim_polygon(polygon, TEST_IMAGE["width"], TEST_IMAGE["height"])
|
|
349
|
+
== expected_polygon
|
|
350
|
+
)
|
|
351
|
+
|
|
352
|
+
|
|
353
|
+
def test_trim_polygon_partially_outside_image():
|
|
354
|
+
polygon = [
|
|
355
|
+
[99, 200],
|
|
356
|
+
[197, 224],
|
|
357
|
+
[120, 251],
|
|
358
|
+
[232, 350],
|
|
359
|
+
[312, 364],
|
|
360
|
+
[325, 310],
|
|
361
|
+
[318, 295],
|
|
362
|
+
[296, 260],
|
|
363
|
+
[352, 259],
|
|
364
|
+
[106, 210],
|
|
365
|
+
[197, 206],
|
|
366
|
+
[99, 200],
|
|
367
|
+
]
|
|
368
|
+
expected_polygon = [
|
|
369
|
+
[99, 200],
|
|
370
|
+
[197, 224],
|
|
371
|
+
[120, 251],
|
|
372
|
+
[232, 300],
|
|
373
|
+
[312, 300],
|
|
374
|
+
[325, 300],
|
|
375
|
+
[318, 295],
|
|
376
|
+
[296, 260],
|
|
377
|
+
[352, 259],
|
|
378
|
+
[106, 210],
|
|
379
|
+
[197, 206],
|
|
380
|
+
[99, 200],
|
|
381
|
+
]
|
|
382
|
+
assert (
|
|
383
|
+
trim_polygon(polygon, TEST_IMAGE["width"], TEST_IMAGE["height"])
|
|
384
|
+
== expected_polygon
|
|
385
|
+
)
|
|
386
|
+
|
|
387
|
+
|
|
388
|
+
def test_trim_polygon():
|
|
389
|
+
polygon = (
|
|
390
|
+
(12, 56),
|
|
391
|
+
(29, 60),
|
|
392
|
+
(35, 61),
|
|
393
|
+
(42, 59),
|
|
394
|
+
(58, 57),
|
|
395
|
+
(65, 61),
|
|
396
|
+
(72, 57),
|
|
397
|
+
(12, 56),
|
|
398
|
+
)
|
|
399
|
+
expected_polygon = [
|
|
400
|
+
[12, 56],
|
|
401
|
+
[29, 60],
|
|
402
|
+
[35, 61],
|
|
403
|
+
[42, 59],
|
|
404
|
+
[58, 57],
|
|
405
|
+
[65, 61],
|
|
406
|
+
[72, 57],
|
|
407
|
+
[12, 56],
|
|
408
|
+
]
|
|
409
|
+
assert (
|
|
410
|
+
trim_polygon(polygon, TEST_IMAGE["width"], TEST_IMAGE["height"])
|
|
411
|
+
== expected_polygon
|
|
412
|
+
)
|
|
430
413
|
|
|
431
414
|
|
|
432
415
|
@pytest.mark.parametrize(
|