This commit is contained in:
Kovid Goyal 2015-12-21 21:32:10 +05:30
parent ac70ab0a0b
commit 83988df64a

View File

@ -12,10 +12,12 @@ __docformat__ = 'restructuredtext en'
Test a binary calibre build to ensure that all needed binary images/libraries have loaded.
'''
import cStringIO, os, ctypes, shutil, sys
from calibre import CurrentDir
import cStringIO, os, ctypes, sys
from calibre.constants import plugins, iswindows, islinux, isosx
from calibre.ptempfile import TemporaryDirectory
def fprint(*args, **kwargs):
print(*args, **kwargs)
sys.stdout.flush()
def test_dlls():
import win32api
@ -27,11 +29,11 @@ def test_dlls():
ctypes.WinDLL(os.path.join(base, x))
except Exception as err:
errors.append('Failed to load DLL %s with error: %s' % (x, err))
print (errors[-1])
fprint(errors[-1])
if errors:
print ('Loading %d dll(s) failed!' % len(errors))
fprint('Loading %d dll(s) failed!' % len(errors))
raise SystemExit(1)
print ('DLLs OK!')
fprint('DLLs OK!')
def test_dbus():
@ -43,28 +45,28 @@ def test_dbus():
if not bus.list_names():
raise ValueError('Failed to list names on the session bus')
del bus
print ('dbus OK!')
fprint('dbus OK!')
def test_regex():
import regex
if regex.findall(r'(?i)(a)(b)', 'ab cd AB 1a1b') != [('a', 'b'), ('A', 'B')]:
raise ValueError('regex module failed on a simple search')
print ('regex OK!')
fprint('regex OK!')
def test_lzma():
from lzma.xz import test_lzma2
test_lzma2()
print ('lzma OK!')
fprint('lzma OK!')
def test_html5lib():
import html5lib.html5parser # noqa
from html5lib import parse # noqa
print ('html5lib OK!')
fprint('html5lib OK!')
def test_spell():
from calibre.spell.dictionary import test_dictionaries
test_dictionaries()
print ('hunspell OK!')
fprint('hunspell OK!')
def test_plugins():
bad = []
@ -74,9 +76,9 @@ def test_plugins():
bad.append((name, err))
if bad:
for name, err in bad:
print ('Failed to load plugin:', name, 'with error:\n', err, '\n')
fprint('Failed to load plugin:', name, 'with error:\n', err, '\n')
raise SystemExit(1)
print ('Loaded all plugins successfully!')
fprint('Loaded all plugins successfully!')
def test_lxml():
from calibre.utils.cleantext import test_clean_xml_chars
@ -85,7 +87,7 @@ def test_lxml():
raw = '<a/>'
root = etree.fromstring(raw)
if etree.tostring(root) == raw:
print ('lxml OK!')
fprint('lxml OK!')
else:
raise RuntimeError('lxml failed')
@ -96,7 +98,7 @@ def test_certgen():
def test_fsevents():
from fsevents import Observer, Stream
del Observer, Stream
print ('macfsevents OK!')
fprint('macfsevents OK!')
def test_winutil():
from calibre.devices.scanner import win_pnp_drives
@ -105,11 +107,11 @@ def test_winutil():
try:
matches = win_pnp_drives.scanner()
except winutil.DriveError:
print ('No removable drives found, skipping win_pnp_drives test!')
fprint('No removable drives found, skipping win_pnp_drives test!')
return
if len(matches) < 1:
raise RuntimeError('win_pnp_drives returned no drives')
print ('win_pnp_drives OK!')
fprint('win_pnp_drives OK!')
def test_sqlite():
import sqlite3
@ -117,13 +119,13 @@ def test_sqlite():
from calibre.library.sqlite import load_c_extensions
if not load_c_extensions(conn, True):
raise RuntimeError('Failed to load sqlite extension')
print ('sqlite OK!')
fprint('sqlite OK!')
def test_apsw():
import apsw
conn = apsw.Connection(':memory:')
conn.close()
print ('apsw OK!')
fprint('apsw OK!')
def test_qt():
from calibre.gui2 import Application
@ -145,13 +147,13 @@ def test_qt():
raise RuntimeError('Qt not compiled with openssl')
del na
del app
print ('Qt OK!')
fprint('Qt OK!')
def test_imaging():
from calibre.ebooks import calibre_cover
data = calibre_cover('test', 'ok')
if len(data) > 1000:
print ('ImageMagick OK!')
fprint('ImageMagick OK!')
else:
raise RuntimeError('ImageMagick choked!')
from PIL import Image
@ -164,39 +166,39 @@ def test_imaging():
i = Image.open(cStringIO.StringIO(data))
if i.size < (20, 20):
raise RuntimeError('PIL choked!')
print ('PIL OK!')
fprint('PIL OK!')
def test_unrar():
from calibre.utils.unrar import test_basic
test_basic()
print ('Unrar OK!')
fprint('Unrar OK!')
def test_ssl():
import ssl
ssl
print ('SSL OK!')
fprint('SSL OK!')
def test_icu():
print ('Testing ICU')
fprint('Testing ICU')
from calibre.utils.icu_test import test_build
test_build()
print ('ICU OK!')
fprint('ICU OK!')
def test_dukpy():
print ('Testing dukpy')
fprint('Testing dukpy')
from duktape import test_build
test_build()
print ('dukpy OK!')
fprint('dukpy OK!')
def test_wpd():
wpd = plugins['wpd'][0]
try:
wpd.init('calibre', 1, 1, 1)
except wpd.NoWPD:
print ('This computer does not have WPD')
fprint('This computer does not have WPD')
else:
wpd.uninit()
print ('WPD OK!')
fprint('WPD OK!')
def test_magick():
from calibre.utils.magick import create_canvas
@ -204,17 +206,17 @@ def test_magick():
from calibre.gui2.tweak_book.editor.canvas import qimage_to_magick, magick_to_qimage
img = magick_to_qimage(i)
i = qimage_to_magick(img)
print ('magick OK!')
fprint('magick OK!')
def test_tokenizer():
print ('Testing tinycss tokenizer')
fprint('Testing tinycss tokenizer')
from tinycss.tokenizer import c_tokenize_flat
if c_tokenize_flat is None:
raise ValueError('tinycss C tokenizer not loaded')
import tinycss.tests.main as m
if getattr(m, '__file__', None) and os.path.exists(m.__file__):
m.run_tests(for_build=True)
print('tinycss tokenizer OK!')
fprint('tinycss tokenizer OK!')
def test_executables():
from calibre.utils.ipc.launch import Worker
@ -232,51 +234,40 @@ def test_executables():
if not os.path.exists(PDFTOHTML):
raise SystemExit('pdftohtml (%s) does not exist' % PDFTOHTML)
print('executables OK!')
fprint('executables OK!')
def test_netifaces():
import netifaces
if len(netifaces.interfaces()) < 1:
raise ValueError('netifaces could find no network interfaces')
print ('netifaces OK!')
fprint('netifaces OK!')
def test_psutil():
import psutil
psutil.Process(os.getpid())
print ('psutil OK!')
fprint('psutil OK!')
def test_podofo():
from calibre.utils.podofo import test_podofo as dotest
dotest()
print ('podofo OK!')
fprint('podofo OK!')
def test_terminal():
import readline
del readline
print ('readline OK!')
fprint('readline OK!')
def test_markdown():
from calibre.ebooks.markdown import Markdown
Markdown(extensions=['extra'])
from calibre.library.comments import sanitize_html
sanitize_html(b'''<script>moo</script>xxx<img src="http://moo.com/x.jpg">''')
print('Markdown OK!')
fprint('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!')
from calibre.utils.img import test
test()
fprint('Image compression OK!')
def test():
if iswindows:
@ -316,4 +307,3 @@ def test():
if __name__ == '__main__':
test()