mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Manual fixes for misreports from ruff
This commit is contained in:
parent
d7c31f4a81
commit
a1d21e3632
@ -1,5 +0,0 @@
|
|||||||
#!/usr/bin/env python
|
|
||||||
# vim:fileencoding=utf-8
|
|
||||||
# License: GPL v3 Copyright: %YEAR%, %USER% <%MAIL%>
|
|
||||||
|
|
||||||
%HERE%
|
|
@ -237,11 +237,12 @@ class NumericSearch: # {{{
|
|||||||
dt = datatype
|
dt = datatype
|
||||||
|
|
||||||
if is_many and query in {'true', 'false'}:
|
if is_many and query in {'true', 'false'}:
|
||||||
def valcheck(x):
|
|
||||||
return True
|
|
||||||
if datatype == 'rating':
|
if datatype == 'rating':
|
||||||
def valcheck(x):
|
def valcheck(x):
|
||||||
return (x is not None and x > 0)
|
return (x is not None and x > 0)
|
||||||
|
else:
|
||||||
|
def valcheck(x):
|
||||||
|
return True
|
||||||
found = set()
|
found = set()
|
||||||
for val, book_ids in field_iter():
|
for val, book_ids in field_iter():
|
||||||
if valcheck(val):
|
if valcheck(val):
|
||||||
@ -273,6 +274,7 @@ class NumericSearch: # {{{
|
|||||||
if dt == 'rating':
|
if dt == 'rating':
|
||||||
def cast(x):
|
def cast(x):
|
||||||
return (0 if x is None else int(x))
|
return (0 if x is None else int(x))
|
||||||
|
|
||||||
def adjust(x):
|
def adjust(x):
|
||||||
return (x // 2)
|
return (x // 2)
|
||||||
else:
|
else:
|
||||||
|
@ -57,8 +57,6 @@ def run_funcs(self, db, ndb, funcs):
|
|||||||
if callable(meth):
|
if callable(meth):
|
||||||
meth(*args)
|
meth(*args)
|
||||||
else:
|
else:
|
||||||
def fmt(x):
|
|
||||||
return x
|
|
||||||
if meth[0] in {'!', '@', '#', '+', '$', '-', '%'}:
|
if meth[0] in {'!', '@', '#', '+', '$', '-', '%'}:
|
||||||
if meth[0] != '+':
|
if meth[0] != '+':
|
||||||
fmt = {'!':dict, '@':lambda x:frozenset(x or ()), '#':lambda x:set((x or '').split(',')),
|
fmt = {'!':dict, '@':lambda x:frozenset(x or ()), '#':lambda x:set((x or '').split(',')),
|
||||||
@ -68,6 +66,9 @@ def run_funcs(self, db, ndb, funcs):
|
|||||||
fmt = args[-1]
|
fmt = args[-1]
|
||||||
args = args[:-1]
|
args = args[:-1]
|
||||||
meth = meth[1:]
|
meth = meth[1:]
|
||||||
|
else:
|
||||||
|
def fmt(x):
|
||||||
|
return x
|
||||||
res1, res2 = fmt(getattr(db, meth)(*args)), fmt(getattr(ndb, meth)(*args))
|
res1, res2 = fmt(getattr(db, meth)(*args)), fmt(getattr(ndb, meth)(*args))
|
||||||
self.assertEqual(res1, res2, f'The method: {meth}() returned different results for argument {args}')
|
self.assertEqual(res1, res2, f'The method: {meth}() returned different results for argument {args}')
|
||||||
# }}}
|
# }}}
|
||||||
@ -257,14 +258,15 @@ class LegacyTest(BaseTest):
|
|||||||
'books_in_series_of':[(0,), (1,), (2,)],
|
'books_in_series_of':[(0,), (1,), (2,)],
|
||||||
'books_with_same_title':[(Metadata(db.title(0)),), (Metadata(db.title(1)),), (Metadata('1234'),)],
|
'books_with_same_title':[(Metadata(db.title(0)),), (Metadata(db.title(1)),), (Metadata('1234'),)],
|
||||||
}):
|
}):
|
||||||
def fmt(x):
|
|
||||||
return x
|
|
||||||
if meth[0] in {'!', '@'}:
|
if meth[0] in {'!', '@'}:
|
||||||
fmt = {'!':dict, '@':frozenset}[meth[0]]
|
fmt = {'!':dict, '@':frozenset}[meth[0]]
|
||||||
meth = meth[1:]
|
meth = meth[1:]
|
||||||
elif meth == 'get_authors_with_ids':
|
elif meth == 'get_authors_with_ids':
|
||||||
def fmt(val):
|
def fmt(val):
|
||||||
return {x[0]: tuple(x[1:]) for x in val}
|
return {x[0]: tuple(x[1:]) for x in val}
|
||||||
|
else:
|
||||||
|
def fmt(x):
|
||||||
|
return x
|
||||||
for a in args:
|
for a in args:
|
||||||
self.assertEqual(fmt(getattr(db, meth)(*a)), fmt(getattr(ndb, meth)(*a)),
|
self.assertEqual(fmt(getattr(db, meth)(*a)), fmt(getattr(ndb, meth)(*a)),
|
||||||
f'The method: {meth}() returned different results for argument {a}')
|
f'The method: {meth}() returned different results for argument {a}')
|
||||||
|
@ -612,11 +612,12 @@ class ReadingTest(BaseTest):
|
|||||||
self.assertSetEqual(set(mi.custom_field_keys()), set(pmi.custom_field_keys()))
|
self.assertSetEqual(set(mi.custom_field_keys()), set(pmi.custom_field_keys()))
|
||||||
|
|
||||||
for field in STANDARD_METADATA_FIELDS | {'#series_index'}:
|
for field in STANDARD_METADATA_FIELDS | {'#series_index'}:
|
||||||
def f(x):
|
|
||||||
return x
|
|
||||||
if field == 'formats':
|
if field == 'formats':
|
||||||
def f(x):
|
def f(x):
|
||||||
return (x if x is None else tuple(x))
|
return (x if x is None else tuple(x))
|
||||||
|
else:
|
||||||
|
def f(x):
|
||||||
|
return x
|
||||||
self.assertEqual(f(getattr(mi, field)), f(getattr(pmi, field)),
|
self.assertEqual(f(getattr(mi, field)), f(getattr(pmi, field)),
|
||||||
f'Standard field: {field} not the same for book {book_id}')
|
f'Standard field: {field} not the same for book {book_id}')
|
||||||
self.assertEqual(mi.format_field(field), pmi.format_field(field),
|
self.assertEqual(mi.format_field(field), pmi.format_field(field),
|
||||||
|
@ -817,7 +817,7 @@ class HTMLConverter:
|
|||||||
valign = css['vertical-align']
|
valign = css['vertical-align']
|
||||||
if valign in ('sup', 'super', 'sub'):
|
if valign in ('sup', 'super', 'sub'):
|
||||||
fp['fontsize'] = int(fp['fontsize']) * 5 // 3
|
fp['fontsize'] = int(fp['fontsize']) * 5 // 3
|
||||||
valigner = Sub if valign == 'sub' else Sup
|
valigner = Sub if valign == 'sub' else Sup # noqa
|
||||||
normal_font_size = int(fp['fontsize'])
|
normal_font_size = int(fp['fontsize'])
|
||||||
|
|
||||||
if variant == 'small-caps':
|
if variant == 'small-caps':
|
||||||
|
@ -181,8 +181,6 @@ class ResultsModel(QAbstractTableModel): # {{{
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
def sort(self, col, order=Qt.SortOrder.AscendingOrder):
|
def sort(self, col, order=Qt.SortOrder.AscendingOrder):
|
||||||
def key(x):
|
|
||||||
return x
|
|
||||||
if col == 0:
|
if col == 0:
|
||||||
key = attrgetter('gui_rank')
|
key = attrgetter('gui_rank')
|
||||||
elif col == 1:
|
elif col == 1:
|
||||||
@ -199,6 +197,9 @@ class ResultsModel(QAbstractTableModel): # {{{
|
|||||||
elif key == 4:
|
elif key == 4:
|
||||||
def key(x):
|
def key(x):
|
||||||
return bool(x.comments)
|
return bool(x.comments)
|
||||||
|
else:
|
||||||
|
def key(x):
|
||||||
|
return x
|
||||||
|
|
||||||
self.beginResetModel()
|
self.beginResetModel()
|
||||||
self.results.sort(key=key, reverse=order==Qt.SortOrder.AscendingOrder)
|
self.results.sort(key=key, reverse=order==Qt.SortOrder.AscendingOrder)
|
||||||
|
@ -1973,6 +1973,7 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns):
|
|||||||
icon_map[category] = icon
|
icon_map[category] = icon
|
||||||
|
|
||||||
datatype = cat['datatype']
|
datatype = cat['datatype']
|
||||||
|
|
||||||
def avgr(x):
|
def avgr(x):
|
||||||
return (0.0 if x.rc == 0 else x.rt / x.rc)
|
return (0.0 if x.rc == 0 else x.rt / x.rc)
|
||||||
# Duplicate the build of items below to avoid using a lambda func
|
# Duplicate the build of items below to avoid using a lambda func
|
||||||
@ -1980,7 +1981,7 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns):
|
|||||||
if datatype == 'rating':
|
if datatype == 'rating':
|
||||||
def formatter(x):
|
def formatter(x):
|
||||||
return ('★' * int(x // 2))
|
return ('★' * int(x // 2))
|
||||||
def avgr(x):
|
def avgr(x): # noqa
|
||||||
return x.n
|
return x.n
|
||||||
# eliminate the zero ratings line as well as count == 0
|
# eliminate the zero ratings line as well as count == 0
|
||||||
items = [v for v in tcategories[category].values() if v.c > 0 and v.n != 0]
|
items = [v for v in tcategories[category].values() if v.c > 0 and v.n != 0]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user