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

Function test_2954

tests/test_textextract.py:136–208  ·  view source on GitHub ↗

Check handling of unknown unicode characters, issue #2954, fixed in mupdf-1.23.9 with addition of FZ_STEXT_USE_CID_FOR_UNKNOWN_UNICODE.

()

Source from the content-addressed store, hash-verified

134 assert text1 == text0
135
136def test_2954():
137 '''
138 Check handling of unknown unicode characters, issue #2954, fixed in
139 mupdf-1.23.9 with addition of FZ_STEXT_USE_CID_FOR_UNKNOWN_UNICODE.
140 '''
141 path = os.path.abspath(f'{__file__}/../../tests/resources/test_2954.pdf')
142 flags0 = (0
143 | pymupdf.TEXT_PRESERVE_WHITESPACE
144 | pymupdf.TEXT_PRESERVE_LIGATURES
145 | pymupdf.TEXT_MEDIABOX_CLIP
146 )
147
148 document = pymupdf.Document(path)
149
150 expected_good = (
151 "IT-204-IP (2021) Page 3 of 5\nNYPA2514 12/06/21\nPartner's share of \n"
152 " modifications (see instructions)\n20\n State additions\nNumber\n"
153 "A ' Total amount\nB '\n State allocated amount\n"
154 "EA '\n20a\nEA '\n20b\nEA '\n20c\nEA '\n20d\nEA '\n20e\nEA '\n20f\n"
155 "Total addition modifications (total of column A, lines 20a through 20f)\n"
156 ". . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . \n"
157 "21\n21\n22\n State subtractions\n"
158 "Number\nA ' Total amount\nB '\n State allocated amount\n"
159 "ES '\n22a\nES '\n22b\nES '\n22c\nES '\n22d\nES '\n22e\nES '\n22f\n23\n23\n"
160 "Total subtraction modifications (total of column A, lines 22a through 22f). . . . . . . . . . . . . . . . . . . . . . . . . . . . \n"
161 "Additions to itemized deductions\n24\nAmount\n"
162 "Letter\n"
163 "24a\n24b\n24c\n24d\n24e\n24f\n"
164 "Total additions to itemized deductions (add lines 24a through 24f)\n"
165 ". . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . \n"
166 "25\n25\n"
167 "Subtractions from itemized deductions\n"
168 "26\nLetter\nAmount\n26a\n26b\n26c\n26d\n26e\n26f\n"
169 "Total subtractions from itemized deductions (add lines 26a through 26f) . . . . . . . . . . . . . . . . . . . . . . . . . . . . \n"
170 "27\n27\n"
171 "This line intentionally left blank. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . \n"
172 "28\n28\n118003213032\n"
173 )
174
175 def check_good(text):
176 '''
177 Returns true if `text` is approximately the same as `expected_good`.
178
179 2024-01-09: MuPDF master and 1.23.x give slightly different 'good'
180 output, differing in a missing newline. So we compare without newlines.
181 '''
182 return text.replace('\n', '') == expected_good.replace('\n', '')
183
184 n_fffd_good = 0
185 n_fffd_bad = 749
186
187 def get(flags=None):
188 text = [page.get_text(flags=flags) for page in document]
189 assert len(text) == 1
190 text = text[0]
191 n_fffd = text.count(chr(0xfffd))
192 if 0:
193 # This print() fails on Windows with UnicodeEncodeError.

Callers

nothing calls this directly

Calls 2

check_goodFunction · 0.85
getFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…