def test_long_decode_encode_decode_equal(self, ts): ec = K.Encoder() dc = K.Decoder() for t in ts: dc.update(t) ec.update(dc.finalize()) assert ''.join(ts) == ec.finalize()
def test_bad_checksum_decodings(self): ec = K.Encoder() for bts, encoding, cs in _get_encoding_set(): for bcs in ec._alphabet.values(): if bcs == cs: continue dc = K.Decoder(checksum=True) dc.update(encoding) dc.update(bcs) with pytest.raises(K.decode.DecoderChecksumException): dc.finalize()
def test_simple_decodings_fuzzed(self): ec = K.Encoder() for bts, encoding, _ in _get_encoding_set(): if len(encoding) == 8: continue for fuzz in range(32): if fuzz & (pow(2, [0, 0, 2, 0, 4, 1, 0, 3][len(encoding) % 8]) - 1) == 0: continue fuzzc = ec._alphabet.get(fuzz) encoding = encoding[:-1] + fuzzc dc = K.Decoder() dc.update(encoding) with pytest.raises(K.decode.DecoderNonZeroCarryException): dc.finalize()
def test_alphabet_strict(self): ec = K.Decoder(strict=True) alphabet = { '0': 0, '1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, '9': 9, 'A': 10, 'B': 11, 'C': 12, 'D': 13, 'E': 14, 'F': 15, 'G': 16, 'H': 17, 'J': 18, 'K': 19, 'M': 20, 'N': 21, 'P': 22, 'Q': 23, 'R': 24, 'S': 25, 'T': 26, 'V': 27, 'W': 28, 'X': 29, 'Y': 30, 'Z': 31, # Extended checksum values '*': 32, '~': 33, '$': 34, '=': 35, 'U': 36 } assert ec._alphabet == alphabet
def test_decode_encode_decode_equal(self, t): ec = K.Encoder() dc = K.Decoder() dc.update(t) ec.update(dc.finalize()) assert t == ec.finalize()
def test_encode_decode_encode_with_checksum_equal(self, b): ec = K.Encoder(checksum=True) dc = K.Decoder(checksum=True) ec.update(b) dc.update(ec.finalize()) assert b == dc.finalize()
def test_encode_decode_encode_equal(self, b): ec = K.Encoder() dc = K.Decoder() ec.update(b) dc.update(ec.finalize()) assert b == dc.finalize()
def test_multiple_final(self): ec = K.Decoder() ec.update('') ec.finalize() with pytest.raises(K.decode.DecoderAlreadyFinalizedException): ec.finalize()
def test_any_simple_decode(self, t): dc = K.Decoder() dc.update(t) assert dc.finalize() is not None
def test_checksum_decodings(self): for bts, encoding, cs in _get_encoding_set(): dc = K.Decoder(checksum=True) dc.update(encoding) dc.update(cs) assert dc.finalize() == bytes(bts)
def test_simple_decodings(self): for bts, encoding, _ in _get_encoding_set(): dc = K.Decoder() dc.update(encoding) assert dc.finalize() == bytes(bts)
def test_alphabet_permissive(self): ec = K.Decoder() alphabet = { '0': 0, 'O': 0, 'o': 0, '1': 1, 'I': 1, 'i': 1, 'L': 1, 'l': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, '9': 9, 'A': 10, 'a': 10, 'B': 11, 'b': 11, 'C': 12, 'c': 12, 'D': 13, 'd': 13, 'E': 14, 'e': 14, 'F': 15, 'f': 15, 'G': 16, 'g': 16, 'H': 17, 'h': 17, 'J': 18, 'j': 18, 'K': 19, 'k': 19, 'M': 20, 'm': 20, 'N': 21, 'n': 21, 'P': 22, 'p': 22, 'Q': 23, 'q': 23, 'R': 24, 'r': 24, 'S': 25, 's': 25, 'T': 26, 't': 26, 'V': 27, 'v': 27, 'W': 28, 'w': 28, 'X': 29, 'x': 29, 'Y': 30, 'y': 30, 'Z': 31, 'z': 31, # Extended checksum values '*': 32, '~': 33, '$': 34, '=': 35, 'U': 36, 'u': 36 } assert ec._alphabet == alphabet
def test_instantiates(self): assert isinstance(K.Decoder(), K.Decoder)