Line | |
---|
1 | """ |
---|
2 | Tests for allmydata.util.base32. |
---|
3 | |
---|
4 | Ported to Python 3. |
---|
5 | """ |
---|
6 | |
---|
7 | import base64 |
---|
8 | |
---|
9 | from twisted.trial import unittest |
---|
10 | |
---|
11 | from hypothesis import ( |
---|
12 | strategies as st, |
---|
13 | given, |
---|
14 | ) |
---|
15 | from allmydata.util import base32 |
---|
16 | |
---|
17 | |
---|
18 | class Base32(unittest.TestCase): |
---|
19 | |
---|
20 | @given(input_bytes=st.binary(max_size=100)) |
---|
21 | def test_a2b_b2a_match_Pythons(self, input_bytes): |
---|
22 | encoded = base32.b2a(input_bytes) |
---|
23 | x = base64.b32encode(input_bytes).rstrip(b"=").lower() |
---|
24 | self.failUnlessEqual(encoded, x) |
---|
25 | self.assertIsInstance(encoded, bytes) |
---|
26 | self.assertTrue(base32.could_be_base32_encoded(encoded)) |
---|
27 | decoded = base32.a2b(encoded) |
---|
28 | self.assertEqual(decoded, input_bytes) |
---|
29 | self.assertIsInstance(decoded, bytes) |
---|
30 | |
---|
31 | def test_b2a(self): |
---|
32 | self.failUnlessEqual(base32.b2a(b"\x12\x34"), b"ci2a") |
---|
33 | |
---|
34 | def test_b2a_or_none(self): |
---|
35 | self.failUnlessEqual(base32.b2a_or_none(None), None) |
---|
36 | self.failUnlessEqual(base32.b2a_or_none(b"\x12\x34"), b"ci2a") |
---|
37 | |
---|
38 | def test_a2b(self): |
---|
39 | self.failUnlessEqual(base32.a2b(b"ci2a"), b"\x12\x34") |
---|
40 | self.failUnlessRaises(AssertionError, base32.a2b, b"b0gus") |
---|
41 | self.assertFalse(base32.could_be_base32_encoded(b"b0gus")) |
---|
Note: See
TracBrowser
for help on using the repository browser.