Skip to content

Commit

Permalink
Seeds for t_plot_fit
Browse files Browse the repository at this point in the history
Also:
* remove t_plot_fit from run_tests
* add short README for pytest
* add to setup.py
  • Loading branch information
pgkirsch committed Oct 23, 2021
1 parent 9326279 commit 93048ca
Show file tree
Hide file tree
Showing 13 changed files with 29 additions and 13 deletions.
10 changes: 10 additions & 0 deletions gpfit/tests/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
## Plot unit tests

Plot unit tests are run with [pytest-mpl](https://github.com/matplotlib/pytest-mpl)

To generate the baseline images:
`pytest --mpl-generate-path=baseline t_plot_fit.py`

To test against the baseline images:
`pytest --mpl t_plot_fit.py`

Binary file modified gpfit/tests/baseline/isma_1d.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified gpfit/tests/baseline/isma_2d_slices.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified gpfit/tests/baseline/isma_2d_surface.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified gpfit/tests/baseline/ma_1d.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified gpfit/tests/baseline/ma_2d_slices.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified gpfit/tests/baseline/ma_2d_surface.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified gpfit/tests/baseline/sma_1d.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified gpfit/tests/baseline/sma_2d_slices.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified gpfit/tests/baseline/sma_2d_surface.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 0 additions & 3 deletions gpfit/tests/run_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@
from gpfit.tests import t_print_fit
TESTS += t_print_fit.TESTS

from gpfit.tests import t_plot_fit
TESTS += t_plot_fit.TESTS

from gpfit.tests import t_examples
TESTS += t_examples.TESTS

Expand Down
20 changes: 11 additions & 9 deletions gpfit/tests/t_plot_fit.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import numpy as np
from gpfit.fit import MaxAffine, SoftmaxAffine, ImplicitSoftmaxAffine

SEED = 33404


class TestPlot:
"Unit tests for plot methods"
Expand All @@ -16,19 +18,19 @@ class TestPlot:

@pytest.mark.mpl_image_compare(filename='ma_1d.png')
def test_max_affine(self):
f = MaxAffine(self.x, self.y, self.K)
f = MaxAffine(self.x, self.y, self.K, seed=SEED)
fig, _ = f.plot()
return fig

@pytest.mark.mpl_image_compare(filename='sma_1d.png')
def test_softmax_affine(self):
f = SoftmaxAffine(self.x, self.y, self.K)
f = SoftmaxAffine(self.x, self.y, self.K, seed=SEED)
fig, _ = f.plot()
return fig

@pytest.mark.mpl_image_compare(filename='isma_1d.png')
def test_implicit_softmax_affine(self):
f = ImplicitSoftmaxAffine(self.x, self.y, self.K)
f = ImplicitSoftmaxAffine(self.x, self.y, self.K, seed=SEED)
fig, _ = f.plot()
return fig

Expand All @@ -47,19 +49,19 @@ class TestPlotSurface:

@pytest.mark.mpl_image_compare(filename='ma_2d_surface.png')
def test_max_affine(self):
f = MaxAffine(self.x, self.y, self.K)
f = MaxAffine(self.x, self.y, self.K, seed=SEED)
fig, _ = f.plot_surface(azim=135)
return fig

@pytest.mark.mpl_image_compare(filename='sma_2d_surface.png')
def test_softmax_affine(self):
f = SoftmaxAffine(self.x, self.y, self.K)
f = SoftmaxAffine(self.x, self.y, self.K, seed=SEED)
fig, _ = f.plot_surface(azim=135)
return fig

@pytest.mark.mpl_image_compare(filename='isma_2d_surface.png')
def test_implicit_softmax_affine(self):
f = ImplicitSoftmaxAffine(self.x, self.y, self.K)
f = ImplicitSoftmaxAffine(self.x, self.y, self.K, seed=SEED)
fig, _ = f.plot_surface(azim=135)
return fig

Expand All @@ -79,19 +81,19 @@ class TestPlotSlices:

@pytest.mark.mpl_image_compare(filename='ma_2d_slices.png')
def test_max_affine(self):
f = MaxAffine(self.x, self.y, self.K)
f = MaxAffine(self.x, self.y, self.K, seed=SEED)
fig, _ = f.plot_slices()
return fig

@pytest.mark.mpl_image_compare(filename='sma_2d_slices.png')
def test_softmax_affine(self):
f = SoftmaxAffine(self.x, self.y, self.K)
f = SoftmaxAffine(self.x, self.y, self.K, seed=SEED)
fig, _ = f.plot_slices()
return fig

@pytest.mark.mpl_image_compare(filename='isma_2d_slices.png')
def test_implicit_softmax_affine(self):
f = ImplicitSoftmaxAffine(self.x, self.y, self.K)
f = ImplicitSoftmaxAffine(self.x, self.y, self.K, seed=SEED)
fig, _ = f.plot_slices()
return fig

Expand Down
9 changes: 8 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,14 @@
author_email="gpkit@mit.edu",
url="https://github.com/convexengineering/gpfit",
python_requires=">=3.4",
install_requires=["numpy", "scipy", "gpkit", "matplotlib"],
install_requires=[
"numpy",
"scipy",
"gpkit",
"matplotlib==3.3.2",
"pytest==6.2.5",
"pytest-mpl==0.13",
],
version="0.2.0",
packages=["gpfit", "gpfit.maths", "gpfit.tests", "gpfit.xfoil"],
include_package_data=True,
Expand Down

0 comments on commit 93048ca

Please sign in to comment.