mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Add tests for relevance sorting to test_identify_plugin
This commit is contained in:
parent
bbd493dee7
commit
b18cd40a4e
@ -41,7 +41,7 @@ class Worker(Thread): # {{{
|
||||
try:
|
||||
self.get_details()
|
||||
except:
|
||||
self.log.error('get_details failed for url: %r'%self.url)
|
||||
self.log.exception('get_details failed for url: %r'%self.url)
|
||||
|
||||
def get_details(self):
|
||||
try:
|
||||
@ -168,7 +168,7 @@ class Worker(Thread): # {{{
|
||||
if self.isbn:
|
||||
self.plugin.cache_isbn_to_identifier(self.isbn, self.amazon_id)
|
||||
if self.cover_url:
|
||||
self.cache_identifier_to_cover_url(self.amazon_id,
|
||||
self.plugin.cache_identifier_to_cover_url(self.amazon_id,
|
||||
self.cover_url)
|
||||
|
||||
self.result_queue.put(mi)
|
||||
|
@ -10,7 +10,7 @@ __docformat__ = 'restructuredtext en'
|
||||
import os, tempfile, time
|
||||
from Queue import Queue, Empty
|
||||
from threading import Event
|
||||
|
||||
from functools import partial
|
||||
|
||||
from calibre.customize.ui import metadata_plugins
|
||||
from calibre import prints
|
||||
@ -90,11 +90,17 @@ def test_identify_plugin(name, tests):
|
||||
except Empty:
|
||||
break
|
||||
|
||||
prints('Found', len(results), 'matches:')
|
||||
prints('Found', len(results), 'matches:', end=' ')
|
||||
prints('Smaller relevance means better match')
|
||||
|
||||
for mi in results:
|
||||
results.sort(cmp=partial(plugin.compare_identify_results,
|
||||
title=kwargs.get('title', None), authors=kwargs.get('authors',
|
||||
None), identifiers=kwargs.get('identifiers', {})))
|
||||
|
||||
for i, mi in enumerate(results):
|
||||
prints('*'*30, 'Relevance:', i, '*'*30)
|
||||
prints(mi)
|
||||
prints('\n\n')
|
||||
prints('*'*75, '\n\n')
|
||||
|
||||
possibles = []
|
||||
for mi in results:
|
||||
@ -117,6 +123,9 @@ def test_identify_plugin(name, tests):
|
||||
prints('Failed to find', plugin.test_fields(possibles[0]))
|
||||
raise SystemExit(1)
|
||||
|
||||
if results[0] is not possibles[0]:
|
||||
prints('Most relevant result failed the tests')
|
||||
|
||||
|
||||
prints('Average time per query', sum(times)/len(times))
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user