mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-08 02:34:06 -04:00
Add build test for image compression utils
This commit is contained in:
parent
a7489de7cb
commit
65c11b0a8c
@ -466,3 +466,6 @@ class ReadOnlyFileBuffer(object):
|
|||||||
def getvalue(self):
|
def getvalue(self):
|
||||||
return self.mv
|
return self.mv
|
||||||
|
|
||||||
|
def close(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
@ -12,8 +12,10 @@ __docformat__ = 'restructuredtext en'
|
|||||||
Test a binary calibre build to ensure that all needed binary images/libraries have loaded.
|
Test a binary calibre build to ensure that all needed binary images/libraries have loaded.
|
||||||
'''
|
'''
|
||||||
|
|
||||||
import cStringIO, os, ctypes
|
import cStringIO, os, ctypes, shutil
|
||||||
|
from calibre import CurrentDir
|
||||||
from calibre.constants import plugins, iswindows, islinux, isosx
|
from calibre.constants import plugins, iswindows, islinux, isosx
|
||||||
|
from calibre.ptempfile import TemporaryDirectory
|
||||||
|
|
||||||
def test_dlls():
|
def test_dlls():
|
||||||
import win32api
|
import win32api
|
||||||
@ -239,10 +241,27 @@ def test_markdown():
|
|||||||
sanitize_html(b'''<script>moo</script>xxx<img src="http://moo.com/x.jpg">''')
|
sanitize_html(b'''<script>moo</script>xxx<img src="http://moo.com/x.jpg">''')
|
||||||
print('Markdown OK!')
|
print('Markdown OK!')
|
||||||
|
|
||||||
|
def test_image_compression():
|
||||||
|
from calibre.utils.img import optimize_png, optimize_jpeg, encode_jpeg
|
||||||
|
with TemporaryDirectory() as tdir, CurrentDir(tdir):
|
||||||
|
shutil.copyfile(I('devices/kindle.jpg'), 'test.jpg')
|
||||||
|
ret = optimize_jpeg('test.jpg')
|
||||||
|
if ret is not None:
|
||||||
|
raise SystemExit(ret)
|
||||||
|
ret = encode_jpeg('test.jpg')
|
||||||
|
if ret is not None:
|
||||||
|
raise SystemExit(ret)
|
||||||
|
shutil.copyfile(I('lt.png'), 'test.png')
|
||||||
|
ret = optimize_png('test.png')
|
||||||
|
if ret is not None:
|
||||||
|
raise SystemExit(ret)
|
||||||
|
print('Image compression OK!')
|
||||||
|
|
||||||
def test():
|
def test():
|
||||||
if iswindows:
|
if iswindows:
|
||||||
test_dlls()
|
test_dlls()
|
||||||
test_plugins()
|
test_plugins()
|
||||||
|
test_image_compression()
|
||||||
test_lzma()
|
test_lzma()
|
||||||
test_dukpy()
|
test_dukpy()
|
||||||
test_spell()
|
test_spell()
|
||||||
|
@ -98,7 +98,7 @@ def run_optimizer(file_path, cmd, as_filter=False, input_data=None):
|
|||||||
inw = Thread(name='CopyInput', target=copy, args=(src, p.stdin))
|
inw = Thread(name='CopyInput', target=copy, args=(src, p.stdin))
|
||||||
inw.daemon = True
|
inw.daemon = True
|
||||||
inw.start()
|
inw.start()
|
||||||
outw = Thread('CopyOutput', target=copy, args=(p.stdout, outf))
|
outw = Thread(name='CopyOutput', target=copy, args=(p.stdout, outf))
|
||||||
outw.daemon = True
|
outw.daemon = True
|
||||||
outw.start()
|
outw.start()
|
||||||
raw = force_unicode(stderr.read())
|
raw = force_unicode(stderr.read())
|
||||||
@ -137,4 +137,4 @@ def encode_jpeg(file_path, quality=80):
|
|||||||
buf.open(QBuffer.WriteOnly)
|
buf.open(QBuffer.WriteOnly)
|
||||||
if not img.save(buf, 'PPM'):
|
if not img.save(buf, 'PPM'):
|
||||||
raise ValueError('Failed to export image to PPM')
|
raise ValueError('Failed to export image to PPM')
|
||||||
return run_optimizer(file_path, cmd, as_filter=True, input_data=ReadOnlyFileBuffer(ba.data))
|
return run_optimizer(file_path, cmd, as_filter=True, input_data=ReadOnlyFileBuffer(ba.data()))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user