Example #1
0
 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()
Example #2
0
 def test_checksum_encodings(self):
     for bts, encoding, cs in _get_encoding_set():
         ec = K.Encoder(checksum=True)
         ec.update(bts)
         ret = ec.finalize()
         assert ret[:-1] == encoding
         assert ret[-1] == cs
Example #3
0
 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()
Example #4
0
 def test_any_simple_encode_with_checksum(self, b):
     ec = K.Encoder(checksum=True)
     ec.update(b)
     cs = 0
     for byte in b:
         cs = cs << 8
         cs += byte
     cs = cs % 37
     v = ec.finalize()
     assert v is not None
     assert v[-1] == ec._alphabet.get(cs)
Example #5
0
 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()
Example #6
0
 def test_alphabet(self):
     ec = K.Encoder()
     alphabet = {
         0: '0',
         1: '1',
         2: '2',
         3: '3',
         4: '4',
         5: '5',
         6: '6',
         7: '7',
         8: '8',
         9: '9',
         10: 'A',
         11: 'B',
         12: 'C',
         13: 'D',
         14: 'E',
         15: 'F',
         16: 'G',
         17: 'H',
         18: 'J',
         19: 'K',
         20: 'M',
         21: 'N',
         22: 'P',
         23: 'Q',
         24: 'R',
         25: 'S',
         26: 'T',
         27: 'V',
         28: 'W',
         29: 'X',
         30: 'Y',
         31: 'Z',
         # Extended checksum values
         32: '*',
         33: '~',
         34: '$',
         35: '=',
         36: 'U'
     }
     assert ec._alphabet == alphabet
Example #7
0
 def test_instantiates(self):
     assert isinstance(K.Encoder(), K.Encoder)
Example #8
0
 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()
Example #9
0
 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()
Example #10
0
 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()
Example #11
0
 def test_multiple_final(self):
     ec = K.Encoder()
     ec.update([0])
     ec.finalize()
     with pytest.raises(K.encode.EncoderAlreadyFinalizedException):
         ec.finalize()
Example #12
0
 def test_any_complex_encode(self, bs):
     ec = K.Encoder()
     for b in bs:
         ec.update(b)
     assert ec.finalize() is not None
Example #13
0
 def test_any_simple_encode(self, b):
     ec = K.Encoder()
     ec.update(b)
     assert ec.finalize() is not None
Example #14
0
 def test_simple_encodings(self):
     for bts, encoding, _ in _get_encoding_set():
         ec = K.Encoder()
         ec.update(bts)
         assert ec.finalize() == encoding