arkindex-base-worker 0.4.0rc3__py3-none-any.whl → 0.4.0rc5__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.
Files changed (26) hide show
  1. {arkindex_base_worker-0.4.0rc3.dist-info → arkindex_base_worker-0.4.0rc5.dist-info}/METADATA +15 -14
  2. {arkindex_base_worker-0.4.0rc3.dist-info → arkindex_base_worker-0.4.0rc5.dist-info}/RECORD +24 -16
  3. {arkindex_base_worker-0.4.0rc3.dist-info → arkindex_base_worker-0.4.0rc5.dist-info}/WHEEL +1 -1
  4. arkindex_worker/cache.py +1 -1
  5. arkindex_worker/worker/__init__.py +6 -2
  6. arkindex_worker/worker/entity.py +8 -19
  7. arkindex_worker/worker/process.py +5 -0
  8. tests/test_elements_worker/{test_classifications.py → test_classification.py} +86 -0
  9. tests/test_elements_worker/test_corpus.py +31 -31
  10. tests/test_elements_worker/test_element.py +427 -0
  11. tests/test_elements_worker/test_element_create_multiple.py +715 -0
  12. tests/test_elements_worker/test_element_create_single.py +528 -0
  13. tests/test_elements_worker/test_element_list_children.py +969 -0
  14. tests/test_elements_worker/test_element_list_parents.py +530 -0
  15. tests/test_elements_worker/{test_entities.py → test_entity_create.py} +42 -245
  16. tests/test_elements_worker/test_entity_list_and_check.py +160 -0
  17. tests/test_elements_worker/test_transcription_create.py +873 -0
  18. tests/test_elements_worker/test_transcription_create_with_elements.py +951 -0
  19. tests/test_elements_worker/test_transcription_list.py +450 -0
  20. tests/test_elements_worker/test_version.py +60 -0
  21. tests/test_elements_worker/test_worker.py +525 -88
  22. tests/test_image.py +181 -198
  23. tests/test_elements_worker/test_elements.py +0 -3704
  24. tests/test_elements_worker/test_transcriptions.py +0 -2252
  25. {arkindex_base_worker-0.4.0rc3.dist-info → arkindex_base_worker-0.4.0rc5.dist-info}/LICENSE +0 -0
  26. {arkindex_base_worker-0.4.0rc3.dist-info → arkindex_base_worker-0.4.0rc5.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
- class TestTrimPolygon(unittest.TestCase):
223
- def test_trim_polygon_partially_outside_image(self):
224
- bad_polygon = [
225
- [99, 200],
226
- [197, 224],
227
- [120, 251],
228
- [232, 350],
229
- [312, 364],
230
- [325, 310],
231
- [318, 295],
232
- [296, 260],
233
- [352, 259],
234
- [106, 210],
235
- [197, 206],
236
- [99, 200],
237
- ]
238
- expected_polygon = [
239
- [99, 200],
240
- [197, 224],
241
- [120, 251],
242
- [232, 300],
243
- [312, 300],
244
- [325, 300],
245
- [318, 295],
246
- [296, 260],
247
- [352, 259],
248
- [106, 210],
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, 208],
301
- ]
302
- }
303
- with pytest.raises(
304
- AssertionError,
305
- match="Input polygon must be a valid list or tuple of points.",
306
- ):
307
- trim_polygon(bad_polygon, TEST_IMAGE["width"], TEST_IMAGE["height"])
308
-
309
- def test_trim_polygon_negative_coordinates(self):
310
- """
311
- Negative coordinates are ignored and replaced by 0 with no error being thrown
312
- """
313
- bad_polygon = [
314
- [99, 200],
315
- [25, 224],
316
- [-8, -52],
317
- [-12, 350],
318
- [102, 364],
319
- [260, 310],
320
- [288, 295],
321
- [296, 260],
322
- [352, 259],
323
- [106, 210],
324
- [197, 206],
325
- [99, 200],
326
- ]
327
- expected_polygon = [
328
- [99, 200],
329
- [25, 224],
330
- [0, 0],
331
- [0, 300],
332
- [102, 300],
333
- [260, 300],
334
- [288, 295],
335
- [296, 260],
336
- [352, 259],
337
- [106, 210],
338
- [197, 206],
339
- [99, 200],
340
- ]
341
- assert (
342
- trim_polygon(bad_polygon, TEST_IMAGE["width"], TEST_IMAGE["height"])
343
- == expected_polygon
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
- def test_trim_polygon_outside_image_error(self):
347
- """
348
- An assertion error is raised when none of the polygon's points are inside the image
349
- """
350
- bad_polygon = [
351
- [999, 200],
352
- [1097, 224],
353
- [1020, 251],
354
- [1232, 350],
355
- [1312, 364],
356
- [1325, 310],
357
- [1318, 295],
358
- [1296, 260],
359
- [1352, 259],
360
- [1006, 210],
361
- [997, 206],
362
- [999, 200],
363
- ]
364
- with pytest.raises(
365
- AssertionError, match="This polygon is entirely outside the image's bounds."
366
- ):
367
- trim_polygon(bad_polygon, TEST_IMAGE["width"], TEST_IMAGE["height"])
368
-
369
- def test_trim_polygon_float_coordinates(self):
370
- """
371
- An assertion error is raised when point coordinates are not integers
372
- """
373
- bad_polygon = [
374
- [9.9, 200],
375
- [25, 224],
376
- [0, 0],
377
- [0, 300],
378
- [102, 300],
379
- [260, 300],
380
- [288, 295],
381
- [296, 260],
382
- [352, 259],
383
- [106, 210],
384
- [197, 206],
385
- [99, 20.8],
386
- ]
387
- with pytest.raises(
388
- AssertionError, match="Polygon point coordinates must be integers."
389
- ):
390
- trim_polygon(bad_polygon, TEST_IMAGE["width"], TEST_IMAGE["height"])
391
-
392
- def test_trim_polygon_invalid_points_1(self):
393
- """
394
- An assertion error is raised when point coordinates are not lists or tuples
395
- """
396
- bad_polygon = [
397
- [12, 56],
398
- [29, 60],
399
- [35, 61],
400
- "[42, 59]",
401
- [58, 57],
402
- [65, 61],
403
- [72, 57],
404
- [12, 56],
405
- ]
406
- with pytest.raises(
407
- AssertionError, match="Polygon points must be tuples or lists."
408
- ):
409
- trim_polygon(bad_polygon, TEST_IMAGE["width"], TEST_IMAGE["height"])
410
-
411
- def test_trim_polygon_invalid_points_2(self):
412
- """
413
- An assertion error is raised when point coordinates are not lists or tuples of length 2
414
- """
415
- bad_polygon = [
416
- [12, 56],
417
- [29, 60, 3],
418
- [35, 61],
419
- [42, 59],
420
- [58, 57],
421
- [65, 61],
422
- [72, 57],
423
- [12, 56],
424
- ]
425
- with pytest.raises(
426
- AssertionError,
427
- match="Polygon points must be tuples or lists of 2 elements.",
428
- ):
429
- trim_polygon(bad_polygon, TEST_IMAGE["width"], TEST_IMAGE["height"])
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(