Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b119a0c

Browse files
committed
Trivial style fixes.
In the various test files, there is no point of wrapping checkdep_usetex in catch_warnings because checkdep_usetex uses logging.warning, not warnings.warn.
1 parent 1020055 commit b119a0c

File tree

9 files changed

+35
-50
lines changed

9 files changed

+35
-50
lines changed

lib/matplotlib/tests/test_backend_pdf.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
from pathlib import Path
44
import sys
55
import tempfile
6-
import warnings
76

87
import numpy as np
98
import pytest
@@ -14,11 +13,9 @@
1413
from matplotlib.testing.decorators import image_comparison
1514

1615

17-
with warnings.catch_warnings():
18-
warnings.simplefilter('ignore')
19-
needs_usetex = pytest.mark.skipif(
20-
not checkdep_usetex(True),
21-
reason="This test needs a TeX installation")
16+
needs_usetex = pytest.mark.skipif(
17+
not checkdep_usetex(True),
18+
reason="This test needs a TeX installation")
2219

2320

2421
@image_comparison(['pdf_use14corefonts.pdf'])

lib/matplotlib/tests/test_backend_ps.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
from pathlib import Path
44
import re
55
import tempfile
6-
import warnings
76

87
import pytest
98

@@ -13,14 +12,12 @@
1312
from matplotlib.testing.decorators import image_comparison
1413

1514

16-
with warnings.catch_warnings():
17-
warnings.simplefilter('ignore')
18-
needs_ghostscript = pytest.mark.skipif(
19-
"eps" not in mpl.testing.compare.converter,
20-
reason="This test needs a ghostscript installation")
21-
needs_usetex = pytest.mark.skipif(
22-
not mpl.checkdep_usetex(True),
23-
reason="This test needs a TeX installation")
15+
needs_ghostscript = pytest.mark.skipif(
16+
"eps" not in mpl.testing.compare.converter,
17+
reason="This test needs a ghostscript installation")
18+
needs_usetex = pytest.mark.skipif(
19+
not mpl.checkdep_usetex(True),
20+
reason="This test needs a TeX installation")
2421

2522

2623
# This tests tends to hit a TeX cache lock on AppVeyor.

lib/matplotlib/tests/test_backend_svg.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
from io import BytesIO
33
import re
44
import tempfile
5-
import warnings
65
import xml.parsers.expat
76

87
import pytest
@@ -14,11 +13,9 @@
1413
from matplotlib.testing.decorators import image_comparison
1514

1615

17-
with warnings.catch_warnings():
18-
warnings.simplefilter('ignore')
19-
needs_usetex = pytest.mark.skipif(
20-
not mpl.checkdep_usetex(True),
21-
reason="This test needs a TeX installation")
16+
needs_usetex = pytest.mark.skipif(
17+
not mpl.checkdep_usetex(True),
18+
reason="This test needs a TeX installation")
2219

2320

2421
def test_visibility():

lib/matplotlib/tests/test_cbook.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,7 @@ def test_step_fails(args):
434434

435435

436436
def test_grouper():
437-
class dummy():
437+
class dummy:
438438
pass
439439
a, b, c, d, e = objs = [dummy() for j in range(5)]
440440
g = cbook.Grouper()
@@ -454,7 +454,7 @@ class dummy():
454454

455455

456456
def test_grouper_private():
457-
class dummy():
457+
class dummy:
458458
pass
459459
objs = [dummy() for j in range(5)]
460460
g = cbook.Grouper()
@@ -484,7 +484,7 @@ def test_flatiter():
484484

485485
def test_reshape2d():
486486

487-
class dummy():
487+
class dummy:
488488
pass
489489

490490
xnew = cbook._reshape_2D([], 'x')

lib/matplotlib/tests/test_text.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,9 @@
1212
from matplotlib.testing.decorators import image_comparison
1313

1414

15-
with warnings.catch_warnings():
16-
warnings.simplefilter('ignore')
17-
needs_usetex = pytest.mark.skipif(
18-
not matplotlib.checkdep_usetex(True),
19-
reason="This test needs a TeX installation")
15+
needs_usetex = pytest.mark.skipif(
16+
not matplotlib.checkdep_usetex(True),
17+
reason="This test needs a TeX installation")
2018

2119

2220
@image_comparison(['font_styles'])

lib/matplotlib/tests/test_ticker.py

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
import warnings
1+
try:
2+
from contextlib import nullcontext
3+
except ImportError:
4+
from contextlib import ExitStack as nullcontext # Py 3.6.
25
import re
36

47
import numpy as np
@@ -242,9 +245,8 @@ def test_set_params(self):
242245
class _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}}$'),

lib/matplotlib/tests/test_transforms.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ def transform_path_non_affine(self, path):
228228
return self.real_trans.transform_path(path)
229229

230230

231-
class TestBasicTransform():
231+
class TestBasicTransform:
232232
def setup_method(self):
233233

234234
self.ta1 = mtransforms.Affine2D(shorthand_name='ta1').rotate(np.pi / 2)

lib/matplotlib/tight_layout.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -220,9 +220,8 @@ def get_renderer(fig):
220220

221221
if canvas and hasattr(canvas, "get_renderer"):
222222
renderer = canvas.get_renderer()
223-
else:
224-
# not sure if this can happen
225-
cbook._warn_external("tight_layout : falling back to Agg renderer")
223+
else: # Some noninteractive backends have no renderer until draw time.
224+
cbook._warn_external("tight_layout: falling back to Agg renderer")
226225
from matplotlib.backends.backend_agg import FigureCanvasAgg
227226
canvas = FigureCanvasAgg(fig)
228227
renderer = canvas.get_renderer()

lib/matplotlib/tri/triinterpolate.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -588,7 +588,7 @@ def _compute_tri_eccentricities(tris_pts):
588588

589589
# FEM element used for interpolation and for solving minimisation
590590
# problem (Reduced HCT element)
591-
class _ReducedHCT_Element():
591+
class _ReducedHCT_Element:
592592
"""
593593
Implementation of reduced HCT triangular element with explicit shape
594594
functions.
@@ -1006,7 +1006,7 @@ def get_Kff_and_Ff(self, J, ecc, triangles, Uc):
10061006
# _DOF_estimator_min_E
10071007
# Private classes used to compute the degree of freedom of each triangular
10081008
# element for the TriCubicInterpolator.
1009-
class _DOF_estimator():
1009+
class _DOF_estimator:
10101010
"""
10111011
Abstract base class for classes used to perform estimation of a function
10121012
first derivatives, and deduce the dofs for a CubicTriInterpolator using a

0 commit comments

Comments
 (0)