22 with pytest.raises(InvalidCustomCharsetLengthException):
23 b36c =
Base36Coder(
"0123456789ABCDEFGHIJKLMNOPQRSTUVWXY")
26 with pytest.raises(InvalidCustomCharsetLengthException):
27 b36c =
Base36Coder(
"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZZ")
30 with pytest.raises(InvalidCustomCharsetException):
31 b36c =
Base36Coder(
"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYY")
34 b36c =
Base36Coder(
"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ")
35 assert b36c
is not None
38 with pytest.raises(InvalidInputStringException):
39 b36c =
Base36Coder(
"ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789")
40 bresult = b36c.to_standard_charset(
"aa")
42 @pytest.mark.parametrize(
"input,output",
[("ABCD", "0123"),
43 (
"ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789",
44 "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"),
49 b36c =
Base36Coder(
"ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789")
50 bresult = b36c.to_standard_charset(input)
51 assert bresult == output
54 with pytest.raises(InvalidInputStringException):
55 b36c =
Base36Coder(
"ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789")
56 bresult = b36c.to_custom_charset(
"aa")
58 @pytest.mark.parametrize(
"input,output",
[
("0123", "ABCD"),
59 (
"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ",
60 "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"),
65 b36c =
Base36Coder(
"ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789")
66 bresult = b36c.to_custom_charset(input)
67 assert bresult == output
70 with pytest.raises(NumberNotPositiveOrZeroException):
71 b36c =
Base36Coder(
"ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789")
72 bresult = b36c.int_to_b36(-1)
74 @pytest.mark.parametrize(
"input,output",
[
(b"\x00", "0"),
75 (b
"\x00\x00\x00\x00",
"0"),
76 (b
"\x00\x00\x00\x01",
"1"),
77 (b
"\x00\x00\x00\x0a",
"A"),
78 (b
"\x00\x00\x00\x0f",
"F"),
79 (b
"\x00\x00\x00\x10",
"G"),
80 (b
"\x00\x00\x00\x23",
"Z"),
81 (b
"\x00\x00\x00\x24",
"10"),
82 (b
"\x00\x00\x00\xff",
"73"),
83 (b
"\x00\x00\xff\xff",
"1EKF"),
84 (b
"\x00\xff\xff\xff",
"9ZLDR"),
85 (b
"\xff\xff\xff\xff",
"1Z141Z3"),
86 (b
"\x01\x00\x00\x00\x00",
"1Z141Z4"),
87 (b
"\x00\x00\x00\x01\x00\x00\x00\x00",
"1Z141Z4"),
88 (b
"\xff\xff\xff\xff\xff\xff\xff\xff",
"3W5E11264SGSF"),
94 bresult = b36c.bytes_to_b36(input)
95 assert bresult == output
97 @pytest.mark.parametrize(
"input,output",
[
(0, "0"),
107 (4294967295,
"1Z141Z3"),
108 (4294967296,
"1Z141Z4"),
109 (18446744073709551615,
"3W5E11264SGSF"),
115 bresult = b36c.int_to_b36(input)
116 assert bresult == output
119 with pytest.raises(InvalidInputStringException):
121 bresult = b36c.b36_to_int(
"-A")
123 @pytest.mark.parametrize(
"input,output",
[
("0", 0),
133 (
"1Z141Z3", 4294967295),
134 (
"1Z141Z4", 4294967296),
135 (
"3W5E11264SGSF", 18446744073709551615),
141 bresult = b36c.b36_to_int(input)
142 assert bresult == output
145 with pytest.raises(InvalidInputStringException):
147 bresult = b36c.b36_to_int(
"-A")
149 @pytest.mark.parametrize(
"input,output",
[
("0", b"\x00"),
157 (
"1EKF", b
"\xff\xff"),
158 (
"9ZLDR", b
"\xff\xff\xff"),
159 (
"1Z141Z3", b
"\xff\xff\xff\xff"),
160 (
"1Z141Z4", b
"\x01\x00\x00\x00\x00"),
161 (
"3W5E11264SGSF", b
"\xff\xff\xff\xff\xff\xff\xff\xff"),
167 bresult = b36c.b36_to_bytes(input)
168 assert bresult == output
171 with pytest.raises(ValueTooLargeException):
173 bresult = b36c.b36_to_bytes(
'2ZZZZZZZZZZZZZZZZZZZZZZZ')
176 if __name__ ==
"__main__":
178 This class provides methods allowing conversion between integer, hexadecimal integer and base36 strin...
def test_encoding_base36_to_custom_charset_invalid_input(self)
def test_encoding_base36_to_std_charset_valid_input(self, input, output)
def test_encoding_base36_to_bytes_too_large(self)
def test_encoding_base36_init_too_long(self)
def test_encoding_base36_int_to_b36_default_charset_valid_input(self, input, output)
def test_encoding_base36_to_bytes_valid_input(self, input, output)
def test_encoding_base36_to_int_negative(self)
def test_encoding_base36_to_int_valid_input(self, input, output)
def test_encoding_base36_init_ok(self)
def test_encoding_base36_bytes_to_b36_default_charset_valid_input(self, input, output)
def test_encoding_base36_to_custom_charset_valid_input(self, input, output)
def test_encoding_base36_init_length_ok_double_char(self)
def test_encoding_base36_to_bytes_negative(self)
def test_encoding_base36_int_to_base36_negative(self)
def test_encoding_base36_init_too_short(self)
def test_encoding_base36_to_std_charset_invalid_input(self)
This module provides utlilities related to converting to/from base36 encoding.