From ed42a7c1b6f6e6a87082f7ee8710381322af6126 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 14 Apr 2019 12:20:43 +0530 Subject: [PATCH] py3: Fix legacy_coverage test --- src/calibre/db/legacy.py | 4 +++- src/calibre/db/tests/legacy.py | 12 +++++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/calibre/db/legacy.py b/src/calibre/db/legacy.py index 20eb149cb9..d65ff275fc 100644 --- a/src/calibre/db/legacy.py +++ b/src/calibre/db/legacy.py @@ -70,9 +70,11 @@ class LibraryDatabase(object): def __init__(self, library_path, default_prefs=None, read_only=False, is_second_db=False, - progress_callback=lambda x, y:True, restore_all_prefs=False): + progress_callback=None, restore_all_prefs=False, row_factory=False): self.is_second_db = is_second_db + if progress_callback is None: + progress_callback = lambda x, y:True self.listeners = set() backend = self.backend = create_backend(library_path, default_prefs=default_prefs, diff --git a/src/calibre/db/tests/legacy.py b/src/calibre/db/tests/legacy.py index b7406bbca8..2e31b09bac 100644 --- a/src/calibre/db/tests/legacy.py +++ b/src/calibre/db/tests/legacy.py @@ -37,12 +37,18 @@ class ET(object): return newres +def get_defaults(spec): + num = len(spec.defaults or ()) + if not num: + return {} + return dict(zip(spec.args[-num:], spec.defaults)) + + def compare_argspecs(old, new, attr): # We dont compare the names of the non-keyword arguments as they are often # different and they dont affect the usage of the API. - num = len(old.defaults or ()) - ok = len(old.args) == len(new.args) and old.defaults == new.defaults and (num == 0 or old.args[-num:] == new.args[-num:]) + ok = len(old.args) == len(new.args) and get_defaults(old) == get_defaults(new) if not ok: raise AssertionError('The argspec for %s does not match. %r != %r' % (attr, old, new)) @@ -459,7 +465,7 @@ class LegacyTest(BaseTest): try: argspec = inspect.getargspec(obj) nargspec = inspect.getargspec(nobj) - except TypeError: + except (TypeError, ValueError): pass else: compare_argspecs(argspec, nargspec, attr)