From 29715635b5be5e93103f03e61f9fe9be47938fa2 Mon Sep 17 00:00:00 2001 From: Antony Lee Date: Sat, 9 Jan 2021 13:45:46 +0100 Subject: [PATCH 1/3] Use simpler approach to skip previously-removed mathtext tests. Just pytest.skip()ping them in the baseline_images fixture will avoid having to duplicate the logic in the upcoming png-only tests. --- lib/matplotlib/tests/test_mathtext.py | 35 ++++++++++++--------------- 1 file changed, 15 insertions(+), 20 deletions(-) diff --git a/lib/matplotlib/tests/test_mathtext.py b/lib/matplotlib/tests/test_mathtext.py index 8c5250ac5021..016ba930c86a 100644 --- a/lib/matplotlib/tests/test_mathtext.py +++ b/lib/matplotlib/tests/test_mathtext.py @@ -165,42 +165,37 @@ for set in chars: font_tests.append(wrapper % set) -font_tests = list(filter(lambda x: x[1] is not None, enumerate(font_tests))) - @pytest.fixture -def baseline_images(request, fontset, index): +def baseline_images(request, fontset, index, text): + if text is None: + pytest.skip("test has been removed") return ['%s_%s_%02d' % (request.param, fontset, index)] -cur_math_tests = list(filter(lambda x: x[1] is not None, enumerate(math_tests))) - - -@pytest.mark.parametrize('index, test', cur_math_tests, - ids=[str(index) for index, _ in cur_math_tests]) -@pytest.mark.parametrize('fontset', - ['cm', 'stix', 'stixsans', 'dejavusans', - 'dejavuserif']) +@pytest.mark.parametrize( + 'index, text', enumerate(math_tests), ids=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): +def test_mathtext_rendering(baseline_images, fontset, index, text): mpl.rcParams['mathtext.fontset'] = fontset fig = plt.figure(figsize=(5.25, 0.75)) - fig.text(0.5, 0.5, test, + fig.text(0.5, 0.5, text, horizontalalignment='center', verticalalignment='center') -@pytest.mark.parametrize('index, test', font_tests, - ids=[str(index) for index, _ in font_tests]) -@pytest.mark.parametrize('fontset', - ['cm', 'stix', 'stixsans', 'dejavusans', - 'dejavuserif']) +@pytest.mark.parametrize( + 'index, text', enumerate(font_tests), ids=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): +def test_mathfont_rendering(baseline_images, fontset, index, text): mpl.rcParams['mathtext.fontset'] = fontset fig = plt.figure(figsize=(5.25, 0.75)) - fig.text(0.5, 0.5, test, + fig.text(0.5, 0.5, text, horizontalalignment='center', verticalalignment='center') From d6687ce6156c11453740305d30a9d534214a2efd Mon Sep 17 00:00:00 2001 From: Antony Lee Date: Fri, 8 Jan 2021 20:22:07 +0100 Subject: [PATCH 2/3] Add machinery for png-only, single-font mathtext tests. (For the sqrt test added below, each font adds ~2k to the size of the baseline image file.) --- lib/matplotlib/tests/test_mathtext.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/lib/matplotlib/tests/test_mathtext.py b/lib/matplotlib/tests/test_mathtext.py index 016ba930c86a..45da6ac81cfc 100644 --- a/lib/matplotlib/tests/test_mathtext.py +++ b/lib/matplotlib/tests/test_mathtext.py @@ -110,6 +110,11 @@ r'$\left(X\right)_{a}^{b}$', # github issue 7615 r'$\dfrac{\$100.00}{y}$', # github issue #1888 ] +# 'Lightweight' tests test only a single fontset (dejavusans, which is the +# default) and only png outputs, in order to minimize the size of baseline +# images. +lightweight_math_tests = [ +] digits = "0123456789" uppercase = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" @@ -186,6 +191,17 @@ def test_mathtext_rendering(baseline_images, fontset, index, text): horizontalalignment='center', verticalalignment='center') +@pytest.mark.parametrize('index, text', enumerate(lightweight_math_tests), + ids=range(len(lightweight_math_tests))) +@pytest.mark.parametrize('fontset', ['dejavusans']) +@pytest.mark.parametrize('baseline_images', ['mathtext1'], indirect=True) +@image_comparison(baseline_images=None, extensions=['png']) +def test_mathtext_rendering_lightweight(baseline_images, fontset, index, text): + fig = plt.figure(figsize=(5.25, 0.75)) + fig.text(0.5, 0.5, text, math_fontfamily=fontset, + horizontalalignment='center', verticalalignment='center') + + @pytest.mark.parametrize( 'index, text', enumerate(font_tests), ids=range(len(font_tests))) @pytest.mark.parametrize( From 7f7fad9de6c1c915f0219af82bdb36fb339e8e8e Mon Sep 17 00:00:00 2001 From: Antony Lee Date: Tue, 5 Jan 2021 07:24:03 +0100 Subject: [PATCH 3/3] Support \sqrt[not-a-number]{...}. --- lib/matplotlib/_mathtext.py | 7 ++++--- .../test_mathtext/mathtext1_dejavusans_00.png | Bin 0 -> 1895 bytes lib/matplotlib/tests/test_mathtext.py | 1 + 3 files changed, 5 insertions(+), 3 deletions(-) create mode 100644 lib/matplotlib/tests/baseline_images/test_mathtext/mathtext1_dejavusans_00.png diff --git a/lib/matplotlib/_mathtext.py b/lib/matplotlib/_mathtext.py index 96a69919c86b..45e51f53984d 100644 --- a/lib/matplotlib/_mathtext.py +++ b/lib/matplotlib/_mathtext.py @@ -2158,7 +2158,8 @@ def __init__(self): p.sqrt <<= Group( Suppress(Literal(r"\sqrt")) - - ((Optional(p.lbracket + p.int_literal + p.rbracket, default=None) + - ((Group(Optional( + p.lbracket + OneOrMore(~p.rbracket + p.token) + p.rbracket)) + p.required_group) | Error("Expected \\sqrt{value}")) ) @@ -2864,10 +2865,10 @@ def sqrt(self, s, loc, toks): # Add the root and shift it upward so it is above the tick. # The value of 0.6 is a hard-coded hack ;) - if root is None: + if not root: root = Box(check.width * 0.5, 0., 0.) else: - root = Hlist([Char(x, state) for x in root]) + root = Hlist(root) root.shrink() root.shrink() diff --git a/lib/matplotlib/tests/baseline_images/test_mathtext/mathtext1_dejavusans_00.png b/lib/matplotlib/tests/baseline_images/test_mathtext/mathtext1_dejavusans_00.png new file mode 100644 index 0000000000000000000000000000000000000000..4cc6978860e35af2d70f37832c259de2ee6de7ea GIT binary patch literal 1895 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H`W#s6hjUP9L|jL(=xS18%$=~X}N$WJw1L&Nev4L z!NE7lRe=tIQ9hrKYfM}qlSp~13!~VHo+tSS3LwaahbhjN*1fmyhQD$Aj|(u}n+C)e z+IKn}IkGX&i))nQ=6^Oq6n2+t8KWcO;=E}z8n)@`@^Axd=KcF;5OID10p;oGstVZy zM$Zcs36`gBnx?jWyS1}(aN@$q^X@`aL2)sL-U&A{>hHK}{CsFgn7lS0IX~QhExyX* zd3$(VIb@KXm6i1aRQuZSr&~*(sbIY^p14gXq>?O(l|QsB8>pC@n>+0I7J7AIwXX;J z`)^C7rxE9x*0~DE%}Ytm=bBSC$no*cK!rXtSRoELgoA?>3qvHOe{Agb zxz<#~`_}XGo12??KSOS1W@JPxj5G_&%f0Dz!HuG#=flHuGAsr|Y2+xDnn!BGb0#Jy z>)7u}#FFE|o@KtJrKJZ^D1Q!T^(VY0_&h%D=>iTSk>sc-A&Epvbu!$u$D**?VImnq z{styV{3Ggo^#QM2SB~y6HWpP^BS&W+JvwpIk=0=c&(qV_FKueVz??7og@%TwWqke}!__ZSw$5x$|Zjlp-Lw Ldg7~3grxroN7qN? literal 0 HcmV?d00001 diff --git a/lib/matplotlib/tests/test_mathtext.py b/lib/matplotlib/tests/test_mathtext.py index 45da6ac81cfc..30f3b2ce4262 100644 --- a/lib/matplotlib/tests/test_mathtext.py +++ b/lib/matplotlib/tests/test_mathtext.py @@ -114,6 +114,7 @@ # default) and only png outputs, in order to minimize the size of baseline # images. lightweight_math_tests = [ + r'$\sqrt[ab]{123}$', # github issue #8665 ] digits = "0123456789"