Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

py3fication of some tests. #11073

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
Apr 18, 2018
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
6 changes: 5 additions & 1 deletion 6 doc/api/next_api_changes/2018-02-15-AL-deprecations.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ The following classes, methods, functions, and attributes are deprecated:
- ``dates.DateFormatter.strftime_pre_1900``, ``dates.DateFormatter.strftime``,
- ``font_manager.TempCache``,
- ``mathtext.unichr_safe`` (use ``chr`` instead),
- ``testing.ImageComparisonTest``,
- ``testing.compare.ImageComparisonTest``, ``testing.compare.compare_float``,
- ``testing.decorators.skip_if_command_unavailable``.
- ``FigureCanvasQT.keyAutoRepeat`` (directly check
``event.guiEvent.isAutoRepeat()`` in the event handler to decide whether to
handle autorepeated key presses).
- ``FigureCanvasWx.macros``,
- ``_ImageBase.iterpnames``, use the ``interpolation_names`` property instead.
(this affects classes that inherit from ``_ImageBase`` including
Expand Down
5 changes: 0 additions & 5 deletions 5 doc/api/next_api_changes/2018-02-16-AL-deprecations.rst

This file was deleted.

1 change: 1 addition & 0 deletions 1 lib/matplotlib/testing/compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def make_test_filename(fname, purpose):
return '%s-%s%s' % (base, purpose, ext)


@cbook.deprecated("3.0")
def compare_float(expected, actual, relTol=None, absTol=None):
"""
Fail if the floating point values are not close enough, with
Expand Down
40 changes: 9 additions & 31 deletions 40 lib/matplotlib/testing/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -434,39 +434,16 @@ def image_comparison(baseline_images, extensions=None, tol=0,
def _image_directories(func):
"""
Compute the baseline and result image directories for testing *func*.
Create the result directory if it doesn't exist.

For test module ``foo.bar.test_baz``, the baseline directory is at
``foo/bar/baseline_images/test_baz`` and the result directory at
``$(pwd)/result_images/test_baz``. The result directory is created if it
doesn't exist.
"""
module_name = func.__module__
if module_name == '__main__':
# FIXME: this won't work for nested packages in matplotlib.tests
warnings.warn(
'Test module run as script. Guessing baseline image locations.')
module_path = Path(sys.argv[0]).resolve()
subdir = module_path.stem
else:
module_path = Path(sys.modules[func.__module__].__file__)
mods = module_name.split('.')
if len(mods) >= 3:
mods.pop(0)
# mods[0] will be the name of the package being tested (in
# most cases "matplotlib") However if this is a
# namespace package pip installed and run via the nose
# multiprocess plugin or as a specific test this may be
# missing. See https://github.com/matplotlib/matplotlib/issues/3314
if mods.pop(0) != 'tests':
warnings.warn(
"Module {!r} does not live in a parent module named 'tests'. "
"This is probably ok, but we may not be able to guess the "
"correct subdirectory containing the baseline images. If "
"things go wrong please make sure that there is a parent "
"directory named 'tests' and that it contains a __init__.py "
"file (can be empty).".format(module_name))
subdir = os.path.join(*mods)

baseline_dir = module_path.parent / 'baseline_images' / subdir
result_dir = Path().resolve() / 'result_images' / subdir
module_path = Path(sys.modules[func.__module__].__file__)
baseline_dir = module_path.parent / "baseline_images" / module_path.stem
result_dir = Path().resolve() / "result_images" / module_path.stem
result_dir.mkdir(parents=True, exist_ok=True)

return str(baseline_dir), str(result_dir)


Expand All @@ -489,6 +466,7 @@ def backend_switcher(*args, **kwargs):
return switch_backend_decorator


@cbook.deprecated("3.0")
def skip_if_command_unavailable(cmd):
"""
skips a test if a command is unavailable.
Expand Down
10 changes: 1 addition & 9 deletions 10 lib/matplotlib/tests/test_compare_images.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,11 @@
from __future__ import absolute_import, division, print_function

import six

import io
import os
import shutil
import warnings

from numpy.testing import assert_almost_equal
import pytest
from pytest import approx

from matplotlib.testing.compare import compare_images
from matplotlib.testing.decorators import _image_directories, image_comparison
from matplotlib.testing.exceptions import ImageComparisonFailure
from matplotlib.testing.decorators import _image_directories


baseline_dir, result_dir = _image_directories(lambda: 'dummy func')
Expand Down
34 changes: 15 additions & 19 deletions 34 lib/matplotlib/tests/test_dviread.py
Original file line number Diff line number Diff line change
@@ -1,34 +1,32 @@
from matplotlib.testing.decorators import skip_if_command_unavailable
import json
from pathlib import Path
import shutil

import matplotlib.dviread as dr
import os.path
import json
import pytest


def test_PsfontsMap(monkeypatch):
monkeypatch.setattr(dr, 'find_tex_file', lambda x: x)

filename = os.path.join(
os.path.dirname(__file__),
'baseline_images', 'dviread', 'test.map')
filename = str(Path(__file__).parent / 'baseline_images/dviread/test.map')
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't 'baseline_images/dviread/test.map' still be created with os.path.join?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

no, pathlib handles these internally just fine (see e.g. third example of https://docs.python.org/3/library/pathlib.html#operators).

fontmap = dr.PsfontsMap(filename)
# Check all properties of a few fonts
for n in [1, 2, 3, 4, 5]:
key = ('TeXfont%d' % n).encode('ascii')
key = b'TeXfont%d' % n
entry = fontmap[key]
assert entry.texname == key
assert entry.psname == ('PSfont%d' % n).encode('ascii')
assert entry.psname == b'PSfont%d' % n
if n not in [3, 5]:
assert entry.encoding == ('font%d.enc' % n).encode('ascii')
assert entry.encoding == b'font%d.enc' % n
elif n == 3:
assert entry.encoding == b'enc3.foo'
# We don't care about the encoding of TeXfont5, which specifies
# multiple encodings.
if n not in [1, 5]:
assert entry.filename == ('font%d.pfa' % n).encode('ascii')
assert entry.filename == b'font%d.pfa' % n
else:
assert entry.filename == ('font%d.pfb' % n).encode('ascii')
assert entry.filename == b'font%d.pfb' % n
if n == 4:
assert entry.effects == {'slant': -0.1, 'extend': 2.2}
else:
Expand All @@ -51,18 +49,16 @@ def test_PsfontsMap(monkeypatch):
assert 'no-such-font' in str(exc.value)


@skip_if_command_unavailable(["kpsewhich", "-version"])
@pytest.mark.skipif(shutil.which("kpsewhich") is None,
reason="kpsewhich is not available")
def test_dviread():
dir = os.path.join(os.path.dirname(__file__), 'baseline_images', 'dviread')
with open(os.path.join(dir, 'test.json')) as f:
dirpath = Path(__file__).parent / 'baseline_images/dviread'
with (dirpath / 'test.json').open() as f:
correct = json.load(f)
for entry in correct:
entry['text'] = [[a, b, c, d.encode('ascii'), e]
for [a, b, c, d, e] in entry['text']]
with dr.Dvi(os.path.join(dir, 'test.dvi'), None) as dvi:
with dr.Dvi(str(dirpath / 'test.dvi'), None) as dvi:
data = [{'text': [[t.x, t.y,
chr(t.glyph),
t.font.texname,
t.font.texname.decode('ascii'),
round(t.font.size, 2)]
for t in page.text],
'boxes': [[b.x, b.y, b.height, b.width] for b in page.boxes]}
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.