X Tutup
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions lib/matplotlib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1482,27 +1482,19 @@ def _jupyter_nbextension_paths():
'matplotlib.tests.test_backend_qt5',
'matplotlib.tests.test_backend_svg',
'matplotlib.tests.test_coding_standards',
'matplotlib.tests.test_dviread',
'matplotlib.tests.test_figure',
'matplotlib.tests.test_font_manager',
'matplotlib.tests.test_gridspec',
'matplotlib.tests.test_image',
'matplotlib.tests.test_legend',
'matplotlib.tests.test_lines',
'matplotlib.tests.test_mathtext',
'matplotlib.tests.test_offsetbox',
'matplotlib.tests.test_patches',
'matplotlib.tests.test_path',
'matplotlib.tests.test_patheffects',
'matplotlib.tests.test_pickle',
'matplotlib.tests.test_png',
'matplotlib.tests.test_quiver',
'matplotlib.tests.test_text',
'matplotlib.tests.test_texmanager',
'matplotlib.tests.test_type1font',
'matplotlib.tests.test_ttconv',
'matplotlib.tests.test_units',
'matplotlib.tests.test_usetex',
'matplotlib.tests.test_widgets',
'matplotlib.tests.test_cycles',
'matplotlib.tests.test_preprocess_data',
Expand Down
48 changes: 18 additions & 30 deletions lib/matplotlib/tests/test_dviread.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,14 @@
import six
from matplotlib.testing.decorators import skip_if_command_unavailable


from nose.tools import assert_equal, with_setup
import matplotlib.dviread as dr
import os.path
import json


original_find_tex_file = dr.find_tex_file


def setup_PsfontsMap():
dr.find_tex_file = lambda x: x


def teardown_PsfontsMap():
dr.find_tex_file = original_find_tex_file

def test_PsfontsMap(monkeypatch):
monkeypatch.setattr(dr, 'find_tex_file', lambda x: x)

@with_setup(setup_PsfontsMap, teardown_PsfontsMap)
def test_PsfontsMap():
filename = os.path.join(
os.path.dirname(__file__),
'baseline_images', 'dviread', 'test.map')
Expand All @@ -32,34 +20,34 @@ def test_PsfontsMap():
for n in [1, 2, 3, 4, 5]:
key = 'TeXfont%d' % n
entry = fontmap[key]
assert_equal(entry.texname, key)
assert_equal(entry.psname, 'PSfont%d' % n)
assert entry.texname == key
assert entry.psname == 'PSfont%d' % n
if n not in [3, 5]:
assert_equal(entry.encoding, 'font%d.enc' % n)
assert entry.encoding == 'font%d.enc' % n
elif n == 3:
assert_equal(entry.encoding, 'enc3.foo')
assert entry.encoding == 'enc3.foo'
# We don't care about the encoding of TeXfont5, which specifies
# multiple encodings.
if n not in [1, 5]:
assert_equal(entry.filename, 'font%d.pfa' % n)
assert entry.filename == 'font%d.pfa' % n
else:
assert_equal(entry.filename, 'font%d.pfb' % n)
assert entry.filename == 'font%d.pfb' % n
if n == 4:
assert_equal(entry.effects, {'slant': -0.1, 'extend': 2.2})
assert entry.effects == {'slant': -0.1, 'extend': 2.2}
else:
assert_equal(entry.effects, {})
assert entry.effects == {}
# Some special cases
entry = fontmap['TeXfont6']
assert_equal(entry.filename, None)
assert_equal(entry.encoding, None)
assert entry.filename is None
assert entry.encoding is None
entry = fontmap['TeXfont7']
assert_equal(entry.filename, None)
assert_equal(entry.encoding, 'font7.enc')
assert entry.filename is None
assert entry.encoding == 'font7.enc'
entry = fontmap['TeXfont8']
assert_equal(entry.filename, 'font8.pfb')
assert_equal(entry.encoding, None)
assert entry.filename == 'font8.pfb'
assert entry.encoding is None
entry = fontmap['TeXfont9']
assert_equal(entry.filename, '/absolute/font9.pfb')
assert entry.filename == '/absolute/font9.pfb'


@skip_if_command_unavailable(["kpsewhich", "-version"])
Expand All @@ -75,4 +63,4 @@ def test_dviread():
for t in page.text],
'boxes': [[b.x, b.y, b.height, b.width] for b in page.boxes]}
for page in dvi]
assert_equal(data, correct)
assert data == correct
7 changes: 3 additions & 4 deletions lib/matplotlib/tests/test_font_manager.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from __future__ import (absolute_import, division, print_function,
unicode_literals)

from nose.tools import assert_equal
import six

import os
Expand All @@ -24,7 +23,7 @@ def test_font_priority():
['cmmi10', 'Bitstream Vera Sans']}):
font = findfont(
FontProperties(family=["sans-serif"]))
assert_equal(os.path.basename(font), 'cmmi10.ttf')
assert os.path.basename(font) == 'cmmi10.ttf'

# Smoketest get_charmap, which isn't used internally anymore
font = get_font(font)
Expand All @@ -51,8 +50,8 @@ def test_json_serialization():
{'family': 'Bitstream Vera Sans', 'weight': 700},
{'family': 'no such font family'}):
fp = FontProperties(**prop)
assert_equal(fontManager.findfont(fp, rebuild_if_missing=False),
copy.findfont(fp, rebuild_if_missing=False))
assert (fontManager.findfont(fp, rebuild_if_missing=False) ==
copy.findfont(fp, rebuild_if_missing=False))


def test_otf():
Expand Down
59 changes: 39 additions & 20 deletions lib/matplotlib/tests/test_mathtext.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@
import six

import io
import re

import numpy as np
import pytest

import matplotlib
from matplotlib.testing.decorators import image_comparison, knownfailureif, cleanup
import matplotlib.pyplot as plt
Expand Down Expand Up @@ -195,8 +198,10 @@ def test_fontinfo():
table = font.get_sfnt_table("head")
assert table['version'] == (1, 0)

def test_mathtext_exceptions():
errors = [

@pytest.mark.parametrize(
'math, msg',
[
(r'$\hspace{}$', r'Expected \hspace{n}'),
(r'$\hspace{foo}$', r'Expected \hspace{n}'),
(r'$\frac$', r'Expected \frac{num}{den}'),
Expand All @@ -205,28 +210,47 @@ def test_mathtext_exceptions():
(r'$\stackrel{}{}$', r'Expected \stackrel{num}{den}'),
(r'$\binom$', r'Expected \binom{num}{den}'),
(r'$\binom{}{}$', r'Expected \binom{num}{den}'),
(r'$\genfrac$', r'Expected \genfrac{ldelim}{rdelim}{rulesize}{style}{num}{den}'),
(r'$\genfrac{}{}{}{}{}{}$', r'Expected \genfrac{ldelim}{rdelim}{rulesize}{style}{num}{den}'),
(r'$\genfrac$',
r'Expected \genfrac{ldelim}{rdelim}{rulesize}{style}{num}{den}'),
(r'$\genfrac{}{}{}{}{}{}$',
r'Expected \genfrac{ldelim}{rdelim}{rulesize}{style}{num}{den}'),
(r'$\sqrt$', r'Expected \sqrt{value}'),
(r'$\sqrt f$', r'Expected \sqrt{value}'),
(r'$\overline$', r'Expected \overline{value}'),
(r'$\overline{}$', r'Expected \overline{value}'),
(r'$\leftF$', r'Expected a delimiter'),
(r'$\rightF$', r'Unknown symbol: \rightF'),
(r'$\left(\right$', r'Expected a delimiter'),
(r'$\left($', r'Expected "\right"')
]

(r'$\left($', r'Expected "\right"'),
],
ids=[
'hspace without value',
'hspace with invalid value',
'frac without parameters',
'frac with empty parameters',
'stackrel without parameters',
'stackrel with empty parameters',
'binom without parameters',
'binom with empty parameters',
'genfrac without parameters',
'genfrac with empty parameters',
'sqrt without parameters',
'sqrt with invalid value',
'overline without parameters',
'overline with empty parameter',
'left with invalid delimiter',
'right with invalid delimiter',
'unclosed parentheses with sizing',
'unclosed parentheses without sizing',
]
)
def test_mathtext_exceptions(math, msg):
parser = mathtext.MathTextParser('agg')

for math, msg in errors:
try:
parser.parse(math)
except ValueError as e:
exc = str(e).split('\n')
assert exc[3].startswith(msg)
else:
assert False, "Expected '%s', but didn't get it" % msg
with pytest.raises(ValueError) as excinfo:
parser.parse(math)
excinfo.match(re.escape(msg))


@cleanup
def test_single_minus_sign():
Expand All @@ -243,8 +267,3 @@ def test_single_minus_sign():

# If this fails, it would be all white
assert not np.all(array == 0xff)


if __name__ == '__main__':
import nose
nose.runmodule(argv=['-s', '--with-doctest'], exit=False)
4 changes: 2 additions & 2 deletions lib/matplotlib/tests/test_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import numpy as np
from numpy.testing import assert_almost_equal
from nose.tools import eq_, assert_raises
import pytest

from matplotlib.transforms import Bbox
import matplotlib
Expand Down Expand Up @@ -286,7 +286,7 @@ def test_get_rotation_int():

def test_get_rotation_raises():
from matplotlib import text
with assert_raises(ValueError):
with pytest.raises(ValueError):
text.get_rotation('hozirontal')


Expand Down
15 changes: 7 additions & 8 deletions lib/matplotlib/tests/test_type1font.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

import six

from nose.tools import assert_equal, assert_in
import matplotlib.type1font as t1f
import os.path
import difflib
Expand All @@ -16,11 +15,11 @@ def test_Type1Font():
condensed = font.transform({'extend': 0.5})
with open(filename, 'rb') as fd:
rawdata = fd.read()
assert_equal(font.parts[0], rawdata[0x0006:0x10c5])
assert_equal(font.parts[1], rawdata[0x10cb:0x897f])
assert_equal(font.parts[2], rawdata[0x8985:0x8ba6])
assert_equal(font.parts[1:], slanted.parts[1:])
assert_equal(font.parts[1:], condensed.parts[1:])
assert font.parts[0] == rawdata[0x0006:0x10c5]
assert font.parts[1] == rawdata[0x10cb:0x897f]
assert font.parts[2] == rawdata[0x8985:0x8ba6]
assert font.parts[1:] == slanted.parts[1:]
assert font.parts[1:] == condensed.parts[1:]

differ = difflib.Differ()
diff = list(differ.compare(
Expand All @@ -39,7 +38,7 @@ def test_Type1Font():
# Alters ItalicAngle
'- /ItalicAngle 0 def',
'+ /ItalicAngle -45.0 def'):
assert_in(line, diff, 'diff to slanted font must contain %s' % line)
assert line in diff, 'diff to slanted font must contain %s' % line

diff = list(differ.compare(font.parts[0].decode('latin-1').splitlines(),
condensed.parts[0].decode('latin-1').splitlines()))
Expand All @@ -53,4 +52,4 @@ def test_Type1Font():
# Alters FontMatrix
'- /FontMatrix [0.001 0 0 0.001 0 0 ]readonly def',
'+ /FontMatrix [0.0005 0.0 0.0 0.001 0.0 0.0]readonly def'):
assert_in(line, diff, 'diff to condensed font must contain %s' % line)
assert line in diff, 'diff to condensed font must contain %s' % line
8 changes: 4 additions & 4 deletions lib/matplotlib/tests/test_usetex.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
from __future__ import (absolute_import, division, print_function,
unicode_literals)

import pytest

import matplotlib
from matplotlib.testing.decorators import image_comparison
from matplotlib.compat.subprocess import check_output
import matplotlib.pyplot as plt


@pytest.mark.skipif(not matplotlib.checkdep_usetex(True),
reason='Missing TeX or Ghostscript or dvipng')
@image_comparison(baseline_images=['test_usetex'],
extensions=['pdf', 'png'],
tol=0.3)
def test_usetex():
canusetex = matplotlib.checkdep_usetex(True)
if not canusetex:
from nose import SkipTest
raise SkipTest('Cannot run usetex_test')
matplotlib.rcParams['text.usetex'] = True
fig = plt.figure()
ax = fig.add_subplot(111)
Expand Down
X Tutup