8000 Test that text is located correctly with xcolor. · matplotlib/matplotlib@0e5f32b · GitHub
[go: up one dir, main page]

Skip to content

Commit 0e5f32b

Browse files
committed
Test that text is located correctly with xcolor.
1 parent b36ffda commit 0e5f32b

File tree

3 files changed

+27
-6
lines changed

3 files changed

+27
-6
lines changed

lib/matplotlib/testing/__init__.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
import locale
66
import logging
7+
import shutil
8+
import subprocess
79

810
import matplotlib as mpl
911
from matplotlib import _api
@@ -44,3 +46,9 @@ def setup():
4446
# are not necessarily the default values as specified in rcsetup.py.
4547
set_font_settings_for_testing()
4648
set_reproducibility_for_testing()
49+
50+
51+
def _has_tex_package(package):
52+
return (shutil.which("kpsewhich")
53+
and subprocess.run(["kpsewhich", f"{package}.sty"],
54+
stdout=subprocess.PIPE).returncode == 0)

lib/matplotlib/tests/test_backend_pgf.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
import matplotlib as mpl
1313
import matplotlib.pyplot as plt
14+
from matplotlib.testing import _has_tex_package
1415
from matplotlib.testing.compare import compare_images, ImageComparisonFailure
1516
from matplotlib.backends.backend_pgf import PdfPages, common_texification
1617
from matplotlib.testing.decorators import (_image_directories,
@@ -51,12 +52,6 @@ def check_for(texsystem):
5152
reason="This test needs a ghostscript installation")
5253

5354

54-
def _has_tex_package(package):
55-
return (shutil.which("kpsewhich")
56-
and subprocess.run(["kpsewhich", f"{package}.sty"],
57-
stdout=subprocess.PIPE).returncode == 0)
58-
59-
6055
def compare_figure(fname, savefig_kwargs={}, tol=0):
6156
actual = os.path.join(result_dir, fname)
6257
plt.savefig(actual, **savefig_kwargs)

lib/matplotlib/tests/test_usetex.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import pytest
33

44
import matplotlib as mpl
5+
from matplotlib.testing import _has_tex_package
56
from matplotlib.testing.decorators import check_figures_equal, image_comparison
67
import matplotlib.pyplot as plt
78

@@ -80,6 +81,23 @@ def test_minus_no_descent(fontsize):
8081
assert len({*heights.values()}) == 1
8182

8283

84+
@pytest.mark.skipif(_has_tex_package('xcolor.sty'),
85+
reason='xcolor is not available')
86+
def test_usetex_xcolor():
87+
mpl.rcParams['text.usetex'] = True
88+
89+
fig = plt.figure()
90+
t = fig.text(0.5, 0.5, "Some text 0123456789")
91+
fig.canvas.draw()
92+
pos = t.get_window_extent()
93+
94+
mpl.rcParams['text.latex.preamble'] = r'\usepackage[dvipsnames]{xcolor}'
95+
fig = plt.figure()
96+
t = fig.text(0.5, 0.5, "Some text 0123456789")
97+
fig.canvas.draw()
98+
np.testing.assert_array_equal(t.get_window_extent(), pos)
99+
100+
83101
def test_textcomp_full():
84102
plt.rcParams["text.latex.preamble"] = r"\usepackage[full]{textcomp}"
85103
fig = plt.figure()

0 commit comments

Comments
 (0)
0