diff --git a/CHANGELOG.md b/CHANGELOG.md index d10ee6e..de857e5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,7 @@ ### Enhancements - Add python 3.13 to list of supported versions ([#158](https://github.com/mpytools/mplotutils/pull/158)). +- Increased test coverage ([#180](https://github.com/mpytools/mplotutils/pull/180)). ### Bug fixes diff --git a/mplotutils/__init__.py b/mplotutils/__init__.py index ae5abf7..37f547b 100644 --- a/mplotutils/__init__.py +++ b/mplotutils/__init__.py @@ -46,7 +46,7 @@ try: __version__ = _get_version("mplotutils") -except Exception: +except Exception: # pragma: no cover # Local copy or not installed with setuptools. # Disable minimum version checks on downstream libraries. __version__ = "999" diff --git a/mplotutils/_colorbar.py b/mplotutils/_colorbar.py index ab0fcba..3fab597 100644 --- a/mplotutils/_colorbar.py +++ b/mplotutils/_colorbar.py @@ -237,7 +237,7 @@ def colorbar( raise ValueError(msg) if not all(isinstance(ax, mpl.axes.Axes) for ax in axs): - raise TypeError("ax must be of Type mpl.axes.Axes") + raise TypeError("ax must be of type mpl.axes.Axes") f = axs[0].get_figure() diff --git a/mplotutils/tests/test_colorbar.py b/mplotutils/tests/test_colorbar.py index fad7174..89f4270 100644 --- a/mplotutils/tests/test_colorbar.py +++ b/mplotutils/tests/test_colorbar.py @@ -144,6 +144,16 @@ def test_colorbar_deprecate_ax1(): mpu.colorbar(h, ax1=ax) +def test_colorbar_error_not_axes(): + + with pytest.raises(TypeError, match="ax must be of type mpl.axes.Axes"): + mpu.colorbar(None, object()) + + with figure_context() as f: + with pytest.raises(TypeError, match="ax must be of type mpl.axes.Axes"): + mpu.colorbar(None, f) + + def test_colorbar_different_figures(): with figure_context() as f1, figure_context() as f2: ax1 = f1.subplots() diff --git a/mplotutils/tests/test_hatch.py b/mplotutils/tests/test_hatch.py index 2490994..bd50f19 100644 --- a/mplotutils/tests/test_hatch.py +++ b/mplotutils/tests/test_hatch.py @@ -57,7 +57,7 @@ def test_hatch_pattern(self): h = self.function(da, "*", ax=ax) assert h.hatches == ["", "*"] - h = self.function(da, "//", ax=ax) + h = self.function(da, "//") assert h.hatches == ["", "//"] def test_hatch_label(self): diff --git a/mplotutils/tests/test_label_map.py b/mplotutils/tests/test_label_map.py index a56776e..342d31e 100644 --- a/mplotutils/tests/test_label_map.py +++ b/mplotutils/tests/test_label_map.py @@ -9,3 +9,6 @@ def test_works(): with subplots_context() as (f, ax): ylabel_map("ylabel", ax=ax) xlabel_map("ylabel", ax=ax) + + ylabel_map("ylabel") + xlabel_map("ylabel") diff --git a/mplotutils/tests/test_mapticklabels.py b/mplotutils/tests/test_mapticklabels.py index 4eb4b74..9afd569 100644 --- a/mplotutils/tests/test_mapticklabels.py +++ b/mplotutils/tests/test_mapticklabels.py @@ -1,18 +1,21 @@ import cartopy.crs as ccrs import numpy as np +import pytest import mplotutils as mpu from . import subplots_context -def test_yticklabels_robinson(): +@pytest.mark.parametrize("pass_ax", (True, False)) +def test_yticklabels_robinson(pass_ax): with subplots_context(subplot_kw=dict(projection=ccrs.Robinson())) as (f, ax): ax.set_global() lat = np.arange(-90, 91, 20) - mpu.yticklabels(lat, ax=ax, size=8) + ax_ = ax if pass_ax else None + mpu.yticklabels(lat, ax=ax_, size=8) x_pos = -179.99 @@ -47,13 +50,14 @@ def test_yticklabels_robinson_180(): assert ax.texts[-1].get_text() == "70°N" -def test_xticklabels_robinson(): +@pytest.mark.parametrize("pass_ax", (True, False)) +def test_xticklabels_robinson(pass_ax): with subplots_context(subplot_kw=dict(projection=ccrs.Robinson())) as (f, ax): ax.set_global() lon = np.arange(-180, 181, 60) - - mpu.xticklabels(lon, ax=ax, size=8) + ax_ = ax if pass_ax else None + mpu.xticklabels(lon, ax=ax_, size=8) y_pos = -89.99