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

Skip to content

Make image_comparison more pytest-y #8380

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Apr 16, 2017
Prev Previous commit
Next Next commit
TST: Properly parametrize the last mathtext tests.
  • Loading branch information
QuLogic committed Apr 15, 2017
commit 3810c2a19cbe16ccc0f20a21adf5b350cea58504
58 changes: 31 additions & 27 deletions lib/matplotlib/tests/test_mathtext.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import matplotlib.pyplot as plt
from matplotlib import mathtext


math_tests = [
r'$a+b+\dot s+\dot{s}+\ldots$',
r'$x \doteq y$',
Expand Down Expand Up @@ -160,36 +161,39 @@
for set in chars:
font_tests.append(wrapper % set)

def make_set(basename, fontset, tests, extensions=None):
def make_test(filename, test):
@image_comparison(baseline_images=[filename], extensions=extensions)
def single_test():
matplotlib.rcParams['mathtext.fontset'] = fontset
fig = plt.figure(figsize=(5.25, 0.75))
fig.text(0.5, 0.5, test, horizontalalignment='center', verticalalignment='center')
func = single_test
func.__name__ = str("test_" + filename)
return func

# We inject test functions into the global namespace, rather than
# using a generator, so that individual tests can be run more
# easily from the commandline and so each test will have its own
# result.
for i, test in enumerate(tests):
filename = '%s_%s_%02d' % (basename, fontset, i)
globals()['test_%s' % filename] = make_test(filename, test)
@pytest.fixture
def baseline_images(request, fontset, index):
return ['%s_%s_%02d' % (request.param, fontset, index)]


@pytest.mark.parametrize('index, test', enumerate(math_tests),
ids=[str(index) for index in range(len(math_tests))])
@pytest.mark.parametrize('fontset',
['cm', 'stix', 'stixsans', 'dejavusans',
'dejavuserif'])
@pytest.mark.parametrize('baseline_images', ['mathtext'], indirect=True)
@image_comparison(baseline_images=None)
def test_mathtext_rendering(baseline_images, fontset, index, test):
matplotlib.rcParams['mathtext.fontset'] = fontset
fig = plt.figure(figsize=(5.25, 0.75))
fig.text(0.5, 0.5, test,
horizontalalignment='center', verticalalignment='center')


make_set('mathtext', 'cm', math_tests)
make_set('mathtext', 'stix', math_tests)
make_set('mathtext', 'stixsans', math_tests)
make_set('mathtext', 'dejavusans', math_tests)
make_set('mathtext', 'dejavuserif', math_tests)
@pytest.mark.parametrize('index, test', enumerate(font_tests),
ids=[str(index) for index in range(len(font_tests))])
@pytest.mark.parametrize('fontset',
['cm', 'stix', 'stixsans', 'dejavusans',
'dejavuserif'])
@pytest.mark.parametrize('baseline_images', ['mathfont'], indirect=True)
@image_comparison(baseline_images=None, extensions=['png'])
def test_mathfont_rendering(baseline_images, fontset, index, test):
matplotlib.rcParams['mathtext.fontset'] = fontset
fig = plt.figure(figsize=(5.25, 0.75))
fig.text(0.5, 0.5, test,
horizontalalignment='center', verticalalignment='center')

make_set('mathfont', 'cm', font_tests, ['png'])
make_set('mathfont', 'stix', font_tests, ['png'])
make_set('mathfont', 'stixsans', font_tests, ['png'])
make_set('mathfont', 'dejavusans', font_tests, ['png'])
make_set('mathfont', 'dejavuserif', font_tests, ['png'])

def test_fontinfo():
import matplotlib.font_manager as font_manager
Expand Down