@@ -582,23 +582,27 @@ def test_percentformatter(self, xmax, decimals, symbol,
582
582
583
583
584
584
class TestEngFormatter (object ):
585
- def test_formatting (self ):
586
- """
587
- Create two instances of EngFormatter with default parameters, with and
588
- without a unit string ('s' for seconds). Test the formatting in some
589
- cases, especially the case when no SI prefix is present, for values in
590
- [1, 1000).
585
+ unit_data = ['' , u's' ]
586
+
587
+ input_data = [0.1 , 1 , 999.9 , 1001 ]
588
+
589
+ format_data = [
590
+ ('' , 0.1 , u'100 m' ),
591
+ ('' , 1 , u'1' ),
592
+ ('' , 999.9 , u'999.9' ),
593
+ ('' , 1001 , u'1.001 k' ),
594
+ (u's' , 0.1 , u'100 ms' ),
595
+ (u's' , 1 , u'1 s' ),
596
+ (u's' , 999.9 , u'999.9 s' ),
597
+ (u's' , 1001 , u'1.001 ks' ),
598
+ ]
591
599
592
- Should not raise exceptions.
600
+ @pytest .mark .parametrize ('unit, input, expected' , format_data )
601
+ def test_formatting (self , unit , input , expected ):
602
+ """
603
+ Test the formatting of EngFormatter with some inputs, against
604
+ instances with and without units. Cases focus on when no SI
605
+ prefix is present, for values in [1, 1000).
593
606
"""
594
- unitless = mticker .EngFormatter ()
595
- assert unitless (0.1 ) == u'100 m'
596
- assert unitless (1 ) == u'1'
597
- assert unitless (999.9 ) == u'999.9'
598
- assert unitless (1001 ) == u'1.001 k'
599
-
600
- with_unit = mticker .EngFormatter (unit = u's' )
601
- assert with_unit (0.1 ) == u'100 ms'
602
- assert with_unit (1 ) == u'1 s'
603
- assert with_unit (999.9 ) == u'999.9 s'
604
- assert with_unit (1001 ) == u'1.001 ks'
607
+ fmt = mticker .EngFormatter (unit )
608
+ assert fmt (input ) == expected
0 commit comments