Skip to content

Commit dc0a418

Browse files
JorjMcKiejulian-smith-artifex-com
authored andcommitted
Add tests for table feature
1 parent 1ec7d35 commit dc0a418

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed

tests/resources/chinese-tables.pdf

372 KB
Binary file not shown.

tests/resources/chinese-tables.pickle

4.86 KB
Binary file not shown.

tests/test_tables.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import os
2+
import fitz
3+
import pickle
4+
5+
scriptdir = os.path.abspath(os.path.dirname(__file__))
6+
filename = os.path.join(scriptdir, "resources", "chinese-tables.pdf")
7+
pickle_file = os.path.join(scriptdir, "resources", "chinese-tables.pickle")
8+
9+
10+
def test_table1():
11+
"""Compare pickled tables with those of the current run."""
12+
pickle_in = open(pickle_file, "rb")
13+
doc = fitz.open(filename)
14+
page = doc[0]
15+
tabs = page.find_tables()
16+
cells = [tabs[0].cells, tabs[1].cells]
17+
extracts = [tabs[0].extract(), tabs[1].extract()]
18+
new_data = {"cells": cells, "extracts": extracts}
19+
old_data = pickle.load(pickle_in)
20+
assert old_data == new_data
21+
22+
23+
def test_table2():
24+
"""Confirm header properties."""
25+
doc = fitz.open(filename)
26+
page = doc[0]
27+
tab1, tab2 = page.find_tables().tables
28+
# both tables contain their header data
29+
assert tab1.header.external == False
30+
assert tab1.header.cells == tab1.rows[0].cells
31+
assert tab2.header.external == False
32+
assert tab2.header.cells == tab2.rows[0].cells

0 commit comments

Comments
 (0)