1- import warnings
1+ try :
2+ from contextlib import nullcontext
3+ except ImportError :
4+ from contextlib import ExitStack as nullcontext # Py 3.6.
25import re
36
47import numpy as np
@@ -242,9 +245,8 @@ def test_set_params(self):
242245class _LogitHelper :
243246 @staticmethod
244247 def isclose (x , y ):
245- if x >= 1 or x <= 0 or y >= 1 or y <= 0 :
246- return False
247- return np .isclose (- np .log (1 / x - 1 ), - np .log (1 / y - 1 ))
248+ return (np .isclose (- np .log (1 / x - 1 ), - np .log (1 / y - 1 ))
249+ if 0 < x < 1 and 0 < y < 1 else False )
248250
249251 @staticmethod
250252 def assert_almost_equal (x , y ):
@@ -460,19 +462,15 @@ def test_offset_value(self, left, right, offset):
460462 fig , ax = plt .subplots ()
461463 formatter = ax .get_xaxis ().get_major_formatter ()
462464
463- with warnings .catch_warnings (record = True ) as w :
464- warnings .filterwarnings ('always' , 'Attempting to set identical' ,
465- UserWarning )
465+ with (pytest .warns (UserWarning , match = 'Attempting to set identical' )
466+ if left == right else nullcontext ()):
466467 ax .set_xlim (left , right )
467- assert len (w ) == (1 if left == right else 0 )
468468 ax .get_xaxis ()._update_ticks ()
469469 assert formatter .offset == offset
470470
471- with warnings .catch_warnings (record = True ) as w :
472- warnings .filterwarnings ('always' , 'Attempting to set identical' ,
473- UserWarning )
471+ with (pytest .warns (UserWarning , match = 'Attempting to set identical' )
472+ if left == right else nullcontext ()):
474473 ax .set_xlim (right , left )
475- assert len (w ) == (1 if left == right else 0 )
476474 ax .get_xaxis ()._update_ticks ()
477475 assert formatter .offset == offset
478476
@@ -484,8 +482,7 @@ def test_use_offset(self, use_offset):
484482
485483 @pytest .mark .parametrize (
486484 'sci_type, scilimits, lim, orderOfMag, fewticks' , scilimits_data )
487- def test_scilimits (self , sci_type , scilimits , lim , orderOfMag ,
488- fewticks ):
485+ def test_scilimits (self , sci_type , scilimits , lim , orderOfMag , fewticks ):
489486 tmp_form = mticker .ScalarFormatter ()
490487 tmp_form .set_scientific (sci_type )
491488 tmp_form .set_powerlimits (scilimits )
@@ -542,7 +539,7 @@ def test_blank(self):
542539 assert formatter (10 ** 0.1 ) == ''
543540
544541
545- class TestLogFormatterMathtext () :
542+ class TestLogFormatterMathtext :
546543 fmt = mticker .LogFormatterMathtext ()
547544 test_data = [
548545 (0 , 1 , '$\\ mathdefault{10^{0}}$' ),
0 commit comments