def test_create_rle_size_overflow(self): source = bytes([0] * 0x10000) target = bytes([1] * 0x10000) created_patch = Patch.create(source, target) result = TestPatch.__save_reload_and_apply(created_patch, source) self.assertEqual(target, result)
def __save_reload_and_apply(patch, source): encoded_patch = patch.encode() decoded_patch = None with tempfile.NamedTemporaryFile(delete=False) as f: f.write(encoded_patch) f.close() decoded_patch = Patch.load(f.name) os.unlink(f.name) return decoded_patch.apply(source)
def test_create_eof_edge_case(self): eof_value = int.from_bytes(b'EOF', byteorder='big') source = bytes(eof_value + 10) target = bytearray(bytes(eof_value + 10)) target[eof_value - 1] = 2 target[eof_value] = 1 patch = Patch.create(source, target) result = TestPatch.__save_reload_and_apply(patch, source) self.assertEqual(len(result), eof_value + 10) self.assertEqual(result[eof_value - 1], 2) self.assertEqual(result[eof_value], 1)