Skip to content
Merged
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
* made `assert_string_contains()` accept correct strings with spaces in them (@nkorinek, #182)

## [0.1.2]
* Adding flake8 for format and other syntax issues! yay! (@lwasser, #195)
* Created a vignette covering the testing of histograms (@ryla5068, #149)
* Created `get_plot_image()` function for the RasterTester object (@nkorinek, #192)
Expand Down
4 changes: 2 additions & 2 deletions examples/plot_testing_basics.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
fig, ax = plt.subplots()
ax.bar(months, percip, color="blue")
ax.set(
title="Average Monthly Percipitation in Boulder, CO",
title="Average Monthly Precipitation in Boulder, CO",
xlabel="Month",
ylabel="Percipitation (in)",
)
Expand Down Expand Up @@ -86,7 +86,7 @@
plot_tester_1.assert_plot_type("bar")

# Test that the plot title contains specific words
plot_tester_1.assert_title_contains(["average", "month", "percip", "boulder"])
plot_tester_1.assert_title_contains(["average", "monthly precip", "boulder"])

# Test that the axis labels contain specific words
plot_tester_1.assert_axis_label_contains(axis="x", strings_expected=["month"])
Expand Down
6 changes: 4 additions & 2 deletions matplotcheck/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,12 @@ def assert_string_contains(
string = string.lower().replace(" ", "")
for check in strings_expected:
if isinstance(check, str):
if not check.lower() in string:
if not check.lower().replace(" ", "") in string:
raise AssertionError(message_default.format(check))
elif isinstance(check, list):
if not any([c.lower() in string for c in check]):
if not any(
[c.lower().replace(" ", "") in string for c in check]
):
if len(check) == 1:
raise AssertionError(message_default.format(check[0]))
else:
Expand Down
16 changes: 16 additions & 0 deletions matplotcheck/tests/test_base_axis.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,22 @@ def test_axis_label_contains_y(pt_line_plt):
plt.close()


def test_axis_label_contains_x_spaces(pt_line_plt):
"""Checks for assert_axis_label_contains for x axis with spaces"""
pt_line_plt.assert_axis_label_contains(
axis="x", strings_expected=["x label"]
)
plt.close()


def test_axis_label_contains_y_spaces(pt_line_plt):
"""Checks for assert_axis_label_contains for y axis with spaces"""
pt_line_plt.assert_axis_label_contains(
axis="y", strings_expected=["y label"]
)
plt.close()


def test_axis_label_contains_invalid_axis(pt_line_plt):
"""Check that assert_axis_label_contains fails when given unexpected
axis"""
Expand Down
12 changes: 12 additions & 0 deletions matplotcheck/tests/test_base_titles_captions.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ def test_title_contains_axes(pt_line_plt):
plt.close()


def test_title_contains_axes_spaces(pt_line_plt):
"""Check title_contains for axes title with spaces"""
pt_line_plt.assert_title_contains(["My Plot Title"], title_type="axes")
plt.close()


def test_title_contains_axes_badtext(pt_line_plt):
"""Check title_contains fails when given bad text"""
with pytest.raises(
Expand Down Expand Up @@ -123,6 +129,12 @@ def test_assert_caption_contains(pt_line_plt):
plt.close()


def test_assert_caption_contains_spaces(pt_line_plt):
"""Test that caption contains passes given right text with spaces"""
pt_line_plt.assert_caption_contains([["Figure Caption"]])
plt.close()


def test_assert_caption_contains_expect_empty(pt_line_plt):
"""Test that caption contains passes when expected text list is empty"""
pt_line_plt.assert_caption_contains([])
Expand Down