mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
more immediate resource closures
This commit is contained in:
parent
1d28aa1d6a
commit
2de9e40eee
@ -63,11 +63,15 @@ def run(*args):
|
||||
if len(args) == 1:
|
||||
args = shlex.split(args[0])
|
||||
print(' '.join(args), flush=True)
|
||||
p = subprocess.Popen(args)
|
||||
try:
|
||||
ret = subprocess.Popen(args).wait(timeout=600)
|
||||
ret = p.wait(timeout=600)
|
||||
except subprocess.TimeoutExpired as err:
|
||||
ret = 1
|
||||
print(err, file=sys.stderr, flush=True)
|
||||
print('Timed out running:', ' '.join(args), flush=True, file=sys.stderr)
|
||||
p.kill()
|
||||
|
||||
if ret != 0:
|
||||
raise SystemExit(ret)
|
||||
|
||||
|
@ -13,6 +13,11 @@ from calibre.db.tests.base import BaseTest
|
||||
from calibre.ptempfile import TemporaryDirectory
|
||||
|
||||
|
||||
def read(x, mode='r'):
|
||||
with open(x, mode) as f:
|
||||
return f.read()
|
||||
|
||||
|
||||
class FilesystemTest(BaseTest):
|
||||
|
||||
def get_filesystem_data(self, cache, book_id):
|
||||
@ -82,8 +87,8 @@ class FilesystemTest(BaseTest):
|
||||
def side_data(book_id=1):
|
||||
bookdir = os.path.dirname(cache.format_abspath(book_id, '__COVER_INTERNAL__'))
|
||||
return {
|
||||
'a.side': open(os.path.join(bookdir, 'a.side')).read(),
|
||||
'a.fmt1': open(os.path.join(bookdir, 'subdir', 'a.fmt1')).read(),
|
||||
'a.side': read(os.path.join(bookdir, 'a.side')),
|
||||
'a.fmt1': read(os.path.join(bookdir, 'subdir', 'a.fmt1')),
|
||||
}
|
||||
|
||||
def check_that_filesystem_and_db_entries_match(book_id):
|
||||
@ -183,8 +188,8 @@ class FilesystemTest(BaseTest):
|
||||
wam.delete_originals()
|
||||
self.assertEqual([], os.listdir(tdir1))
|
||||
self.assertEqual({'a', 'b'}, set(os.listdir(tdir2)))
|
||||
self.assertEqual(raw, open(os.path.join(tdir2, 'a'), 'rb').read())
|
||||
self.assertEqual(raw, open(os.path.join(tdir2, 'b'), 'rb').read())
|
||||
self.assertEqual(raw, read(os.path.join(tdir2, 'a'), 'rb'))
|
||||
self.assertEqual(raw, read(os.path.join(tdir2, 'b'), 'rb'))
|
||||
|
||||
def test_library_move(self):
|
||||
' Test moving of library '
|
||||
@ -239,10 +244,6 @@ class FilesystemTest(BaseTest):
|
||||
def test_export_import(self):
|
||||
from calibre.db.cache import import_library
|
||||
from calibre.utils.exim import Exporter, Importer
|
||||
def read(x, mode='r'):
|
||||
with open(x, mode) as f:
|
||||
return f.read()
|
||||
|
||||
cache = self.init_cache()
|
||||
bookdir = os.path.dirname(cache.format_abspath(1, '__COVER_INTERNAL__'))
|
||||
with open(os.path.join(bookdir, 'exf'), 'w') as f:
|
||||
|
@ -59,7 +59,8 @@ class ContainerTests(BaseTest):
|
||||
c2.commit_item(text)
|
||||
for c in (c1, c2):
|
||||
self.assertEqual(1, nlinks_file(c.name_path_map[text]))
|
||||
self.assertNotEqual(c1.open(text).read(), c2.open(text).read())
|
||||
with c1.open(text) as c1f, c2.open(text) as c2f:
|
||||
self.assertNotEqual(c1f.read(), c2f.read())
|
||||
|
||||
name = spine_names[1]
|
||||
with c1.open(name, mode='r+b') as f:
|
||||
@ -67,7 +68,8 @@ class ContainerTests(BaseTest):
|
||||
f.write(b' ')
|
||||
for c in (c1, c2):
|
||||
self.assertEqual(1, nlinks_file(c.name_path_map[name]))
|
||||
self.assertNotEqual(c1.open(name).read(), c2.open(name).read())
|
||||
with c1.open(text) as c1f, c2.open(text) as c2f:
|
||||
self.assertNotEqual(c1f.read(), c2f.read())
|
||||
|
||||
x = base + 'out.' + fmt
|
||||
for c in (c1, c2):
|
||||
|
Loading…
x
Reference in New Issue
Block a user