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

Function test_boxes_param

tests/test_tables.py:342–371  ·  view source on GitHub ↗

Confirm acceptance of supplied boxes list.

()

Source from the content-addressed store, hash-verified

340
341
342def test_boxes_param():
343 """Confirm acceptance of supplied boxes list."""
344 filename = os.path.join(scriptdir, "resources", "small-table.pdf")
345 doc = pymupdf.open(filename)
346 page = doc[0]
347 paths = page.get_drawings()
348 box0 = page.cluster_drawings(drawings=paths)[0]
349 boxes = [box0]
350 words = page.get_text("words")
351 x_vals = [w[0] - 5 for w in words if w[4] in ("min", "max", "avg")]
352 for x in x_vals:
353 r = +box0
354 r.x1 = x
355 boxes.append(r)
356
357 y_vals = sorted(set([round(w[3]) for w in words]))
358 for y in y_vals[:-1]: # skip last one to avoid empty row
359 r = +box0
360 r.y1 = y
361 boxes.append(r)
362
363 tabs = page.find_tables(paths=[], add_boxes=boxes)
364 tab = tabs.tables[0]
365 assert tab.extract() == [
366 ["Boiling Points °C", "min", "max", "avg"],
367 ["Noble gases", "-269", "-62", "-170.5"],
368 ["Nonmetals", "-253", "4827", "414.1"],
369 ["Metalloids", "335", "3900", "741.5"],
370 ["Metals", "357", ">5000", "2755.9"],
371 ]
372
373
374def test_dotted_grid():

Callers

nothing calls this directly

Calls 5

get_drawingsMethod · 0.80
cluster_drawingsMethod · 0.80
extractMethod · 0.80
get_textMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…