Skip to content

Commit

Permalink
Close figures on teardown (#254)
Browse files Browse the repository at this point in the history
* add pytest fixture to close plots

* also deal with reader, samples and weighted pandas

* instead use TestPlotBase

* nearly linted

* finish linting

* Revert "finish linting"

This reverts commit dd1ed76.

* Revert "nearly linted"

This reverts commit b0aa9b9.

* Revert "instead use TestPlotBase"

This reverts commit 38ca3d1.

* place fixture in test_plot.py instead

* realised what autouse=True does lol

* hist->hist_1d as consequence of #246

* code repetitionionionionion

* removed yield which I copied from the previous attempt

* added check to CI, should fail due to matplotlib.agg.py

* remember to import pytest

* message tweak

* add ls

* add >>

* remove second grep

* only check test*.py

* use variables properly

* extra set of

* make test_gui.py fail again

* not sure what was going on with those wildcards

* echo missing

* too many brackets

* remove echo missing

* unfail test_gui.py

* Revert "unfail test_gui.py"

This reverts commit b45feb6.

* list files in message

* put everything in the if

* bash if statement is more appropriate, as test should always show as run

* fail test_weighted_pandas.py

* remove pandas testing import

* Revert "remove pandas testing import"

This reverts commit d0999e4.

* Revert "fail test_weighted_pandas.py"

This reverts commit 336e69b.

* Revert "Revert "unfail test_gui.py""

This reverts commit 3a7ab81.

* capital C

* Removed erroneous fixture

Co-authored-by: Will Handley <[email protected]>
  • Loading branch information
AdamOrmondroyd and williamjameshandley authored Jan 27, 2023
1 parent 394712c commit 0618a8f
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 2 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ jobs:
run: python -m flake8 anesthetic tests
- name: pydocstyle documentation style checks
run: python -m pydocstyle --convention=numpy anesthetic
- name: Count missing test fixtures
run: |
if [ $( grep -L 'close_figures_on_teardown' $(grep -l 'matplotlib' tests/test*.py) | wc -w ) -ne 0 ]
then
missing_tests=$( grep -L 'close_figures_on_teardown' $(grep -l 'matplotlib' tests/test*.py) )
echo "$missing_tests are missing the close_figures_on_teardown fixture."
exit 1
fi
pip:
runs-on: ${{ matrix.os }}
Expand Down
7 changes: 7 additions & 0 deletions tests/test_gui.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
import anesthetic.examples._matplotlib_agg # noqa: F401
from anesthetic import read_chains
import pytest
import pandas._testing as tm


@pytest.fixture(autouse=True)
def close_figures_on_teardown():
tm.close()


def test_gui():
Expand Down
6 changes: 6 additions & 0 deletions tests/test_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
scatter_plot_2d, quantile_plot_interval,
basic_cmap, AxesSeries, AxesDataFrame)
from numpy.testing import assert_array_equal
import pandas._testing as tm

from matplotlib.axes._subplots import SubplotBase
from matplotlib.contour import ContourSet
Expand All @@ -21,6 +22,11 @@
from scipy.interpolate import interp1d


@pytest.fixture(autouse=True)
def close_figures_on_teardown():
tm.close()


def test_AxesObjects():
paramnames = ['a', 'b', 'c']

Expand Down
6 changes: 6 additions & 0 deletions tests/test_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,18 @@
from anesthetic.read.getdist import read_getdist
from anesthetic.read.cobaya import read_cobaya
from anesthetic.read.multinest import read_multinest
import pandas._testing as tm
try:
import getdist
except ImportError:
pass


@pytest.fixture(autouse=True)
def close_figures_on_teardown():
tm.close()


def test_read_getdist():
np.random.seed(3)
mcmc = read_getdist('./tests/example_data/gd')
Expand Down
10 changes: 8 additions & 2 deletions tests/test_samples.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,16 @@
from numpy.testing import (assert_array_equal, assert_array_almost_equal,
assert_array_less, assert_allclose)
from pandas.testing import assert_frame_equal
import pandas._testing as tm
from matplotlib.colors import to_hex
from scipy.stats import ks_2samp, kstest, norm


@pytest.fixture(autouse=True)
def close_figures_on_teardown():
tm.close()


def test_build_samples():
np.random.seed(3)
nsamps = 1000
Expand Down Expand Up @@ -186,9 +192,9 @@ def test_plot_2d_kinds_multiple_calls():
axes = ns.plot_2d(params, kind={'diagonal': 'kde_1d',
'lower': 'kde_2d',
'upper': 'scatter_2d'})
ns.plot_2d(axes, kind={'diagonal': 'hist'})
ns.plot_2d(axes, kind={'diagonal': 'hist_1d'})

axes = ns.plot_2d(params, kind={'diagonal': 'hist'})
axes = ns.plot_2d(params, kind={'diagonal': 'hist_1d'})
ns.plot_2d(axes, kind={'diagonal': 'kde_1d',
'lower': 'kde_2d',
'upper': 'scatter_2d'})
Expand Down
6 changes: 6 additions & 0 deletions tests/test_weighted_pandas.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@
from pandas.plotting._matplotlib.misc import (
scatter_matrix as orig_scatter_matrix
)
import pandas._testing as tm


@pytest.fixture(autouse=True)
def close_figures_on_teardown():
tm.close()


@pytest.fixture
Expand Down

0 comments on commit 0618a8f

Please sign in to comment.