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

Skip to content

Commit b07fbb8

Browse files
authored
Merge pull request #8708 from QuLogic/flaky-tests
Fix flaky text tests
2 parents 90ded74 + 2005738 commit b07fbb8

File tree

8 files changed

+33
-8
lines changed

8 files changed

+33
-8
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
Unique identifier added to `RendererBase` classes
2+
`````````````````````````````````````````````````
3+
4+
Since ``id()`` is not guaranteed to be unique between objects that exist at
5+
different times, a new private property ``_uid`` has been added to
6+
`RendererBase` which is used along with the renderer's ``id()`` to cache
7+
certain expensive operations.
8+
9+
If a custom renderer does not subclass `RendererBase` or `MixedModeRenderer`,
10+
it is not required to implement this ``_uid`` property, but this may produce
11+
incorrect behavior when the renderers' ``id()`` clashes.

lib/matplotlib/backend_bases.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
from contextlib import contextmanager
4242
import importlib
4343
import io
44+
import itertools
4445
import os
4546
import sys
4647
import time
@@ -100,6 +101,12 @@
100101
}
101102

102103

104+
# Used to ensure that caching based on renderer id() is unique without being as
105+
# expensive as a real UUID. 0 is used for renderers that don't derive from
106+
# here, so start at 1.
107+
_unique_renderer_id = itertools.count(1)
108+
109+
103110
def register_backend(format, backend, description=None):
104111
"""
105112
Register a backend for saving to a given file format.
@@ -212,6 +219,10 @@ class RendererBase(object):
212219
213220
"""
214221
def __init__(self):
222+
# A lightweight id for unique-ification purposes. Along with id(self),
223+
# the combination should be unique enough to use as part of a cache key.
224+
self._uid = next(_unique_renderer_id)
225+
215226
self._texmanager = None
216227

217228
self._text2path = textpath.TextToPath()

lib/matplotlib/backends/backend_mixed.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import six
77

8+
import matplotlib.backend_bases
89
from matplotlib.backends.backend_agg import RendererAgg
910
from matplotlib.tight_bbox import process_figure_for_rasterizing
1011

@@ -49,6 +50,9 @@ def __init__(self, figure, width, height, dpi, vector_renderer,
4950
if raster_renderer_class is None:
5051
raster_renderer_class = RendererAgg
5152

53+
# See matplotlib.backend_bases.RendererBase._uid.
54+
self._uid = next(matplotlib.backend_bases._unique_renderer_id)
55+
5256
self._raster_renderer_class = raster_renderer_class
5357
self._width = width
5458
self._height = height

lib/matplotlib/tests/test_backend_pdf.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,8 @@ def test_grayscale_alpha():
178178
ax.set_yticks([])
179179

180180

181+
# This tests tends to hit a TeX cache lock on AppVeyor.
182+
@pytest.mark.flaky(reruns=3)
181183
@needs_tex
182184
def test_missing_psfont(monkeypatch):
183185
"""An error is raised if a TeX font lacks a Type-1 equivalent"""

lib/matplotlib/tests/test_backend_ps.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
reason="This test needs a TeX installation")
2828

2929

30+
# This tests tends to hit a TeX cache lock on AppVeyor.
31+
@pytest.mark.flaky(reruns=3)
3032
@pytest.mark.parametrize('format, use_log, rcParams', [
3133
('ps', False, {}),
3234
needs_ghostscript(('ps', False, {'ps.usedistiller': 'ghostscript'})),

lib/matplotlib/tests/test_mathtext.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -167,9 +167,6 @@ def baseline_images(request, fontset, index):
167167
return ['%s_%s_%02d' % (request.param, fontset, index)]
168168

169169

170-
# See #7911 for why these tests are flaky and #7107 for why they are not so
171-
# easy to fix.
172-
@pytest.mark.flaky(reruns=3)
173170
@pytest.mark.parametrize('index, test', enumerate(math_tests),
174171
ids=[str(index) for index in range(len(math_tests))])
175172
@pytest.mark.parametrize('fontset',
@@ -184,9 +181,6 @@ def test_mathtext_rendering(baseline_images, fontset, index, test):
184181
horizontalalignment='center', verticalalignment='center')
185182

186183

187-
# See #7911 for why these tests are flaky and #7107 for why they are not so
188-
# easy to fix.
189-
@pytest.mark.flaky(reruns=3)
190184
@pytest.mark.parametrize('index, test', enumerate(font_tests),
191185
ids=[str(index) for index in range(len(font_tests))])
192186
@pytest.mark.parametrize('fontset',

lib/matplotlib/tests/test_tightlayout.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def test_tight_layout3():
5858

5959

6060
@image_comparison(baseline_images=['tight_layout4'],
61-
freetype_version=('2.4.5', '2.4.9'))
61+
freetype_version=('2.5.5', '2.6.1'))
6262
def test_tight_layout4():
6363
'Test tight_layout for subplot2grid'
6464

lib/matplotlib/text.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -907,11 +907,12 @@ def get_prop_tup(self, renderer=None):
907907
need to know if the text has changed.
908908
"""
909909
x, y = self.get_unitless_position()
910+
renderer = renderer or self._renderer
910911
return (x, y, self.get_text(), self._color,
911912
self._verticalalignment, self._horizontalalignment,
912913
hash(self._fontproperties),
913914
self._rotation, self._rotation_mode,
914-
self.figure.dpi, id(renderer or self._renderer),
915+
self.figure.dpi, id(renderer), getattr(renderer, '_uid', 0),
915916
self._linespacing
916917
)
917918

0 commit comments

Comments
 (0)