@@ -450,6 +450,26 @@ def test_percentformatter():
450450 yield (_percent_format_helper ,) + case
451451
452452
453+ def test_EngFormatter_formatting ():
454+ """
455+ Create two instances of EngFormatter with default parameters, with and
456+ without a unit string ('s' for seconds). Test the formatting in some cases,
457+ especially the case when no SI prefix is present, for values in [1, 1000).
458+
459+ Should not raise exceptions.
460+ """
461+ unitless = mticker .EngFormatter ()
462+ nose .tools .assert_equal (unitless (0.1 ), u'100 m' )
463+ nose .tools .assert_equal (unitless (1 ), u'1' )
464+ nose .tools .assert_equal (unitless (999.9 ), u'999.9' )
465+ nose .tools .assert_equal (unitless (1001 ), u'1.001 k' )
466+
467+ with_unit = mticker .EngFormatter (unit = u's' )
468+ nose .tools .assert_equal (with_unit (0.1 ), u'100 ms' )
469+ nose .tools .assert_equal (with_unit (1 ), u'1 s' )
470+ nose .tools .assert_equal (with_unit (999.9 ), u'999.9 s' )
471+ nose .tools .assert_equal (with_unit (1001 ), u'1.001 ks' )
472+
453473if __name__ == '__main__' :
454474 import nose
455475 nose .runmodule (argv = ['-s' , '--with-doctest' ], exit = False )
0 commit comments