Output to stderr when running sources test

This commit is contained in:
Kovid Goyal 2022-07-31 09:20:41 +05:30
parent 3e05244ae9
commit 94dbef4f80
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -6,15 +6,19 @@ __license__ = 'GPL v3'
__copyright__ = '2011, Kovid Goyal <kovid@kovidgoyal.net>'
__docformat__ = 'restructuredtext en'
import os, tempfile, time
import os
import sys
import tempfile
import time
from threading import Event
from calibre.customize.ui import all_metadata_plugins
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.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 polyglot.queue import Queue, Empty
from calibre.utils.logging import ANSIStream, ThreadSafeLog
from polyglot.queue import Empty, Queue
def isbn_test(isbn):
@ -127,10 +131,10 @@ def pubdate_test(year, month, day):
def init_test(tdir_name):
tdir = tempfile.gettempdir()
lf = os.path.join(tdir, tdir_name.replace(' ', '')+'_identify_test.txt')
log = create_log(open(lf, 'w'))
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):
@ -147,8 +151,7 @@ def test_identify(tests): # {{{
'''
from calibre.ebooks.metadata.sources.identify import identify
tdir, lf, log, abort = init_test('Full Identify')
prints('Log saved to', lf)
tdir, abort, log = init_test('Full Identify')
times = []
@ -191,9 +194,7 @@ def test_identify(tests): # {{{
if not possibles:
prints('ERROR: No results that passed all tests were found')
prints('Log saved to', lf)
log.close()
dump_log(lf)
raise SystemExit(1)
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('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('Using extra headers:', plugin.browser.addheaders)
tdir, lf, log, abort = init_test(plugin.name)
prints('Log saved to', lf)
tdir, abort, log = init_test(plugin.name)
times = []
for kwargs, test_funcs in tests:
@ -288,9 +286,6 @@ def test_identify_plugin(name, tests, modify_plugin=lambda plugin:None, # {{{
if not possibles:
prints('ERROR: No results that passed all tests were found')
prints('Log saved to', lf)
log.close()
dump_log(lf)
raise SystemExit(1)
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)
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)
# }}}