mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Output to stderr when running sources test
This commit is contained in:
parent
3e05244ae9
commit
94dbef4f80
@ -6,15 +6,19 @@ __license__ = 'GPL v3'
|
|||||||
__copyright__ = '2011, Kovid Goyal <kovid@kovidgoyal.net>'
|
__copyright__ = '2011, Kovid Goyal <kovid@kovidgoyal.net>'
|
||||||
__docformat__ = 'restructuredtext en'
|
__docformat__ = 'restructuredtext en'
|
||||||
|
|
||||||
import os, tempfile, time
|
import os
|
||||||
|
import sys
|
||||||
|
import tempfile
|
||||||
|
import time
|
||||||
from threading import Event
|
from threading import Event
|
||||||
|
|
||||||
from calibre.customize.ui import all_metadata_plugins
|
|
||||||
from calibre import prints, sanitize_file_name
|
from calibre import prints, sanitize_file_name
|
||||||
|
from calibre.customize.ui import all_metadata_plugins
|
||||||
from calibre.ebooks.metadata import check_isbn
|
from calibre.ebooks.metadata import check_isbn
|
||||||
from calibre.ebooks.metadata.sources.base import create_log, get_cached_cover_urls
|
from calibre.ebooks.metadata.sources.base import get_cached_cover_urls
|
||||||
from calibre.ebooks.metadata.sources.prefs import msprefs
|
from calibre.ebooks.metadata.sources.prefs import msprefs
|
||||||
from polyglot.queue import Queue, Empty
|
from calibre.utils.logging import ANSIStream, ThreadSafeLog
|
||||||
|
from polyglot.queue import Empty, Queue
|
||||||
|
|
||||||
|
|
||||||
def isbn_test(isbn):
|
def isbn_test(isbn):
|
||||||
@ -127,10 +131,10 @@ def pubdate_test(year, month, day):
|
|||||||
|
|
||||||
def init_test(tdir_name):
|
def init_test(tdir_name):
|
||||||
tdir = tempfile.gettempdir()
|
tdir = tempfile.gettempdir()
|
||||||
lf = os.path.join(tdir, tdir_name.replace(' ', '')+'_identify_test.txt')
|
|
||||||
log = create_log(open(lf, 'w'))
|
|
||||||
abort = Event()
|
abort = Event()
|
||||||
return tdir, lf, log, abort
|
log = ThreadSafeLog(level=ThreadSafeLog.DEBUG)
|
||||||
|
log.outputs = [ANSIStream(sys.stderr)]
|
||||||
|
return tdir, abort, log
|
||||||
|
|
||||||
|
|
||||||
def dump_log(lf):
|
def dump_log(lf):
|
||||||
@ -147,8 +151,7 @@ def test_identify(tests): # {{{
|
|||||||
'''
|
'''
|
||||||
from calibre.ebooks.metadata.sources.identify import identify
|
from calibre.ebooks.metadata.sources.identify import identify
|
||||||
|
|
||||||
tdir, lf, log, abort = init_test('Full Identify')
|
tdir, abort, log = init_test('Full Identify')
|
||||||
prints('Log saved to', lf)
|
|
||||||
|
|
||||||
times = []
|
times = []
|
||||||
|
|
||||||
@ -191,9 +194,7 @@ def test_identify(tests): # {{{
|
|||||||
|
|
||||||
if not possibles:
|
if not possibles:
|
||||||
prints('ERROR: No results that passed all tests were found')
|
prints('ERROR: No results that passed all tests were found')
|
||||||
prints('Log saved to', lf)
|
|
||||||
log.close()
|
log.close()
|
||||||
dump_log(lf)
|
|
||||||
raise SystemExit(1)
|
raise SystemExit(1)
|
||||||
|
|
||||||
if results[0] is not possibles[0]:
|
if results[0] is not possibles[0]:
|
||||||
@ -204,8 +205,6 @@ def test_identify(tests): # {{{
|
|||||||
|
|
||||||
prints('Average time per query', sum(times)/len(times))
|
prints('Average time per query', sum(times)/len(times))
|
||||||
|
|
||||||
prints('Full log is at:', lf)
|
|
||||||
|
|
||||||
# }}}
|
# }}}
|
||||||
|
|
||||||
|
|
||||||
@ -228,8 +227,7 @@ def test_identify_plugin(name, tests, modify_plugin=lambda plugin:None, # {{{
|
|||||||
prints('Testing the identify function of', plugin.name)
|
prints('Testing the identify function of', plugin.name)
|
||||||
prints('Using extra headers:', plugin.browser.addheaders)
|
prints('Using extra headers:', plugin.browser.addheaders)
|
||||||
|
|
||||||
tdir, lf, log, abort = init_test(plugin.name)
|
tdir, abort, log = init_test(plugin.name)
|
||||||
prints('Log saved to', lf)
|
|
||||||
|
|
||||||
times = []
|
times = []
|
||||||
for kwargs, test_funcs in tests:
|
for kwargs, test_funcs in tests:
|
||||||
@ -288,9 +286,6 @@ def test_identify_plugin(name, tests, modify_plugin=lambda plugin:None, # {{{
|
|||||||
|
|
||||||
if not possibles:
|
if not possibles:
|
||||||
prints('ERROR: No results that passed all tests were found')
|
prints('ERROR: No results that passed all tests were found')
|
||||||
prints('Log saved to', lf)
|
|
||||||
log.close()
|
|
||||||
dump_log(lf)
|
|
||||||
raise SystemExit(1)
|
raise SystemExit(1)
|
||||||
|
|
||||||
good = [x for x in possibles if plugin.test_fields(x) is
|
good = [x for x in possibles if plugin.test_fields(x) is
|
||||||
@ -333,7 +328,4 @@ def test_identify_plugin(name, tests, modify_plugin=lambda plugin:None, # {{{
|
|||||||
raise SystemExit(1)
|
raise SystemExit(1)
|
||||||
|
|
||||||
prints('Average time per query', sum(times)/len(times))
|
prints('Average time per query', sum(times)/len(times))
|
||||||
|
|
||||||
if os.stat(lf).st_size > 10:
|
|
||||||
prints('There were some errors/warnings, see log', lf)
|
|
||||||
# }}}
|
# }}}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user