def test_read_typical_main(self): expect = ( {'kind': 'magic', 'value': b'ebakup database v1'}, {'kind': 'setting', 'key': b'edb-blocksize', 'value': b'4096'}, {'kind': 'setting', 'key': b'edb-blocksum', 'value': b'sha256'}, {'kind': 'setting', 'key': b'checksum', 'value': b'sha256'} ) tree = FakeTree() tree._add_file( ('path', 'to', 'db', 'main'), testdata.dbfiledata('main-1')) main = datafile.open_main(tree, ('path', 'to', 'db')) self.assertItemSequence(expect, main) self.assertRaises(StopIteration, next, main) self.assertRaises(StopIteration, next, main) self.assertRaises(StopIteration, next, main) main.close() self.assertCountEqual((), tree._files_modified)
def test_read_main_with_non_default_block_sum(self): expect = ( {'kind': 'magic', 'value': b'ebakup database v1'}, {'kind': 'setting', 'key': b'edb-blocksize', 'value': b'4096'}, {'kind': 'setting', 'key': b'edb-blocksum', 'value': b'md5'}, {'kind': 'setting', 'key': b'checksum', 'value': b'sha256'} ) tree = FakeTree() data = testdata.dbfiledata('main-1')[:4064].replace( b'blocksum:sha256', b'blocksum:md5') + b'\x00' * 19 data += hashlib.md5(data).digest() tree._add_file( ('path', 'to', 'db', 'main'), data) main = datafile.open_main(tree, ('path', 'to', 'db')) self.assertItemSequence(expect, main) self.assertRaises(StopIteration, next, main) main.close() self.assertCountEqual((), tree._files_modified)
def open_main(tree, path): return datafile.open_main(tree, path)