@@ -692,33 +692,48 @@ def test_basic(self, format, input, expected):
692
692
693
693
694
694
class TestEngFormatter (object ):
695
- # (input, expected) where ''expected'' corresponds to the outputs
696
- # respectively returned when (places=None, places=0, places=2)
695
+ # (unicode_minus, input, expected) where ''expected'' corresponds to the
696
+ # outputs respectively returned when (places=None, places=0, places=2)
697
+ # unicode_minus is a boolean value for the rcParam['axes.unicode_minus']
697
698
raw_format_data = [
698
- (- 1234.56789 , ('-1.23457 k' , '-1 k' , '-1.23 k' )),
699
- (- 1.23456789 , ('-1.23457' , '-1' , '-1.23' )),
700
- (- 0.123456789 , ('-123.457 m' , '-123 m' , '-123.46 m' )),
701
- (- 0.00123456789 , ('-1.23457 m' , '-1 m' , '-1.23 m' )),
702
- (- 0.0 , ('0' , '0' , '0.00' )),
703
- (- 0 , ('0' , '0' , '0.00' )),
704
- (0 , ('0' , '0' , '0.00' )),
705
- (1.23456789e-6 , ('1.23457 µ' , '1 µ' , '1.23 µ' )),
706
- (0.123456789 , ('123.457 m' , '123 m' , '123.46 m' )),
707
- (0.1 , ('100 m' , '100 m' , '100.00 m' )),
708
- (1 , ('1' , '1' , '1.00' )),
709
- (1.23456789 , ('1.23457' , '1' , '1.23' )),
710
- (999.9 , ('999.9' , '1 k' , '999.90' )), # places=0: corner-case rounding
711
- (999.9999 , ('1 k' , '1 k' , '1.00 k' )), # corner-case rounding for all
712
- (- 999.9999 , ('-1 k' , '-1 k' , '-1.00 k' )), # negative corner-case
713
- (1000 , ('1 k' , '1 k' , '1.00 k' )),
714
- (1001 , ('1.001 k' , '1 k' , '1.00 k' )),
715
- (100001 , ('100.001 k' , '100 k' , '100.00 k' )),
716
- (987654.321 , ('987.654 k' , '988 k' , '987.65 k' )),
717
- (1.23e27 , ('1230 Y' , '1230 Y' , '1230.00 Y' )) # OoR value (> 1000 Y)
699
+ (False , - 1234.56789 , ('-1.23457 k' , '-1 k' , '-1.23 k' )),
700
+ (True , - 1234.56789 , ('\N{MINUS SIGN} 1.23457 k' , '\N{MINUS SIGN} 1 k' ,
701
+ '\N{MINUS SIGN} 1.23 k' )),
702
+ (False , - 1.23456789 , ('-1.23457' , '-1' , '-1.23' )),
703
+ (True , - 1.23456789 , ('\N{MINUS SIGN} 1.23457' , '\N{MINUS SIGN} 1' ,
704
+ '\N{MINUS SIGN} 1.23' )),
705
+ (False , - 0.123456789 , ('-123.457 m' , '-123 m' , '-123.46 m' )),
706
+ (True , - 0.123456789 , ('\N{MINUS SIGN} 123.457 m' , '\N{MINUS SIGN} 123 m' ,
707
+ '\N{MINUS SIGN} 123.46 m' )),
708
+ (False , - 0.00123456789 , ('-1.23457 m' , '-1 m' , '-1.23 m' )),
709
+ (True , - 0.00123456789 , ('\N{MINUS SIGN} 1.23457 m' , '\N{MINUS SIGN} 1 m' ,
710
+ '\N{MINUS SIGN} 1.23 m' )),
711
+ (True , - 0.0 , ('0' , '0' , '0.00' )),
712
+ (True , - 0 , ('0' , '0' , '0.00' )),
713
+ (True , 0 , ('0' , '0' , '0.00' )),
714
+ (True , 1.23456789e-6 , ('1.23457 µ' , '1 µ' , '1.23 µ' )),
715
+ (True , 0.123456789 , ('123.457 m' , '123 m' , '123.46 m' )),
716
+ (True , 0.1 , ('100 m' , '100 m' , '100.00 m' )),
717
+ (True , 1 , ('1' , '1' , '1.00' )),
718
+ (True , 1.23456789 , ('1.23457' , '1' , '1.23' )),
719
+ # places=0: corner-case rounding
720
+ (True , 999.9 , ('999.9' , '1 k' , '999.90' )),
721
+ # corner-case rounding for all
722
+ (True , 999.9999 , ('1 k' , '1 k' , '1.00 k' )),
723
+ # negative corner-case
724
+ (False , - 999.9999 , ('-1 k' , '-1 k' , '-1.00 k' )),
725
+ (True , - 999.9999 , ('\N{MINUS SIGN} 1 k' , '\N{MINUS SIGN} 1 k' ,
726
+ '\N{MINUS SIGN} 1.00 k' )),
727
+ (True , 1000 , ('1 k' , '1 k' , '1.00 k' )),
728
+ (True , 1001 , ('1.001 k' , '1 k' , '1.00 k' )),
729
+ (True , 100001 , ('100.001 k' , '100 k' , '100.00 k' )),
730
+ (True , 987654.321 , ('987.654 k' , '988 k' , '987.65 k' )),
731
+ # OoR value (> 1000 Y)
732
+ (True , 1.23e27 , ('1230 Y' , '1230 Y' , '1230.00 Y' ))
718
733
]
719
734
720
- @pytest .mark .parametrize ('input, expected' , raw_format_data )
721
- def test_params (self , input , expected ):
735
+ @pytest .mark .parametrize ('unicode_minus, input, expected' , raw_format_data )
736
+ def test_params (self , unicode_minus , input , expected ):
722
737
"""
723
738
Test the formatting of EngFormatter for various values of the 'places'
724
739
argument, in several cases:
@@ -729,6 +744,7 @@ def test_params(self, input, expected):
729
744
Note that cases 2. and 3. are looped over several separator strings.
730
745
"""
731
746
747
+ plt .rcParams ['axes.unicode_minus' ] = unicode_minus
732
748
UNIT = 's' # seconds
733
749
DIGITS = '0123456789' # %timeit showed 10-20% faster search than set
734
750
0 commit comments