@@ -582,23 +582,32 @@ def test_percentformatter(self, xmax, decimals, symbol,
582
582
583
583
584
584
class TestEngFormatter (object ):
585
- def test_formatting (self ):
585
+ unit_data = ['' , u's' ]
586
+
587
+ input_data = [0.1 , 1 , 999.9 , 1001 ]
588
+
589
+ expected_data = {
590
+ '' : {
591
+ 0.1 : u'100 m' ,
592
+ 1 : u'1' ,
593
+ 999.99 : u'999.9' ,
594
+ 1001 : u'1.001 k' ,
595
+ }
596
+ u's' : {
597
+ 0.1 : u'100 ms' ,
598
+ 1 : u'1 s' ,
599
+ 999.99 : u'999.9 s' ,
600
+ 1001 : u'1.001 ks' ,
601
+ }
602
+ }
603
+
604
+ @pytest .mark .parametrize ('unit' , unit_data )
605
+ @pytest .mark .parametrize ('input' , input_data )
606
+ def test_formatting (self , unit , input ):
586
607
"""
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).
591
-
592
- Should not raise exceptions.
608
+ Test the formatting of EngFormatter with some inputs, against
609
+ instances with and without units. Cases focus on when no SI
610
+ prefix is present, for values in [1, 1000).
593
611
"""
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'
612
+ fmt = mticker .EngFormatter (unit )
613
+ assert fmt (input ) == self .expected_data [unit ][input ]
0 commit comments