Skip to content

Commit

Permalink
add mpl testing
Browse files Browse the repository at this point in the history
  • Loading branch information
bendichter committed Feb 20, 2024
1 parent 6e722c2 commit a58c27e
Show file tree
Hide file tree
Showing 16 changed files with 62 additions and 19 deletions.
3 changes: 3 additions & 0 deletions requirements-test.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pytest>=6.0
pytest-mpl==0.17.0
pytest-cov
17 changes: 8 additions & 9 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from setuptools import setup, find_packages
from setuptools import setup
# To use a consistent encoding
from codecs import open
from os import path
Expand All @@ -24,14 +24,14 @@
'Topic :: Scientific/Engineering',
'Framework :: Matplotlib',
'License :: OSI Approved :: MIT License',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7'
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
'Programming Language :: Python :: 3.11',
'Programming Language :: Python :: 3.12',
],

keywords='data visualization',

#packages=find_packages(exclude=['docs']),
py_modules=["brokenaxes"],

# List run-time dependencies here. These will be installed by pip when
Expand All @@ -43,10 +43,9 @@
# List additional groups of dependencies here (e.g. development
# dependencies). You can install these using the following syntax,
# for example:
# $ pip install -e .[dev,test]
# $ pip install -e .[test]
extras_require={
# 'dev': ['check-manifest'],
'test': ['pytest'],
'test': ['pytest>=6.0', 'pytest-cov', 'pytest-mpl'],
},


Expand Down
61 changes: 51 additions & 10 deletions test.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
from brokenaxes import brokenaxes


np.random.seed(42)


@pytest.mark.mpl_image_compare
def test_standard():
fig = plt.figure(figsize=(5, 2))
bax = brokenaxes(
Expand All @@ -20,8 +24,10 @@ def test_standard():
bax.legend(loc=3)
bax.set_xlabel("time")
bax.set_ylabel("value")
return fig


@pytest.mark.mpl_image_compare
def test_subplots():
sps1, sps2 = GridSpec(2, 1)

Expand All @@ -33,7 +39,10 @@ def test_subplots():
bax = brokenaxes(xlims=((0, 2.5), (3, 6)), subplot_spec=sps2)
bax.hist(x, histtype="bar")

return bax.fig


@pytest.mark.mpl_image_compare
def test_log():
fig = plt.figure(figsize=(5, 5))
bax = brokenaxes(
Expand All @@ -53,7 +62,10 @@ def test_log():
bax.set_xlabel("x")
bax.set_ylabel("y")

return fig


@pytest.mark.mpl_image_compare
def test_datetime():
fig = plt.figure(figsize=(5, 5))
xx = [datetime.datetime(2020, 1, x) for x in range(1, 20)]
Expand All @@ -79,7 +91,10 @@ def test_datetime():
[x.remove() for x in bax.diag_handles]
bax.draw_diags()

return fig


@pytest.mark.mpl_image_compare
def test_datetime_y():
fig = plt.figure(figsize=(5, 5))
yy = [datetime.datetime(2020, 1, x) for x in range(1, 20)]
Expand All @@ -103,7 +118,10 @@ def test_datetime_y():

bax.draw_diags()

return fig


@pytest.mark.mpl_image_compare
def test_legend():
fig = plt.figure(figsize=(5, 2))
bax = brokenaxes(
Expand All @@ -114,51 +132,61 @@ def test_legend():
h2 = bax.plot(x, np.cos(10 * x), label="cos")
bax.legend(handles=[h1[0][0], h2[0][0]], labels=["1", "2"])

return fig


@pytest.mark.mpl_image_compare
def test_text():
bax = brokenaxes(
xlims=((0, 0.1), (0.4, 0.7)), ylims=((-1, 0.7), (0.79, 1)), hspace=0.05
)
bax.text(0.5, 0.5, "hello")


def test_text_error():
bax = brokenaxes(
xlims=((0, 0.1), (0.4, 0.7)), ylims=((-1, 0.7), (0.79, 1)), hspace=0.05
)
with pytest.raises(ValueError):
bax.text(-11, -11, "hello")
return bax.fig


@pytest.mark.mpl_image_compare
def test_lims_arrays():
lims = np.arange(6).reshape((-1,2))
brokenaxes(xlims=lims, ylims=lims)

return plt.gcf()


@pytest.mark.mpl_image_compare
def test_pass_fig():
fig = plt.figure(figsize=(5, 2))
bax = brokenaxes(
xlims=((0, 0.1), (0.4, 0.7)), ylims=((-1, 0.7), (0.79, 1)), hspace=0.05, fig=fig
)
assert bax.fig is fig

return fig


@pytest.mark.mpl_image_compare
def test_despine():
fig = plt.figure(figsize=(5, 2))
bax = brokenaxes(
xlims=((0, 0.1), (0.4, 0.7)), ylims=((-1, 0.7), (0.79, 1)), hspace=0.05, despine=False,
)
assert bax.despine is False

return fig


@pytest.mark.mpl_image_compare
def test_set_title():
fig = plt.figure(figsize=(5, 2))
bax = brokenaxes(
xlims=((0, 0.1), (0.4, 0.7)), ylims=((-1, 0.7), (0.79, 1)), hspace=0.05
)
bax.set_title("title")

return fig


@pytest.mark.mpl_image_compare
def test_secondary_axes():

fig = plt.figure(figsize=(5, 2))
Expand All @@ -171,6 +199,19 @@ def test_secondary_axes():
bax.secondary_yaxis("left", label="left")
bax.secondary_yaxis("right")

return fig


@pytest.mark.mpl_image_compare
def test_draw_diags():
fig = plt.figure(figsize=(5, 2))
bax = brokenaxes(
xlims=((0, 0.1), (0.4, 0.7)), ylims=((-1, 0.7), (0.79, 1)), hspace=0.05
)
bax.draw_diags(tilt=90, d=.05)

return fig


def test_get_axis_special():
fig = plt.figure(figsize=(5, 2))
Expand All @@ -183,9 +224,9 @@ def test_get_axis_special():
assert isinstance(bax.get_shared_y_axes(), mpl.cbook.GrouperView)


def test_draw_diags():
fig = plt.figure(figsize=(5, 2))
def test_text_error():
bax = brokenaxes(
xlims=((0, 0.1), (0.4, 0.7)), ylims=((-1, 0.7), (0.79, 1)), hspace=0.05
)
bax.draw_diags(tilt=90, d=.05)
with pytest.raises(ValueError):
bax.text(-11, -11, "hello")
Binary file added test_baseline/test_datetime.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test_baseline/test_datetime_y.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test_baseline/test_despine.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test_baseline/test_draw_diags.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test_baseline/test_legend.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test_baseline/test_lims_arrays.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test_baseline/test_log.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test_baseline/test_pass_fig.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test_baseline/test_secondary_axes.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test_baseline/test_set_title.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test_baseline/test_standard.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test_baseline/test_subplots.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test_baseline/test_text.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit a58c27e

Please sign in to comment.