source: trunk/src/allmydata/test/test_base32.py

Last change on this file was 1cfe843d, checked in by Alexandre Detiste <alexandre.detiste@…>, at 2024-02-22T23:40:25Z

more python2 removal

  • Property mode set to 100644
File size: 1.2 KB
Line 
1"""
2Tests for allmydata.util.base32.
3
4Ported to Python 3.
5"""
6
7import base64
8
9from twisted.trial import unittest
10
11from hypothesis import (
12    strategies as st,
13    given,
14)
15from allmydata.util import base32
16
17
18class 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.