def test_identify(tests): # {{{ ''' :param tests: List of 2-tuples. Each two tuple is of the form (args, test_funcs). args is a dict of keyword arguments to pass to the identify method. test_funcs are callables that accept a Metadata object and return True iff the object passes the test. ''' from calibre.ebooks.metadata.sources.identify import identify tdir, lf, log, abort = init_test('Full Identify') prints('Log saved to', lf) times = [] for kwargs, test_funcs in tests: log('') log('#' * 80) log('### Running test with:', kwargs) log('#' * 80) prints('Running test with:', kwargs) args = (log, abort) start_time = time.time() results = identify(*args, **kwargs) total_time = time.time() - start_time times.append(total_time) if not results: prints('identify failed to find any results') break prints('Found', len(results), 'matches:', end=' ') prints('Smaller relevance means better match') for i, mi in enumerate(results): prints('*' * 30, 'Relevance:', i, '*' * 30) if mi.rating: mi.rating *= 2 prints(mi) prints('\nCached cover URLs :', [x[0].name for x in get_cached_cover_urls(mi)]) prints('*' * 75, '\n\n') possibles = [] for mi in results: test_failed = False for tfunc in test_funcs: if not tfunc(mi): test_failed = True break if not test_failed: possibles.append(mi) 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]: prints('Most relevant result failed the tests') raise SystemExit(1) log('\n\n') prints('Average time per query', sum(times) / len(times)) prints('Full log is at:', lf)
def test_identify(tests): # {{{ ''' :param tests: List of 2-tuples. Each two tuple is of the form (args, test_funcs). args is a dict of keyword arguments to pass to the identify method. test_funcs are callables that accept a Metadata object and return True iff the object passes the test. ''' from calibre.ebooks.metadata.sources.identify import identify tdir, lf, log, abort = init_test('Full Identify') prints('Log saved to', lf) times = [] for kwargs, test_funcs in tests: log('#'*80) log('### Running test with:', kwargs) log('#'*80) prints('Running test with:', kwargs) args = (log, abort) start_time = time.time() results = identify(*args, **kwargs) total_time = time.time() - start_time times.append(total_time) if not results: prints('identify failed to find any results') break prints('Found', len(results), 'matches:', end=' ') prints('Smaller relevance means better match') for i, mi in enumerate(results): prints('*'*30, 'Relevance:', i, '*'*30) prints(mi) prints('\nCached cover URLs :', [x[0].name for x in get_cached_cover_urls(mi)]) prints('*'*75, '\n\n') possibles = [] for mi in results: test_failed = False for tfunc in test_funcs: if not tfunc(mi): test_failed = True break if not test_failed: possibles.append(mi) if not possibles: prints('ERROR: No results that passed all tests were found') prints('Log saved to', lf) raise SystemExit(1) if results[0] is not possibles[0]: prints('Most relevant result failed the tests') raise SystemExit(1) log('\n\n') prints('Average time per query', sum(times)/len(times)) prints('Full log is at:', lf)