Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Test with pytest
run: |
pytest -rP --mpl --mpl-baseline-path=baseline --mpl-baseline-relative --mpl-generate-summary=html --mpl-results-path='/home/runner/work/bowtie/bowtie/tests/report/' --cov=bowtie --cov-report=xml bowtie/tests/test.py --nbmake *.ipynb
pytest -rP --mpl --mpl-baseline-path=baseline --mpl-baseline-relative --mpl-generate-summary=html --mpl-results-path='/home/runner/work/bowtie/bowtie/tests/report/' --cov=bowtie --cov-report=xml bowtie/tests/test_.py --nbmake *.ipynb
# - name: Upload coverage reports to Codecov
# uses: codecov/codecov-action@v4
# env:
Expand Down
Binary file modified bowtie/tests/baseline/test_bowtie.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 19 additions & 0 deletions bowtie/tests/helpers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# tests/helpers.py
def strip_figure_text(fig):
"""
Remove all text elements that vary across matplotlib versions.
Use before returning a figure in mpl_image_compare tests.
"""
fig.suptitle('')
for text in fig.texts:
text.set_text('')
for ax in fig.axes:
ax.set_title('')
ax.set_xlabel('') # not removed by remove_text=True
ax.set_ylabel('') # not removed by remove_text=True
ax.set_xticklabels([])
ax.set_yticklabels([])
leg = ax.get_legend()
if leg:
leg.remove()
return fig
9 changes: 6 additions & 3 deletions bowtie/tests/test.py → bowtie/tests/test_.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,17 @@

from bowtie import bowtie as bow
from bowtie import bowtie_util as btutil
from bowtie.tests.helpers import strip_figure_text

"""
Install dependencies for tests:
pip install flake8 pytest pytest-doctestplus pytest-cov pytest-mpl

To create/update the baseline images, run the following command from the base package dir:
pytest --mpl-generate-path=bowtie/tests/baseline bowtie/tests/test.py
pytest --mpl-generate-path=bowtie/tests/baseline bowtie/tests/test_.py

To run the tests locally, go to the base directory of the repository and run:
pytest -rP --mpl --mpl-baseline-path=baseline --mpl-baseline-relative --mpl-generate-summary=html --cov=bowtie bowtie/tests/test.py
pytest -rP --mpl --mpl-baseline-path=baseline --mpl-baseline-relative --mpl-generate-summary=html --cov=bowtie bowtie/tests/test_.py
"""

@pytest.mark.mpl_image_compare(remove_text=True, deterministic=True)
Expand Down Expand Up @@ -86,4 +87,6 @@ def test_bowtie():
assert os.path.exists(f'boxcar{i}_bowtie.png')

# return last produced fig for mpl pytest
return all_channels_results[3]['fig']

# Strip before returning — don't rely solely on remove_text=True
return strip_figure_text(all_channels_results[3]['fig'])