mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2024-12-20 21:43:09 +00:00
Test improvements.
This commit is contained in:
parent
148d9a77ae
commit
27d8eb47fc
@ -32,7 +32,9 @@ class Base32(unittest.TestCase):
|
|||||||
self.failUnlessEqual(encoded, x)
|
self.failUnlessEqual(encoded, x)
|
||||||
self.assertIsInstance(encoded, bytes)
|
self.assertIsInstance(encoded, bytes)
|
||||||
self.assertTrue(base32.could_be_base32_encoded(encoded))
|
self.assertTrue(base32.could_be_base32_encoded(encoded))
|
||||||
self.assertEqual(base32.a2b(encoded), input_bytes)
|
decoded = base32.a2b(encoded)
|
||||||
|
self.assertEqual(decoded, input_bytes)
|
||||||
|
self.assertIsInstance(decoded, bytes)
|
||||||
|
|
||||||
def test_b2a(self):
|
def test_b2a(self):
|
||||||
self.failUnlessEqual(base32.b2a(b"\x12\x34"), b"ci2a")
|
self.failUnlessEqual(base32.b2a(b"\x12\x34"), b"ci2a")
|
||||||
|
@ -31,17 +31,17 @@ class T(unittest.TestCase):
|
|||||||
def _test_num_octets_that_encode_to_this_many_chars(self, chars, octets):
|
def _test_num_octets_that_encode_to_this_many_chars(self, chars, octets):
|
||||||
assert base62.num_octets_that_encode_to_this_many_chars(chars) == octets, "%s != %s <- %s" % (octets, base62.num_octets_that_encode_to_this_many_chars(chars), chars)
|
assert base62.num_octets_that_encode_to_this_many_chars(chars) == octets, "%s != %s <- %s" % (octets, base62.num_octets_that_encode_to_this_many_chars(chars), chars)
|
||||||
|
|
||||||
def _test_ende(self, bs):
|
def _test_roundtrip(self, bs):
|
||||||
ascii=base62.b2a(bs)
|
ascii=base62.b2a(bs)
|
||||||
bs2=base62.a2b(ascii)
|
bs2=base62.a2b(ascii)
|
||||||
assert bs2 == bs, "bs2: %s:%s, bs: %s:%s, ascii: %s:%s" % (len(bs2), repr(bs2), len(bs), repr(bs), len(ascii), repr(ascii))
|
self.assertEqual(bs2, bs)
|
||||||
self.assertIsInstance(ascii, bytes)
|
self.assertIsInstance(ascii, bytes)
|
||||||
self.assertIsInstance(bs, bytes)
|
self.assertIsInstance(bs, bytes)
|
||||||
self.assertIsInstance(bs2, bytes)
|
self.assertIsInstance(bs2, bytes)
|
||||||
|
|
||||||
@given(input_bytes=st.binary(max_size=100))
|
@given(input_bytes=st.binary(max_size=100))
|
||||||
def test_roundtrip(self, input_bytes):
|
def test_roundtrip(self, input_bytes):
|
||||||
self._test_ende(input_bytes)
|
self._test_roundtrip(input_bytes)
|
||||||
|
|
||||||
def test_num_octets_that_encode_to_this_many_chars(self):
|
def test_num_octets_that_encode_to_this_many_chars(self):
|
||||||
return self._test_num_octets_that_encode_to_this_many_chars(2, 1)
|
return self._test_num_octets_that_encode_to_this_many_chars(2, 1)
|
||||||
@ -50,25 +50,25 @@ class T(unittest.TestCase):
|
|||||||
return self._test_num_octets_that_encode_to_this_many_chars(6, 4)
|
return self._test_num_octets_that_encode_to_this_many_chars(6, 4)
|
||||||
|
|
||||||
def test_ende_0x00(self):
|
def test_ende_0x00(self):
|
||||||
return self._test_ende(b'\x00')
|
return self._test_roundtrip(b'\x00')
|
||||||
|
|
||||||
def test_ende_0x01(self):
|
def test_ende_0x01(self):
|
||||||
return self._test_ende(b'\x01')
|
return self._test_roundtrip(b'\x01')
|
||||||
|
|
||||||
def test_ende_0x0100(self):
|
def test_ende_0x0100(self):
|
||||||
return self._test_ende(b'\x01\x00')
|
return self._test_roundtrip(b'\x01\x00')
|
||||||
|
|
||||||
def test_ende_0x000000(self):
|
def test_ende_0x000000(self):
|
||||||
return self._test_ende(b'\x00\x00\x00')
|
return self._test_roundtrip(b'\x00\x00\x00')
|
||||||
|
|
||||||
def test_ende_0x010000(self):
|
def test_ende_0x010000(self):
|
||||||
return self._test_ende(b'\x01\x00\x00')
|
return self._test_roundtrip(b'\x01\x00\x00')
|
||||||
|
|
||||||
def test_ende_randstr(self):
|
def test_ende_randstr(self):
|
||||||
return self._test_ende(insecurerandstr(2**4))
|
return self._test_roundtrip(insecurerandstr(2**4))
|
||||||
|
|
||||||
def test_ende_longrandstr(self):
|
def test_ende_longrandstr(self):
|
||||||
return self._test_ende(insecurerandstr(random.randrange(0, 2**10)))
|
return self._test_roundtrip(insecurerandstr(random.randrange(0, 2**10)))
|
||||||
|
|
||||||
def test_odd_sizes(self):
|
def test_odd_sizes(self):
|
||||||
for j in range(2**6):
|
for j in range(2**6):
|
||||||
|
Loading…
Reference in New Issue
Block a user