Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MRG]Added test case for method bbox_no_intersection from utils to check no intersection logic #252

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
"Test to check intersection logic when no intersection area returned"
import os
import sys

from pdfminer.pdfparser import PDFParser
from pdfminer.pdfdocument import PDFDocument
from pdfminer.pdfpage import PDFPage
from pdfminer.pdfpage import PDFTextExtractionNotAllowed
from pdfminer.pdfinterp import PDFResourceManager
from pdfminer.pdfinterp import PDFPageInterpreter
from pdfminer.converter import PDFPageAggregator
from pdfminer.layout import (
LAParams,
LTAnno,
LTChar,
LTTextLineHorizontal,
LTTextLineVertical,
LTImage,
LTTextBoxHorizontal
)

testdir = os.path.dirname(os.path.abspath(__file__))
testdir = os.path.join(testdir, "files")

from camelot.utils import bbox_intersection_area

def get_text_from_pdf(filename):
"Method to extract text object from pdf"
#https://stackoverflow.com/questions/22898145/how-to-extract-text-and-text-coordinates-from-a-pdf-file
#https://pdfminer-docs.readthedocs.io/programming.html#performing-layout-analysis
document = open(filename, 'rb')
#Create resource manager
rsrcmgr = PDFResourceManager()
# Set parameters for analysis.
laparams = LAParams()
# Create a PDF page aggregator object.
device = PDFPageAggregator(rsrcmgr, laparams=laparams)
interpreter = PDFPageInterpreter(rsrcmgr, device)
for page in PDFPage.get_pages(document):
interpreter.process_page(page)
# receive the LTPage object for the page.
layout = device.get_result()
for element in layout:
if isinstance(element, LTTextBoxHorizontal):
return element

def test_bbox_intersection_text():
"""
Test to check area of intersection between both boxes when no intersection area returned
"""
filename1 = os.path.join(testdir, "foo.pdf")
pdftextelement1 = get_text_from_pdf(filename1)
filename2 = os.path.join(testdir, "tabula/12s0324.pdf")
pdftextelement2 = get_text_from_pdf(filename2)

assert bbox_intersection_area(pdftextelement1, pdftextelement2) == 0.0