8000 TST: skip test_dviread if kpsewhich is not available · matplotlib/matplotlib@75ae5b5 · GitHub
[go: up one dir, main page]

Skip to content

Commit 75ae5b5

Browse files
jankatinsmatthew-brett
authored andcommitted
TST: skip test_dviread if kpsewhich is not available
Also fix the docstring to mention that it is part of miktex...
1 parent 5b2558f commit 75ae5b5

File tree

3 files changed

+41
-2
lines changed

3 files changed

+41
-2
lines changed

lib/matplotlib/dviread.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -844,8 +844,8 @@ def find_tex_file(filename, format=None):
844844
`--format` option.
845845
846846
Apparently most existing TeX distributions on Unix-like systems
847-
use kpathsea. I hear MikTeX (a popular distribution on Windows)
848-
doesn't use kpathsea, so what do we do? (TODO)
847+
use kpathsea. It's also available as part of MikTeX, a popular
848+
distribution on Windows.
849849
850850
.. seealso::
851851

lib/matplotlib/testing/decorators.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,3 +431,24 @@ def backend_switcher(*args, **kwargs):
431431

432432
return nose.tools.make_decorator(func)(backend_switcher)
433433
return switch_backend_decorator
434+
435+
436+
def skip_if_command_unavailable(cmd):
437+
"""
438+
skips a test if a command is unavailable.
439+
440+
Parameters
441+
----------
442+
cmd : list of str
443+
must be a complete command which should not
444+
return a non zero exit code, something like
445+
["latex", "-version"]
446+
"""
447+
from matplotlib.compat.subprocess import check_output
448+
try:
449+
check_output(cmd)
450+
except:
451+
from nose import SkipTest
452+
raise SkipTest('missing command: %s' % cmd[0])
453+
454+
return lambda f: f

lib/matplotlib/tests/test_dviread.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
unicode_literals)
33

44
import six
5+
from matplotlib.testing.decorators import skip_if_command_unavailable
6+
57

68
from nose.tools import assert_equal
79
import matplotlib.dviread as dr
@@ -52,3 +54,19 @@ def test_PsfontsMap():
5254
assert_equal(entry.encoding, None)
5355
entry = fontmap['TeXfont9']
5456
assert_equal(entry.filename, '/absolute/font9.pfb')
57+
58+
59+
@skip_if_command_unavailable(["kpsewhich", "-version"])
60+
def test_dviread():
61+
dir = os.path.join(os.path.dirname(__file__), 'baseline_images', 'dviread')
62+
with open(os.path.join(dir, 'test.json')) as f:
63+
correct = json.load(f)
64+
with dr.Dvi(os.path.join(dir, 'test.dvi'), None) as dvi:
65+
data = [{'text': [[t.x, t.y,
66+
six.unichr(t.glyph),
67+
six.text_type(t.font.texname),
68+
round(t.font.size, 2)]
69+
for t in page.text],
70+
'boxes': [[b.x, b.y, b.height, b.width] for b in page.boxes]}
71+
for page in dvi]
72+
assert_equal(data, correct)

0 commit comments

Comments
 (0)
0