Skip to content

Commit d9c772f

Browse files
authored
some more tests (#180)
* some more tests * cleanup * changelog
1 parent b1815d4 commit d9c772f

File tree

7 files changed

+26
-8
lines changed

7 files changed

+26
-8
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
### Enhancements
2222

2323
- Add python 3.13 to list of supported versions ([#158](https://github.com/mpytools/mplotutils/pull/158)).
24+
- Increased test coverage ([#180](https://github.com/mpytools/mplotutils/pull/180)).
2425

2526
### Bug fixes
2627

mplotutils/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646

4747
try:
4848
__version__ = _get_version("mplotutils")
49-
except Exception:
49+
except Exception: # pragma: no cover
5050
# Local copy or not installed with setuptools.
5151
# Disable minimum version checks on downstream libraries.
5252
__version__ = "999"

mplotutils/_colorbar.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ def colorbar(
237237
raise ValueError(msg)
238238

239239
if not all(isinstance(ax, mpl.axes.Axes) for ax in axs):
240-
raise TypeError("ax must be of Type mpl.axes.Axes")
240+
raise TypeError("ax must be of type mpl.axes.Axes")
241241

242242
f = axs[0].get_figure()
243243

mplotutils/tests/test_colorbar.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,16 @@ def test_colorbar_deprecate_ax1():
144144
mpu.colorbar(h, ax1=ax)
145145

146146

147+
def test_colorbar_error_not_axes():
148+
149+
with pytest.raises(TypeError, match="ax must be of type mpl.axes.Axes"):
150+
mpu.colorbar(None, object())
151+
152+
with figure_context() as f:
153+
with pytest.raises(TypeError, match="ax must be of type mpl.axes.Axes"):
154+
mpu.colorbar(None, f)
155+
156+
147157
def test_colorbar_different_figures():
148158
with figure_context() as f1, figure_context() as f2:
149159
ax1 = f1.subplots()

mplotutils/tests/test_hatch.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def test_hatch_pattern(self):
5757

5858
h = self.function(da, "*", ax=ax)
5959
assert h.hatches == ["", "*"]
60-
h = self.function(da, "//", ax=ax)
60+
h = self.function(da, "//")
6161
assert h.hatches == ["", "//"]
6262

6363
def test_hatch_label(self):

mplotutils/tests/test_label_map.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,6 @@ def test_works():
99
with subplots_context() as (f, ax):
1010
ylabel_map("ylabel", ax=ax)
1111
xlabel_map("ylabel", ax=ax)
12+
13+
ylabel_map("ylabel")
14+
xlabel_map("ylabel")

mplotutils/tests/test_mapticklabels.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
11
import cartopy.crs as ccrs
22
import numpy as np
3+
import pytest
34

45
import mplotutils as mpu
56

67
from . import subplots_context
78

89

9-
def test_yticklabels_robinson():
10+
@pytest.mark.parametrize("pass_ax", (True, False))
11+
def test_yticklabels_robinson(pass_ax):
1012
with subplots_context(subplot_kw=dict(projection=ccrs.Robinson())) as (f, ax):
1113
ax.set_global()
1214

1315
lat = np.arange(-90, 91, 20)
1416

15-
mpu.yticklabels(lat, ax=ax, size=8)
17+
ax_ = ax if pass_ax else None
18+
mpu.yticklabels(lat, ax=ax_, size=8)
1619

1720
x_pos = -179.99
1821

@@ -47,13 +50,14 @@ def test_yticklabels_robinson_180():
4750
assert ax.texts[-1].get_text() == "70°N"
4851

4952

50-
def test_xticklabels_robinson():
53+
@pytest.mark.parametrize("pass_ax", (True, False))
54+
def test_xticklabels_robinson(pass_ax):
5155
with subplots_context(subplot_kw=dict(projection=ccrs.Robinson())) as (f, ax):
5256
ax.set_global()
5357

5458
lon = np.arange(-180, 181, 60)
55-
56-
mpu.xticklabels(lon, ax=ax, size=8)
59+
ax_ = ax if pass_ax else None
60+
mpu.xticklabels(lon, ax=ax_, size=8)
5761

5862
y_pos = -89.99
5963

0 commit comments

Comments
 (0)