From 513fdf0d9aa5291e344b69c06f250633bf928b8d Mon Sep 17 00:00:00 2001 From: Mathias Hauser Date: Tue, 23 Sep 2025 15:01:03 +0200 Subject: [PATCH 1/3] some more tests --- mplotutils/__init__.py | 7 ++++++- mplotutils/_colorbar.py | 2 +- mplotutils/tests/test_colorbar.py | 10 ++++++++++ mplotutils/tests/test_hatch.py | 2 +- mplotutils/tests/test_label_map.py | 3 +++ mplotutils/tests/test_mapticklabels.py | 13 +++++++++---- 6 files changed, 30 insertions(+), 7 deletions(-) diff --git a/mplotutils/__init__.py b/mplotutils/__init__.py index ae5abf7..f96b120 100644 --- a/mplotutils/__init__.py +++ b/mplotutils/__init__.py @@ -46,12 +46,17 @@ 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" +def empty_func_not_testted(): + + pass + + def __getattr__(attr): m = ( 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..d404e3b 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 @@ -26,14 +29,16 @@ def test_yticklabels_robinson(): assert ax.texts[-1].get_text() == "70°N" -def test_yticklabels_robinson_180(): +@pytest.mark.parametrize("pass_ax", (True, False)) +def test_yticklabels_robinson_180(pass_ax): proj = ccrs.Robinson(central_longitude=180) with subplots_context(subplot_kw=dict(projection=proj)) 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 = 0.0 From 2067fc012563251608014ba478e8c2d2e9003e05 Mon Sep 17 00:00:00 2001 From: Mathias Hauser Date: Tue, 23 Sep 2025 15:10:42 +0200 Subject: [PATCH 2/3] cleanup --- mplotutils/__init__.py | 5 ----- mplotutils/tests/test_mapticklabels.py | 13 ++++++------- 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/mplotutils/__init__.py b/mplotutils/__init__.py index f96b120..37f547b 100644 --- a/mplotutils/__init__.py +++ b/mplotutils/__init__.py @@ -52,11 +52,6 @@ __version__ = "999" -def empty_func_not_testted(): - - pass - - def __getattr__(attr): m = ( diff --git a/mplotutils/tests/test_mapticklabels.py b/mplotutils/tests/test_mapticklabels.py index d404e3b..9afd569 100644 --- a/mplotutils/tests/test_mapticklabels.py +++ b/mplotutils/tests/test_mapticklabels.py @@ -29,16 +29,14 @@ def test_yticklabels_robinson(pass_ax): assert ax.texts[-1].get_text() == "70°N" -@pytest.mark.parametrize("pass_ax", (True, False)) -def test_yticklabels_robinson_180(pass_ax): +def test_yticklabels_robinson_180(): proj = ccrs.Robinson(central_longitude=180) with subplots_context(subplot_kw=dict(projection=proj)) as (f, ax): ax.set_global() lat = np.arange(-90, 91, 20) - ax_ = ax if pass_ax else None - mpu.yticklabels(lat, ax=ax_, size=8) + mpu.yticklabels(lat, ax=ax, size=8) x_pos = 0.0 @@ -52,13 +50,14 @@ def test_yticklabels_robinson_180(pass_ax): 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 From 07bb9d3c5287e7ded909220d9d3193b969d35f96 Mon Sep 17 00:00:00 2001 From: Mathias Hauser Date: Tue, 23 Sep 2025 15:30:48 +0200 Subject: [PATCH 3/3] changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) 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