manually added tests from test branch to avoid major conflicts
This commit is contained in:
parent
a089fa5e42
commit
fa479adfb0
28
tests/test_layout_parsing.py
Normal file
28
tests/test_layout_parsing.py
Normal file
@ -0,0 +1,28 @@
|
||||
from vidocp.layout_parsing import parse_layout
|
||||
import pytest
|
||||
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_layout(page)
|
||||
return rectangles
|
||||
|
||||
|
||||
def test_number_of_layout_boxes(rects):
|
||||
assert len([[x] for x in rects]) == 53
|
||||
|
||||
|
||||
def test_layout_rects(rects):
|
||||
for rect in rects:
|
||||
x, y, w, h = rect
|
||||
possible_xrange = (x, x + w)
|
||||
possible_yrange = (y, y + h)
|
||||
assert all(x <= possible_xrange[0] and x + w >= possible_xrange[1] for (x, y, w, h) in rects)
|
||||
assert all(x <= possible_yrange[0] and x + w >= possible_yrange[1] for (x, y, w, h) in rects)
|
||||
|
||||
34
tests/test_redaction_detection.py
Normal file
34
tests/test_redaction_detection.py
Normal file
@ -0,0 +1,34 @@
|
||||
from vidocp.redaction_detection import find_redactions
|
||||
import numpy as np
|
||||
import pytest
|
||||
import pdf2image
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
def image():
|
||||
page_index = 0
|
||||
pdf_path = "/home/lillian/vidocp/tests/CropBoxNotEqualToMediabox_redacted.pdf"
|
||||
page = pdf2image.convert_from_path(pdf_path, first_page=page_index + 1, last_page=page_index + 1)[0]
|
||||
page = np.array(page)
|
||||
return page
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
def contours(image):
|
||||
redaction_contours = find_redactions(image)
|
||||
return redaction_contours
|
||||
|
||||
|
||||
def test_number_of_redaction(contours):
|
||||
assert len(list(contours)) == 1
|
||||
|
||||
|
||||
def test_is_black(image, contours):
|
||||
for contour in contours:
|
||||
cont = contour.tolist()
|
||||
x1, y1 = min(cont)[0]
|
||||
x2, y2 = max(cont)[0]
|
||||
redaction = image[y1:y2, x1:x2]
|
||||
for pixel in redaction:
|
||||
assert pixel.all() < 10
|
||||
|
||||
@ -26,3 +26,13 @@ def test_range_of_rects(rects):
|
||||
|
||||
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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user