mirror of
https://github.com/kovidgoyal/calibre.git
synced 2026-03-25 19:08:02 -04:00
Ensure various Cache objects used in tests are properly closed rather than relying on their __del__ method
This commit is contained in:
parent
0435f0a0c0
commit
669e408cc6
@ -30,12 +30,16 @@ class BaseTest(unittest.TestCase):
|
||||
from calibre.utils.recycle_bin import nuke_recycle
|
||||
nuke_recycle()
|
||||
self.paths_to_remove = []
|
||||
self.objects_to_close = []
|
||||
self.library_path = self.mkdtemp()
|
||||
self.create_db(self.library_path)
|
||||
|
||||
def tearDown(self):
|
||||
from calibre.utils.recycle_bin import restore_recyle
|
||||
restore_recyle()
|
||||
for x in self.objects_to_close:
|
||||
x.close()
|
||||
self.objects_to_close = []
|
||||
gc.collect(), gc.collect()
|
||||
for x in self.paths_to_remove:
|
||||
try:
|
||||
@ -71,6 +75,7 @@ class BaseTest(unittest.TestCase):
|
||||
backend = DB(library_path or self.library_path)
|
||||
cache = Cache(backend)
|
||||
cache.init()
|
||||
self.objects_to_close.append(cache)
|
||||
return cache
|
||||
|
||||
def mkdtemp(self):
|
||||
|
||||
@ -58,11 +58,15 @@ class LibraryBaseTest(BaseTest):
|
||||
from calibre.utils.recycle_bin import nuke_recycle
|
||||
nuke_recycle()
|
||||
self.library_path = self.mkdtemp()
|
||||
self.objects_to_close = []
|
||||
self.create_db(self.library_path)
|
||||
|
||||
def tearDown(self):
|
||||
from calibre.utils.recycle_bin import restore_recyle
|
||||
restore_recyle()
|
||||
for x in self.objects_to_close:
|
||||
x.close()
|
||||
self.objects_to_close = []
|
||||
gc.collect(), gc.collect()
|
||||
try:
|
||||
shutil.rmtree(self.library_path)
|
||||
@ -92,7 +96,7 @@ class LibraryBaseTest(BaseTest):
|
||||
db.add_format(1, 'EPUB', src, run_hooks=False)
|
||||
db.add_format(1, 'FMT2', BytesIO(b'book1fmt2'), run_hooks=False)
|
||||
db.add_format(2, 'FMT1', BytesIO(b'book2fmt1'), run_hooks=False)
|
||||
db.backend.conn.close()
|
||||
db.close()
|
||||
return dest
|
||||
|
||||
def create_server(self, *args, **kwargs):
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user