Mercurial > hgrepos > Python2 > PyMuPDF
comparison tests/test_cluster_drawings.py @ 1:1d09e1dec1d9 upstream
ADD: PyMuPDF v1.26.4: the original sdist.
It does not yet contain MuPDF. This normally will be downloaded when
building PyMuPDF.
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Mon, 15 Sep 2025 11:37:51 +0200 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 1:1d09e1dec1d9 |
|---|---|
| 1 import os | |
| 2 import pymupdf | |
| 3 | |
| 4 scriptdir = os.path.dirname(__file__) | |
| 5 | |
| 6 | |
| 7 def test_cluster1(): | |
| 8 """Confirm correct identification of known examples.""" | |
| 9 if not hasattr(pymupdf, "mupdf"): | |
| 10 print("Not executing 'test_cluster1' in classic") | |
| 11 return | |
| 12 filename = os.path.join(scriptdir, "resources", "symbol-list.pdf") | |
| 13 doc = pymupdf.open(filename) | |
| 14 page = doc[0] | |
| 15 assert len(page.cluster_drawings()) == 10 | |
| 16 filename = os.path.join(scriptdir, "resources", "chinese-tables.pdf") | |
| 17 doc = pymupdf.open(filename) | |
| 18 page = doc[0] | |
| 19 assert len(page.cluster_drawings()) == 2 | |
| 20 | |
| 21 | |
| 22 def test_cluster2(): | |
| 23 """Join disjoint but neighbored drawings.""" | |
| 24 if not hasattr(pymupdf, "mupdf"): | |
| 25 print("Not executing 'test_cluster2' in classic") | |
| 26 return | |
| 27 doc = pymupdf.open() | |
| 28 page = doc.new_page() | |
| 29 r1 = pymupdf.Rect(100, 100, 200, 200) | |
| 30 r2 = pymupdf.Rect(203, 203, 400, 400) | |
| 31 page.draw_rect(r1) | |
| 32 page.draw_rect(r2) | |
| 33 assert page.cluster_drawings() == [r1 | r2] | |
| 34 | |
| 35 | |
| 36 def test_cluster3(): | |
| 37 """Confirm as separate if neighborhood threshold exceeded.""" | |
| 38 if not hasattr(pymupdf, "mupdf"): | |
| 39 print("Not executing 'test_cluster3' in classic") | |
| 40 return | |
| 41 doc = pymupdf.open() | |
| 42 page = doc.new_page() | |
| 43 r1 = pymupdf.Rect(100, 100, 200, 200) | |
| 44 r2 = pymupdf.Rect(204, 200, 400, 400) | |
| 45 page.draw_rect(r1) | |
| 46 page.draw_rect(r2) | |
| 47 assert page.cluster_drawings() == [r1, r2] |
