def test_initialization(self): bs = BlockStructure(self.f, block_size=16, initialize=True) self.f.seek(0) got = self.f.read() got = bytes_to_ints(got) expected = [Block.MAGIC_VALUE, 16, -1, -1, 0, -1, -1, -1, -1] assert expected == got
def test_fill(self): b = Block(0, 16, -1, -1, 0) b.write_header(self.f) b.fill_data(self.f, b'\xff') self.reopen_file() content = self.f.read() got = bytes_to_ints(content) expected = [Block.MAGIC_VALUE, 16, -1, -1, 0, -1, -1, -1, -1]
def test_add_block(self): bs = BlockStructure(self.f, block_size=16, initialize=True) bs.add_block(self.f, 16) self.f.seek(0) content = self.f.read() got = bytes_to_ints(content) expected = [ Block.MAGIC_VALUE, 16, 36, -1, 0, -1, -1, -1, -1, Block.MAGIC_VALUE, 16, -1, 0, 0, -1, -1, -1, -1 ] assert expected == got
def test_intialize(self): mbs = MultiBlockStructure(self.f, initialize=True, block_size=16) self.f.seek(0) got = bytes_to_ints(self.f.read()) expected = [ Block.MAGIC_VALUE, 16, -1, -1, 0, -1, -1, -1, -1, ] assert expected == got
def test_bytes_to_ints(): assert bytes_to_ints(b'){\x8a\x83\xdc\x03O\x8e') == [695962243, -603762802]
def test_add_blocks(self): mbs = MultiBlockStructure(self.f, initialize=True, block_size=16) bs1 = mbs.add_structure(self.f, 16) bs2 = mbs.add_structure(self.f, 16) bs1.add_block(self.f, 16) bs2.add_block(self.f, 16) bs2.add_block(self.f, 16) self.f.seek(0) got = bytes_to_ints(self.f.read()) expected = [ Block.MAGIC_VALUE, 16, -1, -1, 8, 36, 72, -1, -1, Block.MAGIC_VALUE, 16, 108, -1, 0, -1, -1, -1, -1, Block.MAGIC_VALUE, 16, 144, -1, 0, -1, -1, -1, -1, Block.MAGIC_VALUE, 16, -1, 36, 0, -1, -1, -1, -1, Block.MAGIC_VALUE, 16, 180, 72, 0, -1, -1, -1, -1, Block.MAGIC_VALUE, 16, -1, 144, 0, -1, -1, -1, -1, ] assert expected == got