|
|
|
@ -16,7 +16,8 @@
|
|
|
|
|
# |
|
|
|
|
# You should have received a copy of the GNU Lesser General Public License |
|
|
|
|
# along with pygal. If not, see <http://www.gnu.org/licenses/>. |
|
|
|
|
from pygal.util import round_to_int, round_to_float, _swap_curly, template |
|
|
|
|
from pygal.util import ( |
|
|
|
|
round_to_int, round_to_float, _swap_curly, template, humanize) |
|
|
|
|
from pytest import raises |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -73,3 +74,30 @@ def test_format():
|
|
|
|
|
obj.c = '3' |
|
|
|
|
assert template('foo {{ o.a }} {{o.b}}-{{o.c}}', |
|
|
|
|
o=obj) == 'foo 1 True-3' |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_humanize(): |
|
|
|
|
assert humanize(1) == '1' |
|
|
|
|
assert humanize(10) == '10' |
|
|
|
|
assert humanize(12.5) == '12.5' |
|
|
|
|
assert humanize(1000) == '1k' |
|
|
|
|
assert humanize(5000) == '5k' |
|
|
|
|
assert humanize(100000) == '100k' |
|
|
|
|
assert humanize(1253) == '1.253k' |
|
|
|
|
assert humanize(1250) == '1.25k' |
|
|
|
|
|
|
|
|
|
assert humanize(0.1) == '100m' |
|
|
|
|
assert humanize(0.01) == '10m' |
|
|
|
|
assert humanize(0.001) == '1m' |
|
|
|
|
assert humanize(0.002) == '2m' |
|
|
|
|
assert humanize(0.0025) == '2.5m' |
|
|
|
|
assert humanize(0.0001) == u'100µ' |
|
|
|
|
assert humanize(0.000123) == u'123µ' |
|
|
|
|
assert humanize(0.00001) == u'10µ' |
|
|
|
|
assert humanize(0.000001) == u'1µ' |
|
|
|
|
assert humanize(0.0000001) == u'100n' |
|
|
|
|
assert humanize(0.0000000001) == u'100p' |
|
|
|
|
|
|
|
|
|
assert humanize(0) == '0' |
|
|
|
|
assert humanize(-1337) == '-1.337k' |
|
|
|
|
assert humanize(-.000000042) == '-42n' |
|
|
|
|