Skip to content

Commit

Permalink
Title assert accepts strings (#229)
Browse files Browse the repository at this point in the history
* Fixed assert_title_contains to take strings as well as lists

* Better implementation

* Changelog update

Co-authored-by: Leah Wasser <[email protected]>
  • Loading branch information
nkorinek and Leah Wasser authored Apr 2, 2020
1 parent bf9e2db commit 5121d6f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ 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 a string instead of a list (@nkorinek, #53)
* Added functions to get and assert the midpoint values of bins in a histogram (@nkorinek, #184)
* Created tests for the autograde module (@nkorinek, #105)
* Created tests for the vector module (@nkorinek, #209)
Expand Down
4 changes: 4 additions & 0 deletions matplotcheck/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,10 @@ def assert_string_contains(
return

string = string.lower().replace(" ", "")

if isinstance(strings_expected, str):
strings_expected = [strings_expected]

for check in strings_expected:
if isinstance(check, str):
if not check.lower().replace(" ", "") in string:
Expand Down
6 changes: 6 additions & 0 deletions matplotcheck/tests/test_base_titles_captions.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ def test_title_contains_axes_spaces(pt_line_plt):
plt.close()


def test_title_contains_axes_string(pt_line_plt):
"""Check title_contains for axes title as a string, not a list"""
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

0 comments on commit 5121d6f

Please sign in to comment.