diff --git a/CHANGELOG.md b/CHANGELOG.md index bbb28c03..6717f783 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/examples/plot_testing_basics.py b/examples/plot_testing_basics.py index 839a6919..45b182a7 100644 --- a/examples/plot_testing_basics.py +++ b/examples/plot_testing_basics.py @@ -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)", ) @@ -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"]) diff --git a/matplotcheck/base.py b/matplotcheck/base.py index 46cc940b..29be8d9b 100644 --- a/matplotcheck/base.py +++ b/matplotcheck/base.py @@ -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: diff --git a/matplotcheck/tests/test_base_axis.py b/matplotcheck/tests/test_base_axis.py index e16f2885..dfd70af7 100644 --- a/matplotcheck/tests/test_base_axis.py +++ b/matplotcheck/tests/test_base_axis.py @@ -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""" diff --git a/matplotcheck/tests/test_base_titles_captions.py b/matplotcheck/tests/test_base_titles_captions.py index 1506b77e..8fd65581 100644 --- a/matplotcheck/tests/test_base_titles_captions.py +++ b/matplotcheck/tests/test_base_titles_captions.py @@ -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( @@ -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([])