def test_decode_error_cases(self): expected = b'0123456789' * 10 dec = decoder(len(expected), 60) for _ in range(20): self.assertEqual(None, dec.decode(0, b64decode(SAMPLES_A[0]))) self.assertEqual(expected, dec.decode(2, b64decode(SAMPLES_A[2]))) # this shouldn't explode! The decoder will cache the decoded result. self.assertEqual(expected, dec.decode(1, b64decode(SAMPLES_A[1]))) self.assertEqual(expected, dec.decode(2, b64decode(SAMPLES_A[2])))
def test_roundtrip(self): data = b'' + urandom(21234) enc = encoder(data, 1300) dec = decoder(len(data), 1300) for i in range(30): if i % 4 == 0: # fake data loss continue fountain_bytes = enc.encode(i) res = dec.decode(i, fountain_bytes) if res is not None: break self.assertEqual(res, data) self.assertEqual(22, i)
def test_decode_bigger(self): expected = b'0123456789' * 100 dec = decoder(len(expected), 600) self.assertEqual(None, dec.decode(0, b64decode(SAMPLES_B[0]))) self.assertEqual(expected, dec.decode(2, b64decode(SAMPLES_B[2])))
def _reset(self, total_size): from pywirehair import decoder self.fountain = decoder(total_size, self.chunk_size)