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
7 changes: 0 additions & 7 deletions lib/matplotlib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1474,13 +1474,6 @@ def _jupyter_nbextension_paths():


default_test_modules = [
'matplotlib.tests.test_backend_bases',
'matplotlib.tests.test_backend_pdf',
'matplotlib.tests.test_backend_pgf',
'matplotlib.tests.test_backend_ps',
'matplotlib.tests.test_backend_qt4',
'matplotlib.tests.test_backend_qt5',
'matplotlib.tests.test_backend_svg',
'matplotlib.tests.test_coding_standards',
'matplotlib.tests.test_dviread',
'matplotlib.tests.test_figure',
Expand Down
1 change: 1 addition & 0 deletions lib/matplotlib/testing/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,7 @@ def switch_backend(backend):
# Local import to avoid a hard nose dependency and only incur the
# import time overhead at actual test-time.
def switch_backend_decorator(func):
@functools.wraps(func)
def backend_switcher(*args, **kwargs):
try:
prev_backend = mpl.get_backend()
Expand Down
11 changes: 6 additions & 5 deletions lib/matplotlib/testing/determinism.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
import sys
from subprocess import check_output

import pytest

import matplotlib
from matplotlib import pyplot as plt

from nose.plugins.skip import SkipTest


def _determinism_save(objects='mhi', format="pdf", usetex=False):
# save current value of SOURCE_DATE_EPOCH and set it
Expand Down Expand Up @@ -92,11 +92,11 @@ def _determinism_check(objects='mhi', format="pdf", usetex=False):
format : str
format string. The default value is "pdf".
"""
from nose.tools import assert_equal
plots = []
for i in range(3):
result = check_output([sys.executable, '-R', '-c',
'import matplotlib; '
'matplotlib._called_from_pytest = True; '
'matplotlib.use(%r); '
'from matplotlib.testing.determinism '
'import _determinism_save;'
Expand All @@ -106,9 +106,9 @@ def _determinism_check(objects='mhi', format="pdf", usetex=False):
for p in plots[1:]:
if usetex:
if p != plots[0]:
raise SkipTest("failed, maybe due to ghostscript timestamps")
pytest.skip("failed, maybe due to ghostscript timestamps")
else:
assert_equal(p, plots[0])
assert p == plots[0]


def _determinism_source_date_epoch(format, string, keyword=b"CreationDate"):
Expand All @@ -130,6 +130,7 @@ def _determinism_source_date_epoch(format, string, keyword=b"CreationDate"):
"""
buff = check_output([sys.executable, '-R', '-c',
'import matplotlib; '
'matplotlib._called_from_pytest = True; '
'matplotlib.use(%r); '
'from matplotlib.testing.determinism '
'import _determinism_save;'
Expand Down
10 changes: 2 additions & 8 deletions lib/matplotlib/tests/test_backend_bases.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
import matplotlib.transforms as transforms
import matplotlib.path as path

from nose.tools import assert_equal

import numpy as np
import os
import shutil
Expand Down Expand Up @@ -63,7 +61,7 @@ def test_get_default_filename():
fig = plt.figure()
canvas = FigureCanvasBase(fig)
filename = canvas.get_default_filename()
assert_equal(filename, 'image.png')
assert filename == 'image.png'
finally:
shutil.rmtree(test_dir)

Expand All @@ -81,10 +79,6 @@ def test_get_default_filename_already_exists():
open(os.path.join(test_dir, 'image.png'), 'w').close()

filename = canvas.get_default_filename()
assert_equal(filename, 'image-1.png')
assert filename == 'image-1.png'
finally:
shutil.rmtree(test_dir)

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

try:
from unittest.mock import patch
except ImportError:
from mock import patch
from nose.tools import raises
import pytest

import numpy as np
from matplotlib import checkdep_tex, cm, rcParams
Expand Down Expand Up @@ -194,15 +190,15 @@ def test_grayscale_alpha():

@cleanup
@needs_tex
@raises(ValueError)
@patch('matplotlib.dviread.PsfontsMap.__getitem__')
def test_missing_psfont(mock):
def test_missing_psfont(monkeypatch):
"""An error is raised if a TeX font lacks a Type-1 equivalent"""
psfont = dviread.PsFont(texname='texfont', psname='Some Font',
effects=None, encoding=None, filename=None)
mock.configure_mock(return_value=psfont)
def psfont(*args, **kwargs):
return dviread.PsFont(texname='texfont', psname='Some Font',
effects=None, encoding=None, filename=None)

monkeypatch.setattr(dviread.PsfontsMap, '__getitem__', psfont)
rcParams['text.usetex'] = True
fig, ax = plt.subplots()
ax.text(0.5, 0.5, 'hello')
with tempfile.TemporaryFile() as tmpfile:
with tempfile.TemporaryFile() as tmpfile, pytest.raises(ValueError):
fig.savefig(tmpfile, format='pdf')
37 changes: 14 additions & 23 deletions lib/matplotlib/tests/test_backend_pgf.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import shutil

import numpy as np
from nose.plugins.skip import SkipTest
import pytest

import matplotlib as mpl
import matplotlib.pyplot as plt
Expand Down Expand Up @@ -38,6 +38,12 @@ def check_for(texsystem):
return latex.returncode == 0


needs_xelatex = pytest.mark.skipif(not check_for('xelatex'),
reason='xelatex + pgf is required')
needs_pdflatex = pytest.mark.skipif(not check_for('pdflatex'),
reason='pdflatex + pgf is required')


def compare_figure(fname, savefig_kwargs={}, tol=0):
actual = os.path.join(result_dir, fname)
plt.savefig(actual, **savefig_kwargs)
Expand Down Expand Up @@ -76,12 +82,10 @@ def create_figure():


# test compiling a figure to pdf with xelatex
@needs_xelatex
@cleanup(style='classic')
@switch_backend('pgf')
def test_xelatex():
if not check_for('xelatex'):
raise SkipTest('xelatex + pgf is required')

rc_xelatex = {'font.family': 'serif',
'pgf.rcfonts': False}
mpl.rcParams.update(rc_xelatex)
Expand All @@ -90,6 +94,7 @@ def test_xelatex():


# test compiling a figure to pdf with pdflatex
@needs_pdflatex
@cleanup(style='classic')
@switch_backend('pgf')
def test_pdflatex():
Expand All @@ -98,8 +103,6 @@ def test_pdflatex():
from matplotlib.testing import xfail
xfail("pdflatex test does not work on appveyor due "
"to missing latex fonts")
if not check_for('pdflatex'):
raise SkipTest('pdflatex + pgf is required')

rc_pdflatex = {'font.family': 'serif',
'pgf.rcfonts': False,
Expand All @@ -112,12 +115,11 @@ def test_pdflatex():


# test updating the rc parameters for each figure
@needs_xelatex
@needs_pdflatex
@cleanup(style='classic')
@switch_backend('pgf')
def test_rcupdate():
if not check_for('xelatex') or not check_for('pdflatex'):
raise SkipTest('xelatex and pdflatex + pgf required')

rc_sets = []
rc_sets.append({'font.family': 'sans-serif',
'font.size': 30,
Expand Down Expand Up @@ -145,12 +147,10 @@ def test_rcupdate():


# test backend-side clipping, since large numbers are not supported by TeX
@needs_xelatex
@cleanup(style='classic')
@switch_backend('pgf')
def test_pathclip():
if not check_for('xelatex'):
raise SkipTest('xelatex + pgf is required')

rc_xelatex = {'font.family': 'serif',
'pgf.rcfonts': False}
mpl.rcParams.update(rc_xelatex)
Expand All @@ -164,12 +164,10 @@ def test_pathclip():


# test mixed mode rendering
@needs_xelatex
@cleanup(style='classic')
@switch_backend('pgf')
def test_mixedmode():
if not check_for('xelatex'):
raise SkipTest('xelatex + pgf is required')

rc_xelatex = {'font.family': 'serif',
'pgf.rcfonts': False}
mpl.rcParams.update(rc_xelatex)
Expand All @@ -181,12 +179,10 @@ def test_mixedmode():


# test bbox_inches clipping
@needs_xelatex
@cleanup(style='classic')
@switch_backend('pgf')
def test_bbox_inches():
if not check_for('xelatex'):
raise SkipTest('xelatex + pgf is required')

rc_xelatex = {'font.family': 'serif',
'pgf.rcfonts': False}
mpl.rcParams.update(rc_xelatex)
Expand All @@ -202,8 +198,3 @@ def test_bbox_inches():
bbox = ax1.get_window_extent().transformed(fig.dpi_scale_trans.inverted())
compare_figure('pgf_bbox_inches.pdf', savefig_kwargs={'bbox_inches': bbox},
tol=0)


if __name__ == '__main__':
import nose
nose.runmodule(argv=['-s', '--with-doctest'], exit=False)
5 changes: 0 additions & 5 deletions lib/matplotlib/tests/test_backend_ps.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,3 @@ def test_determinism_all():
def test_determinism_all_tex():
"""Test for reproducible PS/tex output"""
_determinism_check(format="ps", usetex=True)


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