13 @pytest.mark.parametrize(
"value,decimals,expected",
[
(0, 0, "0"),
17 (123.456, 3,
"123.456"),
18 (1234.56, 3,
"1.235k"),
19 (123456, 3,
"123.456k"),
20 (123456789, 3,
"123.457M"),
21 (999999, 3,
"999.999k"),
22 (12345678901234567890123456789, 0,
"12346Y"),
23 (12345678901234567890123456789000, 0,
"12345679Y"),
27 assert fmt.formatSI(value, decimals) == expected
29 @pytest.mark.parametrize(
"value,expected",
[
(0, "0"),
32 (12345678901234567890123456789,
"12346Y"),
36 assert fmt.formatSI(value) == expected
38 @pytest.mark.parametrize(
"value,decimals,expected",
[
(0, 0, "0"),
42 (-123.456, 3,
"-123.456"),
43 (-1234.56, 3,
"-1.235k"),
44 (-123456, 3,
"-123.456k"),
45 (-123456789, 3,
"-123.457M"),
46 (-999999, 3,
"-999.999k"),
47 (-12345678901234567890123456789, 0,
"-12346Y"),
51 assert fmt.formatSI(value, decimals) == expected
54 @pytest.mark.parametrize(
"value,decimals,expected",
[
(0, 0, "0"),
56 (1024 * 1024, 0,
"1Mi"),
57 (512 * 1024, 3,
"512.000ki"),
59 (256520, 3,
"250.508ki"),
60 (10240002, 3,
"9.766Mi"),
61 (12345678901234567890123456789, 0,
"10212Yi"),
65 assert fmt.formatBinarySI(value, decimals) == expected
67 @pytest.mark.parametrize(
"value,expected",
[
(0, "0"),
71 (12345678901234567890123456789,
"10212Yi"),
75 assert fmt.formatBinarySI(value) == expected
77 @pytest.mark.parametrize(
"value,decimals,expected",
[
(0, 0, "0"),
79 (-1024 * 1024, 0,
"-1Mi"),
80 (-512 * 1024, 3,
"-512.000ki"),
81 (-256520, 0,
"-251ki"),
82 (-256520, 3,
"-250.508ki"),
83 (-10240002, 3,
"-9.766Mi"),
84 (-12345678901234567890123456789, 0,
"-10212Yi"),
88 assert fmt.formatBinarySI(value, decimals) == expected
91 @pytest.mark.parametrize(
"value,decimals,expected",
[
(0, 0, "0"),
94 (0.000100, 0,
"100μ"),
95 (0.000000100, 0,
"100n"),
96 (0.0001231, 1,
"123.1μ"),
97 (0.135100, 0,
"135m"),
101 (9.999e-25, 0,
"0y"),
105 assert fmt.formatSISubValue(value, decimals) == expected
107 @pytest.mark.parametrize(
"value,expected",
[
(0, "0"),
110 (0.000000100,
"100n"),
116 assert fmt.formatSISubValue(value) == expected
118 @pytest.mark.parametrize(
"value,decimals,expected",
[
(0, 0, "0"),
120 (-0.100, 0,
"-100m"),
121 (-0.000100, 0,
"-100μ"),
122 (-0.000000100, 0,
"-100n"),
123 (-0.0001231, 1,
"-123.1μ"),
124 (-0.135100, 0,
"-135m"),
129 assert fmt.formatSISubValue(value, decimals) == expected
132 @pytest.mark.parametrize(
"value,decimals,expected",
[
(0, 0, "BinSubValueError"),
133 (0, 3,
"BinSubValueError"),
134 (0.100, 0,
"BinSubValueError"),
135 (0.000100, 0,
"BinSubValueError"),
136 (0.000000100, 0,
"BinSubValueError"),
137 (0.0001231, 1,
"BinSubValueError"),
138 (0.135100, 0,
"BinSubValueError"),
139 (1e-50, 0,
"BinSubValueError"),
143 assert fmt.formatSIBinarySubValue(value, decimals) == expected
145 @pytest.mark.parametrize(
"value,decimals,expected",
[
(0, 0, "BinSubValueError"),
146 (0, 3,
"BinSubValueError"),
147 (-0.100, 0,
"BinSubValueError"),
148 (-0.000100, 0,
"BinSubValueError"),
149 (-0.000000100, 0,
"BinSubValueError"),
150 (-0.0001231, 1,
"BinSubValueError"),
151 (-0.135100, 0,
"BinSubValueError"),
152 (-1e-50, 0,
"BinSubValueError"),
156 assert fmt.formatSIBinarySubValue(value, decimals) == expected
159 @pytest.mark.parametrize(
"value,decimals,expected",
[
(0, 0, "0"),
163 (123.456, 3,
"123.456"),
164 (1234.56, 3,
"1.235k"),
165 (123456, 3,
"123.456k"),
166 (123456789, 3,
"123.457M"),
167 (999999, 3,
"999.999k"),
168 (12345678901234567890123456789, 0,
"12346Y"),
170 (0.000100, 0,
"100μ"),
171 (0.000000100, 0,
"100n"),
172 (0.0001231, 1,
"123.1μ"),
173 (0.135100, 0,
"135m"),
180 assert fmt.formatSIFullRange(value, decimals) == expected
182 @pytest.mark.parametrize(
"value,decimals,expected",
[
(0, 0, "0"),
185 (-1000000, 0,
"-1M"),
186 (-123.456, 3,
"-123.456"),
187 (-1234.56, 3,
"-1.235k"),
188 (-123456, 3,
"-123.456k"),
189 (-123456789, 3,
"-123.457M"),
190 (-999999, 3,
"-999.999k"),
191 (-12345678901234567890123456789, 0,
"-12346Y"),
193 (0.000100, 0,
"100μ"),
194 (0.000000100, 0,
"100n"),
195 (0.0001231, 1,
"123.1μ"),
196 (0.135100, 0,
"135m"),
199 (-1 + 1e-24, 0,
"-1"),
203 assert fmt.formatSIFullRange(value, decimals) == expected
205 @pytest.mark.parametrize(
"units,seconds,unit,expected",
[
(9.99, 365000 * 86400, "unit", "9.99unit/millennium"),
206 (1.0, 365000 * 86400,
"unit",
"1.00unit/millennium"),
207 (9.99, 36500 * 86400,
"unit",
"9.99unit/century"),
208 (1.0, 36500 * 86400,
"unit",
"1.00unit/century"),
209 (9.99, 365 * 86400,
"unit",
"9.99unit/year"),
210 (1.0, 365 * 86400,
"unit",
"1.00unit/year"),
211 (6.99, 7 * 86400.0,
"unit",
"6.99unit/week"),
212 (1.0, 7 * 86400.0,
"unit",
"1.00unit/week"),
213 (9.99, 86400.0,
"unit",
"9.99unit/day"),
214 (1.0, 86400.0,
"unit",
"1.00unit/day"),
215 (9.99, 3600.0,
"unit",
"9.99unit/hour"),
216 (1.0, 3600.0,
"unit",
"1.00unit/hour"),
217 (1.0, 60.0,
"unit",
"1.00unit/minute"),
218 (1.0, 1.0,
"unit",
"1.00unit/second"),
219 (0.0, 1.0,
"unit",
"0.00unit/millennium"),
220 (1.0, 0.001,
"unit",
"1.00unit/millisecond"),
221 (1.0, 0.000001,
"unit",
"1.00unit/microsecond"),
222 (-1.0, 0.000001,
"unit",
"-1.00unit/microsecond"),
226 assert fmt.formatUnitsPerIntervalDynamic(
227 units, seconds, unit) == expected
229 @pytest.mark.parametrize(
"units,seconds,unit", [(1.0, -0.000001, "unit"), (1.0, 0,
"unit")]
232 self, units, seconds, unit
234 with pytest.raises(InvalidDurationException):
235 fmt.formatUnitsPerIntervalDynamic(units, seconds, unit)
238 if __name__ ==
"__main__":