More verbose sources.test

This commit is contained in:
Kovid Goyal 2011-04-17 20:37:31 -06:00
parent a80b5a9f1a
commit 0fe4a0651d

View File

@ -15,14 +15,17 @@ from calibre.customize.ui import metadata_plugins
from calibre import prints, sanitize_file_name2 from calibre import prints, sanitize_file_name2
from calibre.ebooks.metadata import check_isbn from calibre.ebooks.metadata import check_isbn
from calibre.ebooks.metadata.sources.base import (create_log, from calibre.ebooks.metadata.sources.base import (create_log,
get_cached_cover_urls) get_cached_cover_urls, msprefs)
def isbn_test(isbn): def isbn_test(isbn):
isbn_ = check_isbn(isbn) isbn_ = check_isbn(isbn)
def test(mi): def test(mi):
misbn = check_isbn(mi.isbn) misbn = check_isbn(mi.isbn)
return misbn and misbn == isbn_ if misbn and misbn == isbn_:
return True
prints('ISBN test failed. Expected: \'%s\' found \'%s\''%(isbn_, misbn))
return False
return test return test
@ -32,8 +35,11 @@ def title_test(title, exact=False):
def test(mi): def test(mi):
mt = mi.title.lower() mt = mi.title.lower()
return (exact and mt == title) or \ if (exact and mt == title) or \
(not exact and title in mt) (not exact and title in mt):
return True
prints('Title test failed. Expected: \'%s\' found \'%s\''%(title, mt))
return False
return test return test
@ -42,7 +48,22 @@ def authors_test(authors):
def test(mi): def test(mi):
au = set([x.lower() for x in mi.authors]) au = set([x.lower() for x in mi.authors])
return au == authors if msprefs['swap_author_names']:
def revert_to_fn_ln(a):
if ',' not in a:
return a
parts = a.split(',', 1)
t = parts[-1]
parts = parts[:-1]
parts.insert(0, t)
return ' '.join(parts)
au = set([revert_to_fn_ln(x) for x in au])
if au == authors:
return True
prints('Author test failed. Expected: \'%s\' found \'%s\''%(authors, au))
return False
return test return test