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