def test_read_uncompressed(self): self.uncompressed.seek(0) block = AttachmentBlock(address=97, stream=self.uncompressed) self.assertEqual(block.file_name, self.filename) self.assertEqual(block.extract(), self.data) self.assertEqual(block.comment, self.comment)
def test_bytes_uncompressed(self): attachment = AttachmentBlock( file_name=self.filename, data=self.data, embedded=True, compressed=False, ) attachment.comment = self.comment stream = BytesIO() stream.write(b"\0") blocks = [] attachment.to_blocks(1, blocks, {}) for block in blocks: stream.write(bytes(block)) address = attachment.address block = AttachmentBlock(address=address, stream=stream) self.assertEqual(block.comment, self.comment) self.assertEqual(block.file_name, self.filename) self.assertEqual(block.extract(), self.data)
def test_read_wrong_id(self): self.compressed.seek(0) stream = BytesIO(self.compressed.read()) stream.seek(97) stream.write(b"_NOK") with self.assertRaises(MdfException): AttachmentBlock(address=97, stream=stream)