From 94dbef4f80d233ca08d7a6cacc09104d7834d721 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 31 Jul 2022 09:20:41 +0530 Subject: [PATCH] Output to stderr when running sources test --- src/calibre/ebooks/metadata/sources/test.py | 34 ++++++++------------- 1 file changed, 13 insertions(+), 21 deletions(-) diff --git a/src/calibre/ebooks/metadata/sources/test.py b/src/calibre/ebooks/metadata/sources/test.py index 427ee4e21e..307ad6f065 100644 --- a/src/calibre/ebooks/metadata/sources/test.py +++ b/src/calibre/ebooks/metadata/sources/test.py @@ -6,15 +6,19 @@ __license__ = 'GPL v3' __copyright__ = '2011, Kovid Goyal ' __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) # }}}