Fix failing tests on maintenance branch by mdboom · Pull Request #779 · matplotlib/matplotlib · GitHub
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
The table of contents is too big for display.
Diff view
Diff view
30 changes: 16 additions & 14 deletions doc/devel/coding_guide.rst
42 changes: 25 additions & 17 deletions lib/matplotlib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -987,27 +987,35 @@ def tk_window_focus():
'matplotlib.tests.test_simplification',
'matplotlib.tests.test_mathtext',
'matplotlib.tests.test_text',
'matplotlib.tests.test_tightlayout'
'matplotlib.tests.test_tightlayout',
'matplotlib.tests.test_delaunay',
'matplotlib.tests.test_legend'
]

def test(verbosity=0):
"""run the matplotlib test suite"""
import nose
import nose.plugins.builtin
from testing.noseclasses import KnownFailure
from nose.plugins.manager import PluginManager

# store the old values before overriding
plugins = []
plugins.append( KnownFailure() )
plugins.extend( [plugin() for plugin in nose.plugins.builtin.plugins] )

manager = PluginManager(plugins=plugins)
config = nose.config.Config(verbosity=verbosity, plugins=manager)

success = nose.run( defaultTest=default_test_modules,
config=config,
)
old_backend = rcParams['backend']
try:
use('agg')
import nose
import nose.plugins.builtin
from testing.noseclasses import KnownFailure
from nose.plugins.manager import PluginManager

# store the old values before overriding
plugins = []
plugins.append( KnownFailure() )
plugins.extend( [plugin() for plugin in nose.plugins.builtin.plugins] )

manager = PluginManager(plugins=plugins)
config = nose.config.Config(verbosity=verbosity, plugins=manager)

success = nose.run( defaultTest=default_test_modules,
config=config,
)
finally:
if old_backend.lower() != 'agg':
use(old_backend)

return success

Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/backends/backend_agg.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ def draw_text(self, gc, x, y, s, prop, angle, ismath):
# We pass '0' for angle here, since it will be rotated (in raster
# space) in the following call to draw_text_image).
font.set_text(s, 0, flags=flags)
font.draw_glyphs_to_bitmap()
font.draw_glyphs_to_bitmap(antialiased=rcParams['text.antialiased'])

#print x, y, int(x), int(y), s

Expand Down
4 changes: 2 additions & 2 deletions lib/matplotlib/backends/backend_svg.py
Original file line number Diff line number Diff line change
Expand Up @@ -691,13 +691,13 @@ def draw_gouraud_triangle(self, gc, points, colors, trans):
href = '#GT%x' % self._n_gradients
writer.element(
'use',
attrib={'xlink:href': '#%s' % href,
attrib={'xlink:href': href,
'fill': rgb2hex(avg_color),
'fill-opacity': str(avg_color[-1])})
for i in range(3):
writer.element(
'use',
attrib={'xlink:href': '#%s' % href,
attrib={'xlink:href': href,
'fill': 'url(#GR%x_%d)' % (self._n_gradients, i),
'fill-opacity': '1',
'filter': 'url(#colorAdd)'})
Expand Down
3 changes: 2 additions & 1 deletion lib/matplotlib/mathtext.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,8 @@ def set_canvas_size(self, w, h, d):

def render_glyph(self, ox, oy, info):
info.font.draw_glyph_to_bitmap(
self.image, ox, oy - info.metrics.iceberg, info.glyph)
self.image, ox, oy - info.metrics.iceberg, info.glyph,
antialiased=rcParams['text.antialiased'])

def render_rect_filled(self, x1, y1, x2, y2):
height = max(int(y2 - y1) - 1, 0)
Expand Down
1 change: 1 addition & 0 deletions lib/matplotlib/rcsetup.py
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,7 @@ def __call__(self, s):
'text.latex.preview' : [False, validate_bool],
'text.dvipnghack' : [None, validate_bool_maybe_none],
'text.hinting' : [True, validate_bool],
'text.antialiased' : [True, validate_bool],

# The following are deprecated and replaced by, e.g., 'font.style'
#'text.fontstyle' : ['normal', str],
Expand Down
51 changes: 40 additions & 11 deletions lib/matplotlib/testing/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import matplotlib.tests
import matplotlib.units
from matplotlib import pyplot as plt
from matplotlib import ft2font
import numpy as np
from matplotlib.testing.compare import comparable_formats, compare_images
import warnings
Expand Down Expand Up @@ -63,7 +64,7 @@ def teardown_class(cls):
matplotlib.units.registry.clear()
matplotlib.units.registry.update(cls.original_units_registry)
warnings.resetwarnings() #reset any warning filters set in tests

def test(self):
self._func()

Expand All @@ -77,6 +78,18 @@ def cleanup(func):
{'_func': func})
return new_class

def check_freetype_version(ver):
if ver is None:
return True

from distutils import version
if isinstance(ver, str):
ver = (ver, ver)
ver = [version.StrictVersion(x) for x in ver]
found = version.StrictVersion(ft2font.__freetype_version__)

return found >= ver[0] and found <= ver[1]

class ImageComparisonTest(CleanupTest):
@classmethod
def setup_class(cls):
Expand Down Expand Up @@ -116,18 +129,25 @@ def do_test():

err = compare_images(expected_fname, actual_fname, self._tol, in_decorator=True)

if not os.path.exists(expected_fname):
raise ImageComparisonFailure(
'image does not exist: %s' % expected_fname)

if err:
raise ImageComparisonFailure(
'images not close: %(actual)s vs. %(expected)s '
'(RMS %(rms).3f)'%err)
try:
if not os.path.exists(expected_fname):
raise ImageComparisonFailure(
'image does not exist: %s' % expected_fname)

if err:
raise ImageComparisonFailure(
'images not close: %(actual)s vs. %(expected)s '
'(RMS %(rms).3f)'%err)
except ImageComparisonFailure:
if not check_freetype_version(self._freetype_version):
raise KnownFailureTest(
"Mismatched version of freetype. Test requires '%s', you have '%s'" %
(self._freetype_version, ft2font.__freetype_version__))
raise

yield (do_test,)

def image_comparison(baseline_images=None, extensions=None, tol=1e-3):
def image_comparison(baseline_images=None, extensions=None, tol=1e-3, freetype_version=None):
"""
call signature::

Expand All @@ -148,6 +168,13 @@ def image_comparison(baseline_images=None, extensions=None, tol=1e-3):
If *None*, default to all supported extensions.

Otherwise, a list of extensions to test. For example ['png','pdf'].

*tol*: (default 1e-3)
The RMS threshold above which the test is considered failed.

*freetype_version*: str or tuple
The expected freetype version or range of versions for this
test to pass.
"""

if baseline_images is None:
Expand Down Expand Up @@ -178,7 +205,9 @@ def compare_images_decorator(func):
{'_func': func,
'_baseline_images': baseline_images,
'_extensions': extensions,
'_tol': tol})
'_tol': tol,
'_freetype_version': freetype_version})

return new_class
return compare_images_decorator

Expand Down
1 change: 1 addition & 0 deletions lib/matplotlib/tests/__init__.py
Binary file modified lib/matplotlib/tests/baseline_images/test_axes/arc_ellipse.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified lib/matplotlib/tests/baseline_images/test_axes/canonical.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified lib/matplotlib/tests/baseline_images/test_axes/const_xy.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified lib/matplotlib/tests/baseline_images/test_axes/fill_units.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading