X Tutup
Skip to content
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
1 change: 0 additions & 1 deletion conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ def pytest_configure(config):
matplotlib._init_tests()

if config.getoption('--no-pep8'):
default_test_modules.remove('matplotlib.tests.test_coding_standards')
IGNORED_TESTS['matplotlib'] += 'test_coding_standards'


Expand Down
8 changes: 0 additions & 8 deletions lib/matplotlib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1474,17 +1474,9 @@ def _jupyter_nbextension_paths():


default_test_modules = [
'matplotlib.tests.test_coding_standards',
'matplotlib.tests.test_offsetbox',
'matplotlib.tests.test_patches',
'matplotlib.tests.test_path',
'matplotlib.tests.test_patheffects',
'matplotlib.tests.test_pickle',
'matplotlib.tests.test_png',
'matplotlib.tests.test_quiver',
'matplotlib.tests.test_units',
'matplotlib.tests.test_widgets',
'matplotlib.tests.test_cycles',
]


Expand Down
12 changes: 3 additions & 9 deletions lib/matplotlib/tests/test_coding_standards.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
from fnmatch import fnmatch
import os

from nose.tools import assert_equal
from nose.plugins.skip import SkipTest
import pytest
from ..testing import xfail

try:
Expand Down Expand Up @@ -103,7 +102,7 @@ def assert_pep8_conformance(module=matplotlib, exclude_files=None,
__tracebackhide__ = True

if not HAS_PEP8:
raise SkipTest('The pep8 tool is required for this test')
pytest.skip('The pep8 tool is required for this test')

# to get a list of bad files, rather than the specific errors, add
# "reporter=pep8.FileReport" to the StyleGuide constructor.
Expand Down Expand Up @@ -141,7 +140,7 @@ def assert_pep8_conformance(module=matplotlib, exclude_files=None,
"{0}".format('\n'.join(reporter._global_deferred_print)))
else:
msg = "Found code syntax errors (and warnings)."
assert_equal(result.total_errors, 0, msg)
assert result.total_errors == 0, msg

# If we've been using the exclusions reporter, check that we didn't
# exclude files unnecessarily.
Expand Down Expand Up @@ -287,8 +286,3 @@ def test_pep8_conformance_examples():
pep8_additional_ignore=PEP8_ADDITIONAL_IGNORE +
['E116', 'E501', 'E402'],
expected_bad_files=expected_bad_files)


if __name__ == '__main__':
import nose
nose.runmodule(argv=['-s', '--with-doctest'], exit=False)
12 changes: 5 additions & 7 deletions lib/matplotlib/tests/test_colors.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import numpy as np

from numpy.testing import assert_raises, assert_equal
from numpy.testing import assert_equal
from numpy.testing.utils import assert_array_equal, assert_array_almost_equal

from matplotlib import cycler
Expand Down Expand Up @@ -336,7 +336,8 @@ def test_cmap_and_norm_from_levels_and_colors2():
'Wih extend={0!r} and data '
'value={1!r}'.format(extend, d_val))

assert_raises(ValueError, mcolors.from_levels_and_colors, levels, colors)
with pytest.raises(ValueError):
mcolors.from_levels_and_colors(levels, colors)


def test_rgb_hsv_round_trip():
Expand All @@ -359,11 +360,8 @@ def test_autoscale_masked():

def test_colors_no_float():
# Gray must be a string to distinguish 3-4 grays from RGB or RGBA.

def gray_from_float_rgba():
return mcolors.to_rgba(0.4)

assert_raises(ValueError, gray_from_float_rgba)
with pytest.raises(ValueError):
mcolors.to_rgba(0.4)


@image_comparison(baseline_images=['light_source_shading_topo'],
Expand Down
7 changes: 4 additions & 3 deletions lib/matplotlib/tests/test_contour.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
from matplotlib import mlab
from matplotlib.testing.decorators import cleanup, image_comparison
from matplotlib import pyplot as plt
from numpy.testing import assert_equal, assert_raises
from numpy.testing import assert_array_almost_equal
import pytest
import warnings

import re
Expand Down Expand Up @@ -282,13 +282,14 @@ def test_contourf_decreasing_levels():
# github issue 5477.
z = [[0.1, 0.3], [0.5, 0.7]]
plt.figure()
assert_raises(ValueError, plt.contourf, z, [1.0, 0.0])
with pytest.raises(ValueError):
plt.contourf(z, [1.0, 0.0])
# Legacy contouring algorithm gives a warning rather than raising an error,
# plus a DeprecationWarning.
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter("always")
plt.contourf(z, [1.0, 0.0], corner_mask='legacy')
assert_equal(len(w), 2)
assert len(w) == 2


@cleanup
Expand Down
42 changes: 26 additions & 16 deletions lib/matplotlib/tests/test_cycles.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from matplotlib.cbook import MatplotlibDeprecationWarning
import matplotlib.pyplot as plt
import numpy as np
from numpy.testing import assert_raises
import pytest

from cycler import cycler

Expand Down Expand Up @@ -198,18 +198,28 @@ def test_cycle_reset():
@cleanup
def test_invalid_input_forms():
fig, ax = plt.subplots()
assert_raises((TypeError, ValueError), ax.set_prop_cycle, 1)
assert_raises((TypeError, ValueError), ax.set_prop_cycle, [1, 2])
assert_raises((TypeError, ValueError), ax.set_prop_cycle, 'color', 'fish')
assert_raises((TypeError, ValueError), ax.set_prop_cycle, 'linewidth', 1)
assert_raises((TypeError, ValueError), ax.set_prop_cycle,
'linewidth', {'1': 1, '2': 2})
assert_raises((TypeError, ValueError), ax.set_prop_cycle,
linewidth=1, color='r')
assert_raises((TypeError, ValueError), ax.set_prop_cycle, 'foobar', [1, 2])
assert_raises((TypeError, ValueError), ax.set_prop_cycle,
foobar=[1, 2])
assert_raises((TypeError, ValueError), ax.set_prop_cycle,
cycler(foobar=[1, 2]))
assert_raises(ValueError, ax.set_prop_cycle,
cycler(color='rgb', c='cmy'))

with pytest.raises((TypeError, ValueError)):
ax.set_prop_cycle(1)
with pytest.raises((TypeError, ValueError)):
ax.set_prop_cycle([1, 2])

with pytest.raises((TypeError, ValueError)):
ax.set_prop_cycle('color', 'fish')

with pytest.raises((TypeError, ValueError)):
ax.set_prop_cycle('linewidth', 1)
with pytest.raises((TypeError, ValueError)):
ax.set_prop_cycle('linewidth', {'1': 1, '2': 2})
with pytest.raises((TypeError, ValueError)):
ax.set_prop_cycle(linewidth=1, color='r')

with pytest.raises((TypeError, ValueError)):
ax.set_prop_cycle('foobar', [1, 2])
with pytest.raises((TypeError, ValueError)):
ax.set_prop_cycle(foobar=[1, 2])

with pytest.raises((TypeError, ValueError)):
ax.set_prop_cycle(cycler(foobar=[1, 2]))
with pytest.raises(ValueError):
ax.set_prop_cycle(cycler(color='rgb', c='cmy'))
20 changes: 13 additions & 7 deletions lib/matplotlib/tests/test_dates.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
except ImportError:
import mock

from numpy.testing import assert_raises, assert_equal
from numpy.testing import assert_equal

from matplotlib.testing.decorators import image_comparison, cleanup
import matplotlib.pyplot as plt
Expand Down Expand Up @@ -108,7 +108,8 @@ def test_too_many_date_ticks():
ax.set_xlim((t0, tf), auto=True)
ax.plot([], [])
ax.xaxis.set_major_locator(mdates.DayLocator())
assert_raises(RuntimeError, fig.savefig, 'junk.png')
with pytest.raises(RuntimeError):
fig.savefig('junk.png')


@image_comparison(baseline_images=['RRuleLocator_bounds'], extensions=['png'])
Expand Down Expand Up @@ -266,7 +267,8 @@ def test_empty_date_with_year_formatter():
ax.xaxis.set_major_formatter(yearFmt)

with tempfile.TemporaryFile() as fh:
assert_raises(ValueError, fig.savefig, fh)
with pytest.raises(ValueError):
fig.savefig(fh)


def test_auto_date_locator():
Expand Down Expand Up @@ -453,10 +455,14 @@ def tz_convert(*args):


def test_DayLocator():
assert_raises(ValueError, mdates.DayLocator, interval=-1)
assert_raises(ValueError, mdates.DayLocator, interval=-1.5)
assert_raises(ValueError, mdates.DayLocator, interval=0)
assert_raises(ValueError, mdates.DayLocator, interval=1.3)
with pytest.raises(ValueError):
mdates.DayLocator(interval=-1)
with pytest.raises(ValueError):
mdates.DayLocator(interval=-1.5)
with pytest.raises(ValueError):
mdates.DayLocator(interval=0)
with pytest.raises(ValueError):
mdates.DayLocator(interval=1.3)
mdates.DayLocator(interval=1.0)


Expand Down
5 changes: 2 additions & 3 deletions lib/matplotlib/tests/test_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@
import os
import warnings


import numpy as np
from numpy.testing import assert_array_equal

from matplotlib.testing.decorators import (image_comparison,
knownfailureif, cleanup)
from matplotlib.image import (BboxImage, imread, NonUniformImage,
AxesImage, FigureImage, PcolorImage)
from matplotlib.image import (AxesImage, BboxImage, FigureImage,
NonUniformImage, PcolorImage)
from matplotlib.transforms import Bbox, Affine2D, TransformedBbox
from matplotlib import rcParams, rc_context
from matplotlib import patches
Expand Down
5 changes: 0 additions & 5 deletions lib/matplotlib/tests/test_legend.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,8 +331,3 @@ def test_linecollection_scaled_dashes():
for oh, lh in zip((lc1, lc2, lc3), (h1, h2, h3)):
assert oh.get_linestyles()[0][1] == lh._dashSeq
assert oh.get_linestyles()[0][0] == lh._dashOffset


if __name__ == '__main__':
import nose
nose.runmodule(argv=['-s', '--with-doctest'], exit=False)
6 changes: 3 additions & 3 deletions lib/matplotlib/tests/test_lines.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import itertools
import matplotlib.lines as mlines
from numpy.testing import assert_raises
import pytest
from timeit import repeat
import numpy as np
from cycler import cycler
Expand Down Expand Up @@ -109,7 +109,7 @@ def test_linestyle_variants():
@cleanup
def test_valid_linestyles():
line = mlines.Line2D([], [])
with assert_raises(ValueError):
with pytest.raises(ValueError):
line.set_linestyle('aardvark')


Expand All @@ -130,7 +130,7 @@ def test_drawstyle_variants():
@cleanup
def test_valid_drawstyles():
line = mlines.Line2D([], [])
with assert_raises(ValueError):
with pytest.raises(ValueError):
line.set_drawstyle('foobar')


Expand Down
10 changes: 0 additions & 10 deletions lib/matplotlib/tests/test_mlab.py
Original file line number Diff line number Diff line change
Expand Up @@ -3102,13 +3102,3 @@ def test_psd_onesided_norm():
sides='onesided')
Su_1side = np.append([Su[0]], Su[1:4] + Su[4:][::-1])
assert_allclose(P, Su_1side, atol=1e-06)


if __name__ == '__main__':
import nose
import sys

args = ['-s', '--with-doctest']
argv = sys.argv
argv = argv[:1] + args + argv[1:]
nose.runmodule(argv=argv, exit=False)
9 changes: 2 additions & 7 deletions lib/matplotlib/tests/test_offsetbox.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
from __future__ import (absolute_import, division, print_function,
unicode_literals)

import nose
from nose.tools import assert_true, assert_false
from matplotlib.testing.decorators import image_comparison, cleanup
import matplotlib.pyplot as plt
import matplotlib.patches as mpatches
Expand Down Expand Up @@ -78,9 +76,9 @@ def test_offsetbox_clip_children():
ax.add_artist(anchored_box)

fig.canvas.draw()
assert_false(fig.stale)
assert not fig.stale
da.clip_children = True
assert_true(fig.stale)
assert fig.stale


@cleanup
Expand All @@ -103,6 +101,3 @@ def test_offsetbox_loc_codes():
anchored_box = AnchoredOffsetbox(loc=code, child=da)
ax.add_artist(anchored_box)
fig.canvas.draw()

if __name__ == '__main__':
nose.runmodule(argv=['-s', '--with-doctest'], exit=False)
13 changes: 3 additions & 10 deletions lib/matplotlib/tests/test_patches.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
import six

import numpy as np
from numpy.testing import assert_array_equal
from numpy.testing import assert_equal
from numpy.testing import assert_almost_equal
from numpy.testing import assert_almost_equal, assert_array_equal

from matplotlib.patches import Polygon
from matplotlib.patches import Rectangle
Expand Down Expand Up @@ -255,9 +253,9 @@ def test_wedge_movement():

w = mpatches.Wedge(**init_args)
for attr, (old_v, new_v, func) in six.iteritems(param_dict):
assert_equal(getattr(w, attr), old_v)
assert getattr(w, attr) == old_v
getattr(w, func)(new_v)
assert_equal(getattr(w, attr), new_v)
assert getattr(w, attr) == new_v


# png needs tol>=0.06, pdf tol>=1.617
Expand Down Expand Up @@ -313,8 +311,3 @@ def test_patch_str():
p = mpatches.Arc(xy=(1, 2), width=3, height=4, angle=5, theta1=6, theta2=7)
expected = 'Arc(xy=(1, 2), width=3, height=4, angle=5, theta1=6, theta2=7)'
assert str(p) == expected


if __name__ == '__main__':
import nose
nose.runmodule(argv=['-s', '--with-doctest'], exit=False)
14 changes: 4 additions & 10 deletions lib/matplotlib/tests/test_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@
unicode_literals)
import copy

import six

import numpy as np

from numpy.testing import assert_array_equal
import pytest

from matplotlib.path import Path
from matplotlib.patches import Polygon
from nose.tools import assert_raises, assert_equal
from matplotlib.testing.decorators import image_comparison
import matplotlib.pyplot as plt
from matplotlib import transforms
Expand All @@ -22,7 +20,8 @@ def test_readonly_path():
def modify_vertices():
path.vertices = path.vertices * 2.0

assert_raises(AttributeError, modify_vertices)
with pytest.raises(AttributeError):
modify_vertices()


def test_point_in_path():
Expand Down Expand Up @@ -90,7 +89,7 @@ def test_make_compound_path_empty():
# We should be able to make a compound path with no arguments.
# This makes it easier to write generic path based code.
r = Path.make_compound_path()
assert_equal(r.vertices.shape, (0, 2))
assert r.vertices.shape == (0, 2)


@image_comparison(baseline_images=['xkcd'], remove_text=True)
Expand Down Expand Up @@ -181,8 +180,3 @@ def test_path_deepcopy():
path2 = Path(verts, codes)
copy.deepcopy(path1)
copy.deepcopy(path2)


if __name__ == '__main__':
import nose
nose.runmodule(argv=['-s', '--with-doctest'], exit=False)
Loading
X Tutup