MCPcopy Create free account
hub / github.com/pymupdf/PyMuPDF / test_table1

Function test_table1

tests/test_tables.py:15–37  ·  view source on GitHub ↗

Compare pickled tables with those of the current run.

()

Source from the content-addressed store, hash-verified

13
14
15def test_table1():
16 """Compare pickled tables with those of the current run."""
17 pickle_in = open(pickle_file, "rb")
18 doc = pymupdf.open(filename)
19 page = doc[0]
20 tabs = page.find_tables()
21 cells = tabs[0].cells + tabs[1].cells # all table cell tuples on page
22 extracts = [tabs[0].extract(), tabs[1].extract()] # all table cell content
23 old_data = pickle.load(pickle_in) # previously saved data
24
25 # Compare cell contents
26 assert old_data["extracts"] == extracts # same cell contents
27
28 # Compare cell coordinates.
29 # Cell rectangles may get somewhat larger due to more cautious border
30 # computations, but any differences must be small.
31 old_cells = old_data["cells"][0] + old_data["cells"][1]
32 assert len(cells) == len(old_cells)
33 for i in range(len(cells)):
34 c1 = pymupdf.Rect(cells[i]) # new cell coordinates
35 c0 = pymupdf.Rect(old_cells[i]) # old cell coordinates
36 assert c0 in c1 # always: old contained in new
37 assert abs(c1 - c0) < 0.2 # difference must be small
38
39
40def test_table2():

Callers

nothing calls this directly

Calls 1

extractMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…