cv-analysis-service/tests/test_table_parsing.py

38 lines
929 B
Python

import pytest
from vidocp.table_parsing import parse_table
import numpy as np
import pdf2image
@pytest.fixture()
def rects():
page_index = 0
pdf_path = "/home/lillian/vidocp/tests/VV-313450.pdf"
page = pdf2image.convert_from_path(pdf_path, first_page=page_index + 1, last_page=page_index + 1)[0]
page = np.array(page)
rectangles = parse_table(page)
return rectangles
def test_num_of_rects(rects):
assert len(rects) == 49
def test_range_of_rects(rects):
expected_range = ((210, 605), (1430, 1620))
topleft = min(rects)
x, y, w, h = max(rects)
bottomright = (x + w, y + h)
assert topleft >= expected_range[0]
assert bottomright <= expected_range[1]
def test_rects_in_range(rects):
x, y, w, h = min(rects)
minimum = (x, y)
x, y, w, h = max(rects)
maximum = (x + w, y + h)
for (x, y, w, h) in rects:
assert minimum <= (x, y) <= maximum