1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
|
# encoding utf-8
"""
* Confirm sample doc has no links and no annots.
* Confirm proper release of file handles via Document.close()
* Confirm properly raising exceptions in document creation
"""
import io
import os
import fitz
scriptdir = os.path.abspath(os.path.dirname(__file__))
filename = os.path.join(scriptdir, "resources", "001003ED.pdf")
def test_haslinks():
doc = fitz.open(filename)
assert doc.has_links() == False
def test_hasannots():
doc = fitz.open(filename)
assert doc.has_annots() == False
def test_haswidgets():
doc = fitz.open(filename)
assert doc.is_form_pdf == False
def test_isrepaired():
doc = fitz.open(filename)
assert doc.is_repaired == False
fitz.TOOLS.mupdf_warnings()
def test_isdirty():
doc = fitz.open(filename)
assert doc.is_dirty == False
def test_cansaveincrementally():
doc = fitz.open(filename)
assert doc.can_save_incrementally() == True
def test_iswrapped():
doc = fitz.open(filename)
page = doc[0]
assert page.is_wrapped
def test_wrapcontents():
doc = fitz.open(filename)
page = doc[0]
page.wrap_contents()
xref = page.get_contents()[0]
cont = page.read_contents()
doc.update_stream(xref, cont)
page.set_contents(xref)
assert len(page.get_contents()) == 1
page.clean_contents()
def test_config():
assert fitz.TOOLS.fitz_config["py-memory"] in (True, False)
def test_glyphnames():
name = "infinity"
infinity = fitz.glyph_name_to_unicode(name)
assert fitz.unicode_to_glyph_name(infinity) == name
def test_rgbcodes():
sRGB = 0xFFFFFF
assert fitz.sRGB_to_pdf(sRGB) == (1, 1, 1)
assert fitz.sRGB_to_rgb(sRGB) == (255, 255, 255)
def test_pdfstring():
fitz.get_pdf_now()
fitz.get_pdf_str("Beijing, chinesisch 北京")
fitz.get_text_length("Beijing, chinesisch 北京", fontname="china-s")
fitz.get_pdf_str("Latin characters êßöäü")
def test_open_exceptions():
try:
doc = fitz.open(filename, filetype="xps")
except RuntimeError as e:
assert repr(e).startswith("FileDataError")
try:
doc = fitz.open(filename, filetype="xxx")
except Exception as e:
assert repr(e).startswith("ValueError")
try:
doc = fitz.open("x.y")
except Exception as e:
assert repr(e).startswith("FileNotFoundError")
try:
doc = fitz.open("pdf", b"")
except RuntimeError as e:
assert repr(e).startswith("EmptyFileError")
def test_bug1945():
pdf = fitz.open(f'{scriptdir}/resources/bug1945.pdf')
buffer_ = io.BytesIO()
pdf.save(buffer_, clean=True)
def test_bug1971():
for _ in range(2):
doc = fitz.Document(f'{scriptdir}/resources/bug1971.pdf')
page = next(doc.pages())
page.get_drawings()
doc.close()
def test_default_font():
f = fitz.Font()
assert str(f) == "Font('Noto Serif Regular')"
assert repr(f) == "Font('Noto Serif Regular')"
|