Commit 2b457640 authored by Kirill Smelkov's avatar Kirill Smelkov

*/tests: Use defer instead of finally

try/finally was used in a couple of places to save/restore default ZBlk
format setting. Move the restore part close to save with the help of
defer.
parent 5c8340d2
...@@ -730,43 +730,40 @@ def test_bigfile_filezodb_fmt_change(): ...@@ -730,43 +730,40 @@ def test_bigfile_filezodb_fmt_change():
# save/restore original ZBlk_fmt_write # save/restore original ZBlk_fmt_write
fmt_write_save = file_zodb.ZBlk_fmt_write fmt_write_save = file_zodb.ZBlk_fmt_write
def _():
file_zodb.ZBlk_fmt_write = fmt_write_save
defer(_)
try: # check all combinations of format pairs via working with blk #0 and
# check all combinations of format pairs via working with blk #0 and # checking internal f structure
# checking internal f structure for src_fmt, src_type in ZBlk_fmt_registry.items():
for src_fmt, src_type in ZBlk_fmt_registry.items(): for dst_fmt, dst_type in ZBlk_fmt_registry.items():
for dst_fmt, dst_type in ZBlk_fmt_registry.items(): if src_fmt == dst_fmt:
if src_fmt == dst_fmt: continue # skip checking e.g. ZBlk0 -> ZBlk0
continue # skip checking e.g. ZBlk0 -> ZBlk0
file_zodb.ZBlk_fmt_write = src_fmt
struct.pack_into('p', vma, 0, b(src_fmt))
transaction.commit()
assert type(f.blktab[0]) is src_type file_zodb.ZBlk_fmt_write = src_fmt
struct.pack_into('p', vma, 0, b(src_fmt))
transaction.commit()
file_zodb.ZBlk_fmt_write = dst_fmt assert type(f.blktab[0]) is src_type
struct.pack_into('p', vma, 0, b(dst_fmt))
transaction.commit()
assert type(f.blktab[0]) is dst_type file_zodb.ZBlk_fmt_write = dst_fmt
struct.pack_into('p', vma, 0, b(dst_fmt))
transaction.commit()
finally: assert type(f.blktab[0]) is dst_type
file_zodb.ZBlk_fmt_write = fmt_write_save
# test that ZData are reused for changed chunks in ZBlk1 format # test that ZData are reused for changed chunks in ZBlk1 format
@func
def test_bigfile_zblk1_zdata_reuse(): def test_bigfile_zblk1_zdata_reuse():
# set ZBlk_fmt_write to ZBlk1 for this test # set ZBlk_fmt_write to ZBlk1 for this test
fmt_write_save = file_zodb.ZBlk_fmt_write fmt_write_save = file_zodb.ZBlk_fmt_write
file_zodb.ZBlk_fmt_write = 'ZBlk1' file_zodb.ZBlk_fmt_write = 'ZBlk1'
try: def _():
_test_bigfile_zblk1_zdata_reuse()
finally:
file_zodb.ZBlk_fmt_write = fmt_write_save file_zodb.ZBlk_fmt_write = fmt_write_save
defer(_)
@func
def _test_bigfile_zblk1_zdata_reuse():
root = dbopen() root = dbopen()
defer(lambda: dbclose(root)) defer(lambda: dbclose(root))
root['zfile6'] = f = ZBigFile(blksize) root['zfile6'] = f = ZBigFile(blksize)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment