diff --git a/ultraplot/tests/test_1dplots.py b/ultraplot/tests/test_1dplots.py index d368cdd04..4108d1e09 100644 --- a/ultraplot/tests/test_1dplots.py +++ b/ultraplot/tests/test_1dplots.py @@ -171,13 +171,33 @@ def test_column_iteration(rng): return fig -@pytest.mark.skip("TODO") -@pytest.mark.mpl_image_compare -def test_bar_stack(): - """ - Test bar and area stacking. - """ - # TODO: Add test here +@pytest.mark.parametrize("method", ["bar", "barh"]) +def test_bar_stack(method): + """Each column starts at the preceding columns' sum at the same position.""" + fig, ax = uplt.subplots() + positions = np.array([1, 2, 3]) + values = np.array([[1, 2, 3], [4, 2, 1], [2, 3, 4]]) + original = values.copy() + containers = getattr(ax, method)(positions, values, stacked=True) + + assert len(containers) == values.shape[1] + for column, container in enumerate(containers): + assert len(container.patches) == len(positions) + bottoms, heights, centers = [], [], [] + for patch in container.patches: + if method == "bar": + bottoms.append(patch.get_y()) + heights.append(patch.get_height()) + centers.append(patch.get_x() + patch.get_width() / 2) + else: + bottoms.append(patch.get_x()) + heights.append(patch.get_width()) + centers.append(patch.get_y() + patch.get_height() / 2) + np.testing.assert_allclose(bottoms, values[:, :column].sum(axis=1)) + np.testing.assert_allclose(heights, values[:, column]) + np.testing.assert_allclose(centers, positions) + np.testing.assert_array_equal(values, original) + fig.canvas.draw() @pytest.mark.mpl_image_compare diff --git a/ultraplot/tests/test_fonts.py b/ultraplot/tests/test_fonts.py index 52079bfd4..713824df3 100644 --- a/ultraplot/tests/test_fonts.py +++ b/ultraplot/tests/test_fonts.py @@ -1,20 +1,9 @@ from matplotlib.mathtext import MathTextParser -import pytest, ultraplot as uplt, matplotlib as mpl +import ultraplot as uplt, matplotlib as mpl import ultraplot.internals.fonts as ufonts from unittest.mock import patch, MagicMock - -@pytest.mark.skip(reason="Only for reference, relies on class attributes") -def test_replacement(): - """ - Test whether replaced the unicodes fonts - """ - # This is just a reference and is already skipped - # The correct attribute name may have changed in the MathTextParser class - pass - - # Postscript names of the Computer Modern fonts used for symbol routing _CM_FONT_NAMES = {"Cmsy10", "Cmex10"} diff --git a/ultraplot/tests/test_format.py b/ultraplot/tests/test_format.py index 51cc8b3fe..3a5132d25 100644 --- a/ultraplot/tests/test_format.py +++ b/ultraplot/tests/test_format.py @@ -5,6 +5,7 @@ import locale, numpy as np, ultraplot as uplt, pytest import warnings +from ultraplot.internals.warnings import UltraPlotWarning def test_format_is_the_only_entry_point(): @@ -77,23 +78,31 @@ def record(keys): # assert uplt.rc["image.cmap"] == uplt.rc["cmap.sequential"] == "_magma_copy_r" -@pytest.mark.skip(reason="This is failing on github but not locally") def test_ignored_keywords(): - """ - Test ignored keywords and functions. - """ + """Legacy layout arguments emit specific UltraPlot warnings.""" with warnings.catch_warnings(record=True) as record: + warnings.simplefilter("always", UltraPlotWarning) fig, ax = uplt.subplots( gridspec_kw={"left": 3}, subplot_kw={"proj": "cart"}, subplotpars={"left": 0.2}, ) - # only capture ultraplot warnings not general mpl warnings, e.g. deprecation warnings - record = [r for r in record if "UltraPlotWarning" in str(r)] - assert len(record) == 3 - with warnings.catch_warnings(record=True) as record: + messages = [ + str(item.message) + for item in record + if issubclass(item.category, UltraPlotWarning) + ] + for expected in ( + "'gridspec_kw' is not necessary in ultraplot", + "'subplot_kw' is not necessary in ultraplot", + "Ignoring subplotpars=", + ): + assert any(expected in message for message in messages), messages + with pytest.warns( + UltraPlotWarning, + match=r"fig\.subplots_adjust\(\) has no effect on ultraplot figures", + ): fig.subplots_adjust(left=0.2) - assert len(record) == 1 @pytest.mark.mpl_image_compare