mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-08 10:44:09 -04:00
Add a build test for podofo
This commit is contained in:
parent
bb4671c22b
commit
615d1104d2
@ -174,6 +174,10 @@ def test_psutil():
|
||||
psutil.Process(os.getpid())
|
||||
print ('psutil OK!')
|
||||
|
||||
def test_podofo():
|
||||
from calibre.utils.podofo import test_podofo as dotest
|
||||
dotest()
|
||||
|
||||
def test():
|
||||
test_plugins()
|
||||
test_lxml()
|
||||
@ -191,6 +195,7 @@ def test():
|
||||
test_tokenizer()
|
||||
test_netifaces()
|
||||
test_psutil()
|
||||
test_podofo()
|
||||
if iswindows:
|
||||
test_winutil()
|
||||
test_wpd()
|
||||
|
@ -145,6 +145,28 @@ def test_save_to(src, dest):
|
||||
p.save_to_fileobj(out)
|
||||
print ('Wrote PDF of size:', out.tell())
|
||||
|
||||
def test_podofo():
|
||||
from io import BytesIO
|
||||
from calibre.ebooks.metadata.book.base import Metadata
|
||||
from calibre.ebooks.metadata.xmp import metadata_to_xmp_packet
|
||||
raw = b'%PDF-1.1\n%\xc2\xa5\xc2\xb1\xc3\xab\n\n1 0 obj\n << /Type /Catalog\n /Pages 2 0 R\n >>\nendobj\n\n2 0 obj\n << /Type /Pages\n /Kids [3 0 R]\n /Count 1\n /MediaBox [0 0 300 144]\n >>\nendobj\n\n3 0 obj\n << /Type /Page\n /Parent 2 0 R\n /Resources\n << /Font\n << /F1\n << /Type /Font\n /Subtype /Type1\n /BaseFont /Times-Roman\n >>\n >>\n >>\n /Contents 4 0 R\n >>\nendobj\n\n4 0 obj\n << /Length 55 >>\nstream\n BT\n /F1 18 Tf\n 0 0 Td\n (Hello World) Tj\n ET\nendstream\nendobj\n\nxref\n0 5\n0000000000 65535 f \n0000000018 00000 n \n0000000077 00000 n \n0000000178 00000 n \n0000000457 00000 n \ntrailer\n << /Root 1 0 R\n /Size 5\n >>\nstartxref\n565\n%%EOF\n' # noqa
|
||||
mi = Metadata(u'title1', [u'author1'])
|
||||
xmp_packet = metadata_to_xmp_packet(mi)
|
||||
podofo = get_podofo()
|
||||
p = podofo.PDFDoc()
|
||||
p.load(raw)
|
||||
p.title = mi.title
|
||||
p.author = mi.authors[0]
|
||||
p.set_xmp_metadata(xmp_packet)
|
||||
buf = BytesIO()
|
||||
p.save_to_fileobj(buf)
|
||||
raw = buf.getvalue()
|
||||
p = podofo.PDFDoc()
|
||||
p.load(raw)
|
||||
if (p.title, p.author) != (mi.title, mi.authors[0]):
|
||||
raise ValueError('podofo failed to set title and author in Info dict')
|
||||
if not p.get_xmp_metadata():
|
||||
raise ValueError('podofo failed to write XMP packet')
|
||||
|
||||
if __name__ == '__main__':
|
||||
import sys
|
||||
|
Loading…
x
Reference in New Issue
Block a user