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
56 changes: 20 additions & 36 deletions lib/matplotlib/tests/test_backend_ps.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,26 @@
reason="This test needs a TeX installation")


def _test_savefig_to_stringio(format='ps', use_log=False):
@pytest.mark.parametrize('format, use_log, rcParams', [
('ps', False, {}),
needs_ghostscript(('ps', False, {'ps.usedistiller': 'ghostscript'})),
needs_tex(needs_ghostscript(('ps', False, {'text.latex.unicode': True,
'text.usetex': True}))),
('eps', False, {}),
('eps', True, {'ps.useafm': True}),
needs_tex(needs_ghostscript(('eps', False, {'text.latex.unicode': True,
'text.usetex': True}))),
], ids=[
'ps',
'ps with distiller',
'ps with usetex',
'eps',
'eps afm',
'eps with usetex'
])
def test_savefig_to_stringio(format, use_log, rcParams):
matplotlib.rcParams.update(rcParams)

fig, ax = plt.subplots()
buffers = [
six.moves.StringIO(),
Expand Down Expand Up @@ -60,41 +79,6 @@ def _test_savefig_to_stringio(format='ps', use_log=False):
buffer.close()


def test_savefig_to_stringio():
_test_savefig_to_stringio()


@needs_ghostscript
def test_savefig_to_stringio_with_distiller():
matplotlib.rcParams['ps.usedistiller'] = 'ghostscript'
_test_savefig_to_stringio()


@needs_tex
@needs_ghostscript
def test_savefig_to_stringio_with_usetex():
matplotlib.rcParams['text.latex.unicode'] = True
matplotlib.rcParams['text.usetex'] = True
_test_savefig_to_stringio()


def test_savefig_to_stringio_eps():
_test_savefig_to_stringio(format='eps')


def test_savefig_to_stringio_eps_afm():
matplotlib.rcParams['ps.useafm'] = True
_test_savefig_to_stringio(format='eps', use_log=True)


@needs_tex
@needs_ghostscript
def test_savefig_to_stringio_with_usetex_eps():
matplotlib.rcParams['text.latex.unicode'] = True
matplotlib.rcParams['text.usetex'] = True
_test_savefig_to_stringio(format='eps')


def test_composite_image():
# Test that figures can be saved with and without combining multiple images
# (on a single set of axes) into a single composite image.
Expand Down
22 changes: 5 additions & 17 deletions lib/matplotlib/tests/test_colorbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
unicode_literals)

import numpy as np
import pytest

from matplotlib import rc_context
from matplotlib.testing.decorators import image_comparison
import matplotlib.pyplot as plt
Expand Down Expand Up @@ -207,7 +209,9 @@ def test_colorbar_single_scatter():
plt.colorbar(cs)


def _test_remove_from_figure(use_gridspec):
@pytest.mark.parametrize('use_gridspec', [False, True],
ids=['no gridspec', 'with gridspec'])
def test_remove_from_figure(use_gridspec):
"""
Test `remove_from_figure` with the specified ``use_gridspec`` setting
"""
Expand All @@ -224,22 +228,6 @@ def _test_remove_from_figure(use_gridspec):
assert (pre_figbox == post_figbox).all()


def test_remove_from_figure_with_gridspec():
"""
Make sure that `remove_from_figure` removes the colorbar and properly
restores the gridspec
"""
_test_remove_from_figure(True)


def test_remove_from_figure_no_gridspec():
"""
Make sure that `remove_from_figure` removes a colorbar that was created
without modifying the gridspec
"""
_test_remove_from_figure(False)


def test_colorbarbase():
# smoke test from #3805
ax = plt.gca()
Expand Down
23 changes: 11 additions & 12 deletions lib/matplotlib/tests/test_colors.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import numpy as np
import pytest

from numpy.testing import assert_equal
from numpy.testing.utils import assert_array_equal, assert_array_almost_equal

from matplotlib import cycler
Expand Down Expand Up @@ -160,25 +159,25 @@ def test_PowerNorm():
expected = [0, 0, 1/16, 1/4, 1]
pnorm = mcolors.PowerNorm(2, vmin=0, vmax=8)
assert_array_almost_equal(pnorm(a), expected)
assert_equal(pnorm(a[0]), expected[0])
assert_equal(pnorm(a[2]), expected[2])
assert pnorm(a[0]) == expected[0]
assert pnorm(a[2]) == expected[2]
assert_array_almost_equal(a[1:], pnorm.inverse(pnorm(a))[1:])

# Clip = True
a = np.array([-0.5, 0, 1, 8, 16], dtype=float)
expected = [0, 0, 0, 1, 1]
pnorm = mcolors.PowerNorm(2, vmin=2, vmax=8, clip=True)
assert_array_almost_equal(pnorm(a), expected)
assert_equal(pnorm(a[0]), expected[0])
assert_equal(pnorm(a[-1]), expected[-1])
assert pnorm(a[0]) == expected[0]
assert pnorm(a[-1]) == expected[-1]

# Clip = True at call time
a = np.array([-0.5, 0, 1, 8, 16], dtype=float)
expected = [0, 0, 0, 1, 1]
pnorm = mcolors.PowerNorm(2, vmin=2, vmax=8, clip=False)
assert_array_almost_equal(pnorm(a, clip=True), expected)
assert_equal(pnorm(a[0], clip=True), expected[0])
assert_equal(pnorm(a[-1], clip=True), expected[-1])
assert pnorm(a[0], clip=True) == expected[0]
assert pnorm(a[-1], clip=True) == expected[-1]


def test_Normalize():
Expand Down Expand Up @@ -652,14 +651,14 @@ def test_conversions():
mcolors.to_rgba_array([".2", ".5", ".8"]),
np.vstack([mcolors.to_rgba(c) for c in [".2", ".5", ".8"]]))
# alpha is properly set.
assert_equal(mcolors.to_rgba((1, 1, 1), .5), (1, 1, 1, .5))
assert_equal(mcolors.to_rgba(".1", .5), (.1, .1, .1, .5))
assert mcolors.to_rgba((1, 1, 1), .5) == (1, 1, 1, .5)
assert mcolors.to_rgba(".1", .5) == (.1, .1, .1, .5)
# builtin round differs between py2 and py3.
assert_equal(mcolors.to_hex((.7, .7, .7)), "#b2b2b2")
assert mcolors.to_hex((.7, .7, .7)) == "#b2b2b2"
# hex roundtrip.
hex_color = "#1234abcd"
assert_equal(mcolors.to_hex(mcolors.to_rgba(hex_color), keep_alpha=True),
hex_color)
assert mcolors.to_hex(mcolors.to_rgba(hex_color), keep_alpha=True) == \
hex_color


def test_grey_gray():
Expand Down
4 changes: 2 additions & 2 deletions lib/matplotlib/tests/test_compare_images.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import shutil
import warnings

from numpy.testing import assert_equal, assert_almost_equal
from numpy.testing import assert_almost_equal
import pytest

from matplotlib.testing.compare import compare_images
Expand Down Expand Up @@ -41,7 +41,7 @@ def image_comparison_expect_rms(im1, im2, tol, expect_rms):
results = compare_images(im1, im2, tol=tol, in_decorator=True)

if expect_rms is None:
assert_equal(None, results)
assert results is None
else:
assert results is not None
assert_almost_equal(expect_rms, results['rms'], decimal=4)
Expand Down
24 changes: 10 additions & 14 deletions lib/matplotlib/tests/test_dates.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
except ImportError:
import mock

from numpy.testing import assert_equal

from matplotlib.testing.decorators import image_comparison
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
Expand Down Expand Up @@ -184,16 +182,16 @@ def test_strftime_fields(dt):
minute=dt.minute,
second=dt.second,
microsecond=dt.microsecond))
assert_equal(formatter.strftime(dt), formatted_date_str)
assert formatter.strftime(dt) == formatted_date_str

try:
# Test strftime("%x") with the current locale.
import locale # Might not exist on some platforms, such as Windows
locale_formatter = mdates.DateFormatter("%x")
locale_d_fmt = locale.nl_langinfo(locale.D_FMT)
expanded_formatter = mdates.DateFormatter(locale_d_fmt)
assert_equal(locale_formatter.strftime(dt),
expanded_formatter.strftime(dt))
assert locale_formatter.strftime(dt) == \
expanded_formatter.strftime(dt)
except (ImportError, AttributeError):
pass

Expand All @@ -211,8 +209,7 @@ def test_date_formatter_callable():

formatter = mdates.AutoDateFormatter(locator)
formatter.scaled[-10] = callable_formatting_function
assert_equal(formatter([datetime.datetime(2014, 12, 25)]),
['25-12//2014'])
assert formatter([datetime.datetime(2014, 12, 25)]) == ['25-12//2014']


def test_drange():
Expand All @@ -225,12 +222,12 @@ def test_drange():
delta = datetime.timedelta(hours=1)
# We expect 24 values in drange(start, end, delta), because drange returns
# dates from an half open interval [start, end)
assert_equal(24, len(mdates.drange(start, end, delta)))
assert len(mdates.drange(start, end, delta)) == 24

# if end is a little bit later, we expect the range to contain one element
# more
end = end + datetime.timedelta(microseconds=1)
assert_equal(25, len(mdates.drange(start, end, delta)))
assert len(mdates.drange(start, end, delta)) == 25

# reset end
end = datetime.datetime(2011, 1, 2, tzinfo=mdates.UTC)
Expand All @@ -239,8 +236,8 @@ def test_drange():
# 4 hours = 1/6 day, this is an "dangerous" float
delta = datetime.timedelta(hours=4)
daterange = mdates.drange(start, end, delta)
assert_equal(6, len(daterange))
assert_equal(mdates.num2date(daterange[-1]), end - delta)
assert len(daterange) == 6
assert mdates.num2date(daterange[-1]) == (end - delta)


def test_empty_date_with_year_formatter():
Expand Down Expand Up @@ -331,8 +328,7 @@ def _create_auto_date_locator(date1, date2):
for t_delta, expected in results:
d2 = d1 + t_delta
locator = _create_auto_date_locator(d1, d2)
assert_equal(list(map(str, mdates.num2date(locator()))),
expected)
assert list(map(str, mdates.num2date(locator()))) == expected


@image_comparison(baseline_images=['date_inverted_limit'],
Expand Down Expand Up @@ -368,7 +364,7 @@ def _test_date2num_dst(date_range, tz_convert):
expected_ordinalf = [735322.0 + (i * interval_days) for i in range(N)]
actual_ordinalf = list(mdates.date2num(dt_bxl))

assert_equal(actual_ordinalf, expected_ordinalf)
assert actual_ordinalf == expected_ordinalf


def test_date2num_dst():
Expand Down
Loading
X Tutup