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

Skip to content

Trivial style fixes. #15194

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions lib/matplotlib/tests/test_backend_pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from pathlib import Path
import sys
import tempfile
import warnings

import numpy as np
import pytest
Expand All @@ -14,11 +13,9 @@
from matplotlib.testing.decorators import image_comparison


with warnings.catch_warnings():
warnings.simplefilter('ignore')
needs_usetex = pytest.mark.skipif(
not checkdep_usetex(True),
reason="This test needs a TeX installation")
needs_usetex = pytest.mark.skipif(
not checkdep_usetex(True),
reason="This test needs a TeX installation")


@image_comparison(['pdf_use14corefonts.pdf'])
Expand Down
15 changes: 6 additions & 9 deletions lib/matplotlib/tests/test_backend_ps.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from pathlib import Path
import re
import tempfile
import warnings

import pytest

Expand All @@ -13,14 +12,12 @@
from matplotlib.testing.decorators import image_comparison


with warnings.catch_warnings():
warnings.simplefilter('ignore')
needs_ghostscript = pytest.mark.skipif(
"eps" not in mpl.testing.compare.converter,
reason="This test needs a ghostscript installation")
needs_usetex = pytest.mark.skipif(
not mpl.checkdep_usetex(True),
reason="This test needs a TeX installation")
needs_ghostscript = pytest.mark.skipif(
"eps" not in mpl.testing.compare.converter,
reason="This test needs a ghostscript installation")
needs_usetex = pytest.mark.skipif(
not mpl.checkdep_usetex(True),
reason="This test needs a TeX installation")


# This tests tends to hit a TeX cache lock on AppVeyor.
Expand Down
9 changes: 3 additions & 6 deletions lib/matplotlib/tests/test_backend_svg.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from io import BytesIO
import re
import tempfile
import warnings
import xml.parsers.expat

import pytest
Expand All @@ -14,11 +13,9 @@
from matplotlib.testing.decorators import image_comparison


with warnings.catch_warnings():
warnings.simplefilter('ignore')
needs_usetex = pytest.mark.skipif(
not mpl.checkdep_usetex(True),
reason="This test needs a TeX installation")
needs_usetex = pytest.mark.skipif(
not mpl.checkdep_usetex(True),
reason="This test needs a TeX installation")


def test_visibility():
Expand Down
6 changes: 3 additions & 3 deletions lib/matplotlib/tests/test_cbook.py
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ def test_step_fails(args):


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


def test_grouper_private():
class dummy():
class dummy:
pass
objs = [dummy() for j in range(5)]
g = cbook.Grouper()
Expand Down Expand Up @@ -484,7 +484,7 @@ def test_flatiter():

def test_reshape2d():

class dummy():
class dummy:
pass

xnew = cbook._reshape_2D([], 'x')
Expand Down
8 changes: 3 additions & 5 deletions lib/matplotlib/tests/test_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,9 @@
from matplotlib.testing.decorators import image_comparison


with warnings.catch_warnings():
warnings.simplefilter('ignore')
needs_usetex = pytest.mark.skipif(
not matplotlib.checkdep_usetex(True),
reason="This test needs a TeX installation")
needs_usetex = pytest.mark.skipif(
not matplotlib.checkdep_usetex(True),
reason="This test needs a TeX installation")


@image_comparison(['font_styles'])
Expand Down
27 changes: 12 additions & 15 deletions lib/matplotlib/tests/test_ticker.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import warnings
try:
from contextlib import nullcontext
except ImportError:
from contextlib import ExitStack as nullcontext # Py 3.6.
import re

import numpy as np
Expand Down Expand Up @@ -242,9 +245,8 @@ def test_set_params(self):
class _LogitHelper:
@staticmethod
def isclose(x, y):
if x >= 1 or x <= 0 or y >= 1 or y <= 0:
return False
return np.isclose(-np.log(1/x-1), -np.log(1/y-1))
return (np.isclose(-np.log(1/x-1), -np.log(1/y-1))
if 0 < x < 1 and 0 < y < 1 else False)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not convinced that the ternary if-else expression makes this more readable. But no strong feeling.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not so much about the ternary, more about '0 < x < 1' vs 'x >= 1 or x <= 0', I can revert to non-ternary if you prefer.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fully agree on 0 < x < 1. Would slightly prefer non-ternary-if, but as said: no strong feelings.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's see what the next reviewer says, then

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is fine this way. It is one less line of code, and one less return call.


@staticmethod
def assert_almost_equal(x, y):
Expand Down Expand Up @@ -460,19 +462,15 @@ def test_offset_value(self, left, right, offset):
fig, ax = plt.subplots()
formatter = ax.get_xaxis().get_major_formatter()

with warnings.catch_warnings(record=True) as w:
warnings.filterwarnings('always', 'Attempting to set identical',
UserWarning)
with (pytest.warns(UserWarning, match='Attempting to set identical')
if left == right else nullcontext()):
ax.set_xlim(left, right)
assert len(w) == (1 if left == right else 0)
ax.get_xaxis()._update_ticks()
assert formatter.offset == offset

with warnings.catch_warnings(record=True) as w:
warnings.filterwarnings('always', 'Attempting to set identical',
UserWarning)
with (pytest.warns(UserWarning, match='Attempting to set identical')
if left == right else nullcontext()):
ax.set_xlim(right, left)
assert len(w) == (1 if left == right else 0)
ax.get_xaxis()._update_ticks()
assert formatter.offset == offset

Expand All @@ -484,8 +482,7 @@ def test_use_offset(self, use_offset):

@pytest.mark.parametrize(
'sci_type, scilimits, lim, orderOfMag, fewticks', scilimits_data)
def test_scilimits(self, sci_type, scilimits, lim, orderOfMag,
fewticks):
def test_scilimits(self, sci_type, scilimits, lim, orderOfMag, fewticks):
tmp_form = mticker.ScalarFormatter()
tmp_form.set_scientific(sci_type)
tmp_form.set_powerlimits(scilimits)
Expand Down Expand Up @@ -542,7 +539,7 @@ def test_blank(self):
assert formatter(10**0.1) == ''


class TestLogFormatterMathtext():
class TestLogFormatterMathtext:
fmt = mticker.LogFormatterMathtext()
test_data = [
(0, 1, '$\\mathdefault{10^{0}}$'),
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/tests/test_transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ def transform_path_non_affine(self, path):
return self.real_trans.transform_path(path)


class TestBasicTransform():
class TestBasicTransform:
def setup_method(self):

self.ta1 = mtransforms.Affine2D(shorthand_name='ta1').rotate(np.pi / 2)
Expand Down
5 changes: 2 additions & 3 deletions lib/matplotlib/tight_layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,9 +220,8 @@ def get_renderer(fig):

if canvas and hasattr(canvas, "get_renderer"):
renderer = canvas.get_renderer()
else:
# not sure if this can happen
cbook._warn_external("tight_layout : falling back to Agg renderer")
else: # Some noninteractive backends have no renderer until draw time.
cbook._warn_external("tight_layout: falling back to Agg renderer")
from matplotlib.backends.backend_agg import FigureCanvasAgg
canvas = FigureCanvasAgg(fig)
renderer = canvas.get_renderer()
Expand Down
4 changes: 2 additions & 2 deletions lib/matplotlib/tri/triinterpolate.py
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,7 @@ def _compute_tri_eccentricities(tris_pts):

# FEM element used for interpolation and for solving minimisation
# problem (Reduced HCT element)
class _ReducedHCT_Element():
class _ReducedHCT_Element:
"""
Implementation of reduced HCT triangular element with explicit shape
functions.
Expand Down Expand Up @@ -1006,7 +1006,7 @@ def get_Kff_and_Ff(self, J, ecc, triangles, Uc):
# _DOF_estimator_min_E
# Private classes used to compute the degree of freedom of each triangular
# element for the TriCubicInterpolator.
class _DOF_estimator():
class _DOF_estimator:
"""
Abstract base class for classes used to perform estimation of a function
first derivatives, and deduce the dofs for a CubicTriInterpolator using a
Expand Down