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

Skip to content

Commit acfc0e2

Browse files
authored
Merge pull request #11073 from anntzer/py3tests
py3fication of some tests.
2 parents ff8cc81 + 136ce07 commit acfc0e2

File tree

6 files changed

+31
-65
lines changed

6 files changed

+31
-65
lines changed

doc/api/next_api_changes/2018-02-15-AL-deprecations.rst

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,11 @@ The following classes, methods, functions, and attributes are deprecated:
1919
- ``dates.DateFormatter.strftime_pre_1900``, ``dates.DateFormatter.strftime``,
2020
- ``font_manager.TempCache``,
2121
- ``mathtext.unichr_safe`` (use ``chr`` instead),
22-
- ``testing.ImageComparisonTest``,
22+
- ``testing.compare.ImageComparisonTest``, ``testing.compare.compare_float``,
23+
- ``testing.decorators.skip_if_command_unavailable``.
24+
- ``FigureCanvasQT.keyAutoRepeat`` (directly check
25+
``event.guiEvent.isAutoRepeat()`` in the event handler to decide whether to
26+
handle autorepeated key presses).
2327
- ``FigureCanvasWx.macros``,
2428
- ``_ImageBase.iterpnames``, use the ``interpolation_names`` property instead.
2529
(this affects classes that inherit from ``_ImageBase`` including

doc/api/next_api_changes/2018-02-16-AL-deprecations.rst

Lines changed: 0 additions & 5 deletions
This file was deleted.

lib/matplotlib/testing/compare.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ def make_test_filename(fname, purpose):
3535
return '%s-%s%s' % (base, purpose, ext)
3636

3737

38+
@cbook.deprecated("3.0")
3839
def compare_float(expected, actual, relTol=None, absTol=None):
3940
"""
4041
Fail if the floating point values are not close enough, with

lib/matplotlib/testing/decorators.py

Lines changed: 9 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -434,39 +434,16 @@ def image_comparison(baseline_images, extensions=None, tol=0,
434434
def _image_directories(func):
435435
"""
436436
Compute the baseline and result image directories for testing *func*.
437-
Create the result directory if it doesn't exist.
437+
438+
For test module ``foo.bar.test_baz``, the baseline directory is at
439+
``foo/bar/baseline_images/test_baz`` and the result directory at
440+
``$(pwd)/result_images/test_baz``. The result directory is created if it
441+
doesn't exist.
438442
"""
439-
module_name = func.__module__
440-
if module_name == '__main__':
441-
# FIXME: this won't work for nested packages in matplotlib.tests
442-
warnings.warn(
443-
'Test module run as script. Guessing baseline image locations.')
444-
module_path = Path(sys.argv[0]).resolve()
445-
subdir = module_path.stem
446-
else:
447-
module_path = Path(sys.modules[func.__module__].__file__)
448-
mods = module_name.split('.')
449-
if len(mods) >= 3:
450-
mods.pop(0)
451-
# mods[0] will be the name of the package being tested (in
452-
# most cases "matplotlib") However if this is a
453-
# namespace package pip installed and run via the nose
454-
# multiprocess plugin or as a specific test this may be
455-
# missing. See https://github.com/matplotlib/matplotlib/issues/3314
456-
if mods.pop(0) != 'tests':
457-
warnings.warn(
458-
"Module {!r} does not live in a parent module named 'tests'. "
459-
"This is probably ok, but we may not be able to guess the "
460-
"correct subdirectory containing the baseline images. If "
461-
"things go wrong please make sure that there is a parent "
462-
"directory named 'tests' and that it contains a __init__.py "
463-
"file (can be empty).".format(module_name))
464-
subdir = os.path.join(*mods)
465-
466-
baseline_dir = module_path.parent / 'baseline_images' / subdir
467-
result_dir = Path().resolve() / 'result_images' / subdir
443+
module_path = Path(sys.modules[func.__module__].__file__)
444+
baseline_dir = module_path.parent / "baseline_images" / module_path.stem
445+
result_dir = Path().resolve() / "result_images" / module_path.stem
468446
result_dir.mkdir(parents=True, exist_ok=True)
469-
470447
return str(baseline_dir), str(result_dir)
471448

472449

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

491468

469+
@cbook.deprecated("3.0")
492470
def skip_if_command_unavailable(cmd):
493471
"""
494472
skips a test if a command is unavailable.

lib/matplotlib/tests/test_compare_images.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,11 @@
1-
from __future__ import absolute_import, division, print_function
2-
3-
import six
4-
5-
import io
61
import os
72
import shutil
8-
import warnings
93

10-
from numpy.testing import assert_almost_equal
114
import pytest
125
from pytest import approx
136

147
from matplotlib.testing.compare import compare_images
15-
from matplotlib.testing.decorators import _image_directories, image_comparison
16-
from matplotlib.testing.exceptions import ImageComparisonFailure
8+
from matplotlib.testing.decorators import _image_directories
179

1810

1911
baseline_dir, result_dir = _image_directories(lambda: 'dummy func')

lib/matplotlib/tests/test_dviread.py

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,32 @@
1-
from matplotlib.testing.decorators import skip_if_command_unavailable
1+
import json
2+
from pathlib import Path
3+
import shutil
24

35
import matplotlib.dviread as dr
4-
import os.path
5-
import json
66
import pytest
77

88

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

12-
filename = os.path.join(
13-
os.path.dirname(__file__),
14-
'baseline_images', 'dviread', 'test.map')
12+
filename = str(Path(__file__).parent / 'baseline_images/dviread/test.map')
1513
fontmap = dr.PsfontsMap(filename)
1614
# Check all properties of a few fonts
1715
for n in [1, 2, 3, 4, 5]:
18-
key = ('TeXfont%d' % n).encode('ascii')
16+
key = b'TeXfont%d' % n
1917
entry = fontmap[key]
2018
assert entry.texname == key
21-
assert entry.psname == ('PSfont%d' % n).encode('ascii')
19+
assert entry.psname == b'PSfont%d' % n
2220
if n not in [3, 5]:
23-
assert entry.encoding == ('font%d.enc' % n).encode('ascii')
21+
assert entry.encoding == b'font%d.enc' % n
2422
elif n == 3:
2523
assert entry.encoding == b'enc3.foo'
2624
# We don't care about the encoding of TeXfont5, which specifies
2725
# multiple encodings.
2826
if n not in [1, 5]:
29-
assert entry.filename == ('font%d.pfa' % n).encode('ascii')
27+
assert entry.filename == b'font%d.pfa' % n
3028
else:
31-
assert entry.filename == ('font%d.pfb' % n).encode('ascii')
29+
assert entry.filename == b'font%d.pfb' % n
3230
if n == 4:
3331
assert entry.effects == {'slant': -0.1, 'extend': 2.2}
3432
else:
@@ -51,18 +49,16 @@ def test_PsfontsMap(monkeypatch):
5149
assert 'no-such-font' in str(exc.value)
5250

5351

54-
@skip_if_command_unavailable(["kpsewhich", "-version"])
52+
@pytest.mark.skipif(shutil.which("kpsewhich") is None,
53+
reason="kpsewhich is not available")
5554
def test_dviread():
56-
dir = os.path.join(os.path.dirname(__file__), 'baseline_images', 'dviread')
57-
with open(os.path.join(dir, 'test.json')) as f:
55+
dirpath = Path(__file__).parent / 'baseline_images/dviread'
56+
with (dirpath / 'test.json').open() as f:
5857
correct = json.load(f)
59-
for entry in correct:
60-
entry['text'] = [[a, b, c, d.encode('ascii'), e]
61-
for [a, b, c, d, e] in entry['text']]
62-
with dr.Dvi(os.path.join(dir, 'test.dvi'), None) as dvi:
58+
with dr.Dvi(str(dirpath / 'test.dvi'), None) as dvi:
6359
data = [{'text': [[t.x, t.y,
6460
chr(t.glyph),
65-
t.font.texname,
61+
t.font.texname.decode('ascii'),
6662
round(t.font.size, 2)]
6763
for t in page.text],
6864
'boxes': [[b.x, b.y, b.height, b.width] for b in page.boxes]}

0 commit comments

Comments
 (0)