|
14 | 14 | import matplotlib.pyplot as plt
|
15 | 15 | from matplotlib import mathtext
|
16 | 16 |
|
| 17 | + |
17 | 18 | math_tests = [
|
18 | 19 | r'$a+b+\dot s+\dot{s}+\ldots$',
|
19 | 20 | r'$x \doteq y$',
|
|
160 | 161 | for set in chars:
|
161 | 162 | font_tests.append(wrapper % set)
|
162 | 163 |
|
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 |
173 | 164 |
|
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 | + |
181 | 183 |
|
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') |
187 | 196 |
|
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']) |
193 | 197 |
|
194 | 198 | def test_fontinfo():
|
195 | 199 | import matplotlib.font_manager as font_manager
|
|
0 commit comments