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)
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)
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)
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)
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)
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)
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)
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)
def test_sanity(I): 'Test round-trip encode/decode.' datum = b'John' enc = base41.b41encode(datum) sut = base41.b41decode(enc) I.assertEqual(sut, datum)
def test_singles(I): 'Test the decoder using single byte and punctuation.' datum = b'_-+#+-_' sut = base41.b41decode(datum) I.assertEqual(sut, b'#')
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)')
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)')
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')
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)
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')
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)
def test_just_punct(I): 'Test the decoder with only punctuation.' datum = b'[-+/*___*/]' sut = base41.b41decode(datum) I.assertEqual(sut, b'')
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!')
def test_sanity(I): 'Test the decoder with a standard byte string.' datum = b'Omk2Uo' sut = base41.b41decode(datum) I.assertEqual(sut, b'John')