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