@@ -48,6 +48,47 @@ def test_encode_raw(
4848
4949 self .assertEqual (output_data , expected_output_data )
5050
51+ @data (str , bool , float , bytes )
52+ def test_encode_raw_invalid_inputs (self , data_type ):
53+ """
54+ Any non-integer types (or lists of non-integers) passed to the function
55+ should raise TypeError.
56+ """
57+ with self .assertRaises (TypeError ):
58+ encode_raw (
59+ input_base = data_type (), output_base = data_type (),
60+ input_ratio = data_type (), output_ratio = data_type (),
61+ input_data = data_type ()
62+ )
63+
64+ @data (
65+ (94 , 256 , 10 , 9 , [1 , 2 , 3 , 4 , 5 ]),
66+ (94 , 256 , 10 , 9 , [1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 , 12 , 13 , 14 , 15 ]),
67+ (78 , 256 , 20 , 16 , [70 ]),
68+ (78 , 256 , 20 , 16 , [0 , 5 , 10 , 15 , 20 , 25 , 30 , 35 , 40 , 45 , 50 , 55 , 60 ])
69+ )
70+ @unpack
71+ def test_encode_raw_invalid_input_ratio (
72+ self ,
73+ input_base , output_base ,
74+ input_ratio , output_ratio ,
75+ input_data
76+ ):
77+ """
78+ When encoding from a smaller base to a larger one, it is impossible to
79+ encode input if the number of symbols is not an exact multiple of the
80+ input ratio. This is because such an action normally can be solved with
81+ padding, however padding can only be used successfully on the 'smaller'
82+ side of the transformation, in any other case data corruption occurs.
83+ If this is attempted, then ValueError should be raised.
84+ """
85+ with self .assertRaises (ValueError ):
86+ encode_raw (
87+ input_base = input_base , output_base = output_base ,
88+ input_ratio = input_ratio , output_ratio = output_ratio ,
89+ input_data = input_data
90+ )
91+
5192 @data (
5293 # Base-85 - no padding
5394 (
@@ -81,11 +122,30 @@ def test_decode_raw(
81122
82123 self .assertEqual (output_data , expected_output_data )
83124
125+ @data (str , bool , float , bytes )
126+ def test_decode_raw_invalid_inputs (self , data_type ):
127+ """
128+ Any non-integer types (or lists of non-integers) passed to the function
129+ should raise TypeError.
130+ """
131+ with self .assertRaises (TypeError ):
132+ decode_raw (
133+ input_base = data_type (), output_base = data_type (),
134+ input_ratio = data_type (), output_ratio = data_type (),
135+ input_data = data_type ()
136+ )
137+
84138 @data (
85139 # Base-85 - no padding required
86140 (256 , 85 , 4 , 5 , [99 , 97 , 98 , 98 , 97 , 103 , 101 , 115 ]),
87141 # Base-85 - padding is required
88- (256 , 85 , 4 , 5 , [43 , 42 , 41 , 40 , 39 ])
142+ (256 , 85 , 4 , 5 , [43 , 42 , 41 , 40 , 39 ]),
143+ # Base-94 to Base-256 --the 'wrong' way round, but it is valid as long
144+ # as the input data is a multiple of the input_ratio size.
145+ # Otherwise, padding-related errors occur (because padding happens on
146+ # the 'smaller' side of the transformation only).
147+ (94 , 256 , 10 , 9 , [0 , 10 , 20 , 30 , 40 , 50 , 60 , 70 , 80 , 90 ]),
148+ (94 , 256 , 10 , 9 , [93 , 88 , 77 , 66 , 55 , 44 , 33 , 22 , 11 , 0 ])
89149 )
90150 @unpack
91151 def test_encode_decode_raw (
0 commit comments