@@ -582,23 +582,23 @@ 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
+ format_data = [
586
+ ('' , 0.1 , u'100 m' ),
587
+ ('' , 1 , u'1' ),
588
+ ('' , 999.9 , u'999.9' ),
589
+ ('' , 1001 , u'1.001 k' ),
590
+ (u's' , 0.1 , u'100 ms' ),
591
+ (u's' , 1 , u'1 s' ),
592
+ (u's' , 999.9 , u'999.9 s' ),
593
+ (u's' , 1001 , u'1.001 ks' ),
594
+ ]
591
595
592
- Should not raise exceptions.
596
+ @pytest .mark .parametrize ('unit, input, expected' , format_data )
597
+ def test_formatting (self , unit , input , expected ):
598
+ """
599
+ Test the formatting of EngFormatter with some inputs, against
600
+ instances with and without units. Cases focus on when no SI
601
+ prefix is present, for values in [1, 1000).
593
602
"""
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'
603
+ fmt = mticker .EngFormatter (unit )
604
+ assert fmt (input ) == expected
0 commit comments