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

Skip to content

Commit 0913080

Browse files
committed
TST: Properly parametrize the last mathtext tests.
1 parent 36a1617 commit 0913080

File tree

1 file changed

+31
-27
lines changed

1 file changed

+31
-27
lines changed

lib/matplotlib/tests/test_mathtext.py

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import matplotlib.pyplot as plt
1515
from matplotlib import mathtext
1616

17+
1718
math_tests = [
1819
r'$a+b+\dot s+\dot{s}+\ldots$',
1920
r'$x \doteq y$',
@@ -160,36 +161,39 @@
160161
for set in chars:
161162
font_tests.append(wrapper % set)
162163

163-
def make_set(basename, fontset, tests, extensions=None):
164-
def make_test(filename, test):
165-
@image_comparison(baseline_images=[filename], extensions=extensions)
166-
def single_test():
167-
matplotlib.rcParams['mathtext.fontset'] = fontset
168-
fig = plt.figure(figsize=(5.25, 0.75))
169-
fig.text(0.5, 0.5, test, horizontalalignment='center', verticalalignment='center')
170-
func = single_test
171-
func.__name__ = str("test_" + filename)
172-
return func
173164

174-
# We inject test functions into the global namespace, rather than
175-
# using a generator, so that individual tests can be run more
176-
# easily from the commandline and so each test will have its own
177-
# result.
178-
for i, test in enumerate(tests):
179-
filename = '%s_%s_%02d' % (basename, fontset, i)
180-
globals()['test_%s' % filename] = make_test(filename, test)
165+
@pytest.fixture
166+
def baseline_images(request, fontset, index):
167+
return ['%s_%s_%02d' % (request.param, fontset, index)]
168+
169+
170+
@pytest.mark.parametrize('index, test', enumerate(math_tests),
171+
ids=[str(index) for index in range(len(math_tests))])
172+
@pytest.mark.parametrize('fontset',
173+
['cm', 'stix', 'stixsans', 'dejavusans',
174+
'dejavuserif'])
175+
@pytest.mark.parametrize('baseline_images', ['mathtext'], indirect=True)
176+
@image_comparison(baseline_images=None)
177+
def test_mathtext_rendering(baseline_images, fontset, index, test):
178+
matplotlib.rcParams['mathtext.fontset'] = fontset
179+
fig = plt.figure(figsize=(5.25, 0.75))
180+
fig.text(0.5, 0.5, test,
181+
horizontalalignment='center', verticalalignment='center')
182+
181183

182-
make_set('mathtext', 'cm', math_tests)
183-
make_set('mathtext', 'stix', math_tests)
184-
make_set('mathtext', 'stixsans', math_tests)
185-
make_set('mathtext', 'dejavusans', math_tests)
186-
make_set('mathtext', 'dejavuserif', math_tests)
184+
@pytest.mark.parametrize('index, test', enumerate(font_tests),
185+
ids=[str(index) for index in range(len(font_tests))])
186+
@pytest.mark.parametrize('fontset',
187+
['cm', 'stix', 'stixsans', 'dejavusans',
188+
'dejavuserif'])
189+
@pytest.mark.parametrize('baseline_images', ['mathfont'], indirect=True)
190+
@image_comparison(baseline_images=None, extensions=['png'])
191+
def test_mathfont_rendering(baseline_images, fontset, index, test):
192+
matplotlib.rcParams['mathtext.fontset'] = fontset
193+
fig = plt.figure(figsize=(5.25, 0.75))
194+
fig.text(0.5, 0.5, test,
195+
horizontalalignment='center', verticalalignment='center')
187196

188-
make_set('mathfont', 'cm', font_tests, ['png'])
189-
make_set('mathfont', 'stix', font_tests, ['png'])
190-
make_set('mathfont', 'stixsans', font_tests, ['png'])
191-
make_set('mathfont', 'dejavusans', font_tests, ['png'])
192-
make_set('mathfont', 'dejavuserif', font_tests, ['png'])
193197

194198
def test_fontinfo():
195199
import matplotlib.font_manager as font_manager

0 commit comments

Comments
 (0)