From f1ce0eb75c38f0f4fc3f4dea50f77d6666766925 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 4 Jul 2013 13:16:09 +0530 Subject: [PATCH] Fix test failures due to file locking on windows --- src/calibre/db/legacy.py | 4 +++- src/calibre/db/tests/legacy.py | 32 +++++++++++++++++++------------- src/calibre/db/tests/writing.py | 3 +++ 3 files changed, 25 insertions(+), 14 deletions(-) diff --git a/src/calibre/db/legacy.py b/src/calibre/db/legacy.py index 874707fa2e..287d2d47db 100644 --- a/src/calibre/db/legacy.py +++ b/src/calibre/db/legacy.py @@ -64,9 +64,11 @@ class LibraryDatabase(object): self.backend.close() def break_cycles(self): + delattr(self.backend, 'field_metadata') self.data.cache.backend = None self.data.cache = None - self.data = self.backend = self.new_api = self.field_metadata = self.prefs = self.listeners = self.refresh_ondevice = None + for x in ('data', 'backend', 'new_api', 'listeners',): + delattr(self, x) # Library wide properties {{{ @property diff --git a/src/calibre/db/tests/legacy.py b/src/calibre/db/tests/legacy.py index af6b977aef..1fe719e31e 100644 --- a/src/calibre/db/tests/legacy.py +++ b/src/calibre/db/tests/legacy.py @@ -117,18 +117,24 @@ class LegacyTest(BaseTest): '__init__', } - for attr in dir(db): - if attr in SKIP_ATTRS: - continue - if not hasattr(ndb, attr): - raise AssertionError('The attribute %s is missing' % attr) - obj, nobj = getattr(db, attr), getattr(ndb, attr) - if attr not in SKIP_ARGSPEC: - try: - argspec = inspect.getargspec(obj) - except TypeError: - pass - else: - self.assertEqual(argspec, inspect.getargspec(nobj), 'argspec for %s not the same' % attr) + try: + for attr in dir(db): + if attr in SKIP_ATTRS: + continue + if not hasattr(ndb, attr): + raise AssertionError('The attribute %s is missing' % attr) + obj, nobj = getattr(db, attr), getattr(ndb, attr) + if attr not in SKIP_ARGSPEC: + try: + argspec = inspect.getargspec(obj) + except TypeError: + pass + else: + self.assertEqual(argspec, inspect.getargspec(nobj), 'argspec for %s not the same' % attr) + finally: + for db in (ndb, db): + db.close() + db.break_cycles() + # }}} diff --git a/src/calibre/db/tests/writing.py b/src/calibre/db/tests/writing.py index 5d04c11def..597c98a771 100644 --- a/src/calibre/db/tests/writing.py +++ b/src/calibre/db/tests/writing.py @@ -374,6 +374,9 @@ class WritingTest(BaseTest): ae(cache.field_for('cover', book_id), 1) ae(old.cover(book_id, index_is_id=True), img, 'Cover was not set correctly for book %d' % book_id) self.assertTrue(old.has_cover(book_id)) + old.close() + old.break_cycles() + del old # }}} def test_set_metadata(self): # {{{