Merge in RR/cv-analysis from integrate-new-pyinfra to master
Squashed commit of the following:
commit f27b7eb342838b7a235a062a04363dc417f859ad
Author: Julius Unverfehrt <julius.unverfehrt@iqser.com>
Date: Thu Jun 23 14:24:03 2022 +0200
refactor table test
commit 9f57cc7d72bffc106c852041666b2f11eb6eacc3
Author: Julius Unverfehrt <julius.unverfehrt@iqser.com>
Date: Thu Jun 23 14:07:37 2022 +0200
debug bamboo
commit 30911cc5a34559a8b622634ddf974a9860481d17
Author: Julius Unverfehrt <julius.unverfehrt@iqser.com>
Date: Thu Jun 23 13:22:04 2022 +0200
track test data with dvc
commit 501460c3c99482879ae585872bd67fd67693c47a
Author: Julius Unverfehrt <julius.unverfehrt@iqser.com>
Date: Thu Jun 23 13:19:39 2022 +0200
untrack test data
commit f65ade167802901a6f402618c062df0120279df3
Author: Julius Unverfehrt <julius.unverfehrt@iqser.com>
Date: Thu Jun 23 12:02:43 2022 +0200
refactor&extend tests
commit 8c9dc41ddeda5b0f630a267e328d1c09f69bdb04
Author: Julius Unverfehrt <julius.unverfehrt@iqser.com>
Date: Thu Jun 23 09:36:26 2022 +0200
debug bamboo
commit f0b38130502475cf9bfa8632d3b0eb3a84b32b7d
Author: Julius Unverfehrt <julius.unverfehrt@iqser.com>
Date: Thu Jun 23 09:27:42 2022 +0200
debug bamboo
commit 0f188b4eb5293cf2bc4024fb397f161ad3b867bd
Author: Julius Unverfehrt <julius.unverfehrt@iqser.com>
Date: Thu Jun 23 09:23:38 2022 +0200
update build script
commit 281e13d822790deefa3d1a4f2519d300d84cded3
Author: Julius Unverfehrt <julius.unverfehrt@iqser.com>
Date: Thu Jun 23 09:21:31 2022 +0200
refactor tests
commit e90e84cb3b13b2903611985cc9eb3b5b7bf0262e
Author: Julius Unverfehrt <julius.unverfehrt@iqser.com>
Date: Thu Jun 23 08:54:29 2022 +0200
parametrize analysis_fn for server logic, refactor tests
commit 20734bcd14fec489e80ea6900dba64de4b190398
Author: Julius Unverfehrt <julius.unverfehrt@iqser.com>
Date: Thu Jun 23 08:53:16 2022 +0200
oursource tests from module
commit cd2c41762df1a231f2ed1d43c3b71d2443530ffa
Author: Julius Unverfehrt <julius.unverfehrt@iqser.com>
Date: Wed Jun 22 14:26:36 2022 +0200
add tests for analyse server logic
commit 16497ac4ec8b0d7064f6d8dd887c189f0d955a1d
Author: Julius Unverfehrt <julius.unverfehrt@iqser.com>
Date: Wed Jun 22 11:36:34 2022 +0200
debug build script
commit 45688c1c6d9b738cce519edcdc044aae3b800cd1
Author: Julius Unverfehrt <julius.unverfehrt@iqser.com>
Date: Wed Jun 22 11:33:13 2022 +0200
debug build script
commit 0576140916c0cd9d290dd02225621e5360665d71
Author: Julius Unverfehrt <julius.unverfehrt@iqser.com>
Date: Wed Jun 22 10:51:51 2022 +0200
update tests
commit fcbecdde95cef46bce46545af65d040cc918447b
Author: Julius Unverfehrt <julius.unverfehrt@iqser.com>
Date: Wed Jun 22 10:04:30 2022 +0200
rename operations, update requirements
commit 7b40f6d643bb332fd7dd0867d64f17db16ede5bb
Author: Julius Unverfehrt <julius.unverfehrt@iqser.com>
Date: Wed Jun 22 10:03:48 2022 +0200
adjust deployment scripts
commit b66f937d2e0abc79e68bce6ee058bc0bd5cb86e5
Author: Julius Unverfehrt <julius.unverfehrt@iqser.com>
Date: Tue Jun 21 13:32:44 2022 +0200
refactor server logic, use operation2function logic for pyinfra server
commit 5e7247f85cacaa6c0643796a98f13642db3e59e1
Author: Julius Unverfehrt <julius.unverfehrt@iqser.com>
Date: Mon Jun 20 17:23:11 2022 +0200
add server logic for pyinfra 2
commit eecb985fed76af9404bd99f0104508efe7d75e35
Author: Julius Unverfehrt <julius.unverfehrt@iqser.com>
Date: Mon Jun 20 16:24:05 2022 +0200
add server logic for pyinfra 2.0.0
... and 3 more commits
62 lines
1.8 KiB
Python
62 lines
1.8 KiB
Python
import gzip
|
|
import io
|
|
|
|
import numpy as np
|
|
import pytest
|
|
from PIL import Image
|
|
from funcy import first
|
|
|
|
from cv_analysis.pyinfra_compat import get_analysis_fn
|
|
from cv_analysis.utils.preprocessing import open_img_from_bytes
|
|
from cv_analysis.utils.structures import Rectangle
|
|
from incl.pyinfra.pyinfra.server.packing import bytes_to_string, string_to_bytes
|
|
|
|
|
|
@pytest.fixture
|
|
def random_image():
|
|
return np.random.rand(100, 100, 3) * 255
|
|
|
|
|
|
@pytest.fixture
|
|
def random_image_as_bytes_and_compressed(random_image):
|
|
image = Image.fromarray(random_image.astype("uint8")).convert("RGBA")
|
|
img_byte_arr = io.BytesIO()
|
|
image.save(img_byte_arr, format="PNG")
|
|
return gzip.compress(img_byte_arr.getvalue())
|
|
|
|
|
|
@pytest.fixture
|
|
def random_image_metadata_package(random_image_as_bytes_and_compressed):
|
|
data = bytes_to_string(random_image_as_bytes_and_compressed)
|
|
return [{"data": data, "metadata": {"key": "value", "key2": "value2"}}]
|
|
|
|
|
|
@pytest.fixture
|
|
def expected_analyse_metadata(operation, random_image_metadata_package):
|
|
metadata = first(random_image_metadata_package)
|
|
image = open_img_from_bytes(gzip.decompress(string_to_bytes(metadata["data"])))
|
|
wrapped_metadata = {
|
|
**metadata["metadata"],
|
|
"pageWidth": image.shape[1],
|
|
"pageHeight": image.shape[0],
|
|
}
|
|
|
|
if operation == "mock":
|
|
return {
|
|
**wrapped_metadata,
|
|
"cells": [{"x": 0, "y": 0, "width": image.shape[1], "height": image.shape[0]}],
|
|
}
|
|
if operation == "table_parsing":
|
|
return {}
|
|
|
|
|
|
@pytest.fixture
|
|
def analyse_fn(operation):
|
|
if operation == "mock":
|
|
|
|
def analyse_mock(image: np.ndarray):
|
|
return [Rectangle.from_xywh((0, 0, image.shape[1], image.shape[0]))]
|
|
|
|
return analyse_mock
|
|
return get_analysis_fn(operation)
|