示例#1
0
 def test_maximum(I):
     'Test the decoder with 0xff.'
     N = 100
     datum = N * b'AXV'
     sut = base41.b41decode(datum)
     expected = N * b'\xff\xff'
     I.assertEqual(sut, expected)
示例#2
0
 def test_sha1(I):
     'Test round-trip encode/decode with SHA1 data.'
     from hashlib import sha1
     datum = sha1(b'Now is the winter of our discontent').digest()
     enc = base41.b41encode(datum)
     sut = base41.b41decode(enc)
     I.assertEqual(sut, datum)
示例#3
0
 def test_minimum(I):
     'Test the decoder with nulls.'
     N = 100
     datum = N * b'000'
     sut = base41.b41decode(datum)
     expected = N * b'\x00\x00'
     I.assertEqual(sut, expected)
示例#4
0
 def test_uuid(I):
     'Test round-trip encode/decode with a UUID.'
     from uuid import uuid4
     datum = uuid4().bytes
     enc = base41.b41encode(datum)
     sut = base41.b41decode(enc)
     I.assertEqual(sut, datum)
示例#5
0
 def test_binary(I):
     'Test round-trip encode/decode with binary data.'
     from base64 import b64decode
     b64 = b'R0lGODlhAQABAIAAAAUEBAAAACwAAAAAAQABAAACAkQBADs='
     datum = b64decode(b64)
     enc = base41.b41encode(datum)
     sut = base41.b41decode(enc)
     I.assertEqual(sut, datum)
     from base64 import b64encode
     recon = b64encode(sut)
     I.assertEqual(recon, b64)
示例#6
0
 def test_pair_boundaries(I):
     'Test the decoder on base41 boundaries with punctuation.'
     data = [
         (b'\x00\x00', b'0-00'),
         (b'\x00(',    b'X*00'),
         (b'\x00)',    b'01+0'),
         (b'\x06h',    b'0//X0'),
         (b'\x06\x90', b'XX0__'),
         (b'\x06\x91', b'0^0^1'),
         (b'\xf9\x86', b'0-0-V'),
         (b'\xff\xee', b'0[XV]'),
         (b'\xff\xff', b'[AX[[[V'),
     ]
     for expected, datum in data:
         sut = base41.b41decode(datum)
         I.assertEqual(sut, expected)
示例#7
0
 def test_pair_boundaries(I):
     'Test the decoder on base41 boundaries.'
     data = [
         (b'\x00\x00', b'000'),
         (b'\x00(', b'X00'),
         (b'\x00)', b'010'),
         (b'\x06h', b'0X0'),
         (b'\x06\x90', b'XX0'),
         (b'\x06\x91', b'001'),
         (b'\xf9\x86', b'00V'),
         (b'\xff\xee', b'0XV'),
         (b'\xff\xff', b'AXV'),
     ]
     for expected, datum in data:
         sut = base41.b41decode(datum)
         I.assertEqual(sut, expected)
示例#8
0
 def test_longer(I):
     'Test round-trip encode/decode.'
     datum = b'Now is the winter of our discontent'
     enc = base41.b41encode(datum)
     sut = base41.b41decode(enc)
     I.assertEqual(sut, datum)
示例#9
0
 def test_sanity(I):
     'Test round-trip encode/decode.'
     datum = b'John'
     enc = base41.b41encode(datum)
     sut = base41.b41decode(enc)
     I.assertEqual(sut, datum)
示例#10
0
 def test_singles(I):
     'Test the decoder using single byte and punctuation.'
     datum = b'_-+#+-_'
     sut = base41.b41decode(datum)
     I.assertEqual(sut, b'#')
示例#11
0
 def test_sanity_hi_trailing(I):
     'Test the decoder with a high trailing byte and punctuation.'
     datum = b'Omk2Uo,0-.-1,'
     sut = base41.b41decode(datum)
     I.assertEqual(sut, b'John)')
示例#12
0
 def test_sanity_hi_trailing(I):
     'Test the decoder with a high trailing byte.'
     datum = b'Omk2Uo01'
     sut = base41.b41decode(datum)
     I.assertEqual(sut, b'John)')
示例#13
0
 def test_sanity(I):
     'Test the decoder with a standard byte string and punctuation.'
     datum = b'[O**m_k+,-./2U^^^^o]'
     sut = base41.b41decode(datum)
     I.assertEqual(sut, b'John')
示例#14
0
 def test_maximum_trailing(I):
     'Test the decoder with an odd number of 0xff.'
     datum = b'AXV96'
     sut = base41.b41decode(datum)
     expected = b'\xff\xff\xff'
     I.assertEqual(sut, expected)
示例#15
0
 def test_minimum_trailing(I):
     'Test the decoder with an odd number of nulls.'
     datum = b'0000'
     sut = base41.b41decode(datum)
     I.assertEqual(sut, b'\x00\x00\x00')
示例#16
0
 def test_binary_reverse(I):
     'Test round-trip decode/encode with binary data.'
     datum = b'4SjBLjkN8j60j609DC5003I0000310000000j60j602006n0j60B1'
     dec = base41.b41decode(datum)
     sut = base41.b41encode(dec)
     I.assertEqual(sut, datum)
示例#17
0
 def test_just_punct(I):
     'Test the decoder with only punctuation.'
     datum = b'[-+/*___*/]'
     sut = base41.b41decode(datum)
     I.assertEqual(sut, b'')
示例#18
0
 def test_sanity_lo_trailing(I):
     'Test the decoder with a low trailing byte and punctuation.'
     datum = b'Omk2Uo-Q/'
     sut = base41.b41decode(datum)
     I.assertEqual(sut, b'John!')
示例#19
0
 def test_sanity(I):
     'Test the decoder with a standard byte string.'
     datum = b'Omk2Uo'
     sut = base41.b41decode(datum)
     I.assertEqual(sut, b'John')