Skip to content

Commit

Permalink
Merge pull request #51 from jgieseler/test_figures
Browse files Browse the repository at this point in the history
Add real figure unit test
  • Loading branch information
jgieseler authored Mar 22, 2024
2 parents f9947af + 3a35c59 commit 45b6108
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 9 deletions.
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ test =
pytest
pytest-doctestplus
pytest-cov
pytest-mpl
docs =
sphinx
sphinx-automodapi
Expand Down
4 changes: 4 additions & 0 deletions solarmach/tests/figure_hashes_mpl_353.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"solarmach.tests.test.test_solarmach_plot": "81ac59e6d0803820cde44e62f6324990da07b837962a7450ec42fd208b44585e",
"solarmach.tests.test.test_solarmach_pfss": "f668036286f29197e67e26f5eeec1dc70d93c0d1c8e58c323d27794126581141"
}
17 changes: 11 additions & 6 deletions solarmach/tests/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
import numpy as np
import pandas
import pfsspy
import pytest
import sunpy
from pathlib import Path
from solarmach import SolarMACH, print_body_list, get_gong_map, calculate_pfss_solution, sc_distance


Expand Down Expand Up @@ -58,6 +60,7 @@ def test_solarmach_get_sw_speed():
assert sm.coord_table[sm.coord_table['Spacecraft/Body']=='BepiColombo']['Vsw'].values[0] == 400.0


@pytest.mark.mpl_image_compare(hash_library=Path(__file__).parent / 'figure_hashes_mpl_353.json')
def test_solarmach_plot():
body_list = ['STEREO-A']
vsw_list = [400]
Expand All @@ -72,15 +75,16 @@ def test_solarmach_plot():
background_spirals=[6, 600]

sm = SolarMACH(date=date, body_list=body_list, vsw_list=vsw_list, reference_long=reference_long, reference_lat=reference_lat)
sm.plot(plot_spirals=True, plot_sun_body_line=True,
reference_vsw=reference_vsw, transparent=False,
show_earth_centered_coord=False, markers='numbers',
long_sector=long_sector, long_sector_vsw=long_sector_vsw, long_sector_color=long_sector_color,
background_spirals=background_spirals, outfile=filename)

fig, ax = sm.plot(plot_spirals=True, plot_sun_body_line=True,
reference_vsw=reference_vsw, transparent=False,
show_earth_centered_coord=False, markers='numbers',
long_sector=long_sector, long_sector_vsw=long_sector_vsw, long_sector_color=long_sector_color,
background_spirals=background_spirals, outfile=filename, return_plot_object=True)
assert os.path.exists(os.getcwd()+os.sep+filename)
return fig


@pytest.mark.mpl_image_compare(hash_library=Path(__file__).parent / 'figure_hashes_mpl_353.json')
def test_solarmach_pfss():
date = '2021-4-1 1:00:00'
body_list = ['Earth', 'STEREO-A']
Expand All @@ -94,6 +98,7 @@ def test_solarmach_pfss():
markers='numbers', long_sector=[290, 328], long_sector_vsw=[400, 600],
long_sector_color='red', reference_vsw=400.0)
assert isinstance(fig, matplotlib.figure.Figure)
return fig


def test_sc_distance():
Expand Down
6 changes: 3 additions & 3 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tox]
envlist =
py{36,37,38}-test
py{38,39,310}-test
build_docs
codestyle
isolated_build = true
Expand All @@ -9,7 +9,7 @@ skip_missing_interpreters = True

[testenv]
# Pass through the following environemnt variables which may be needed for the CI
passenv = HOME WINDIR LC_ALL LC_CTYPE CC CI TRAVIS
passenv = HOME, WINDIR, LC_ALL, LC_CTYPE, CC, CI, TRAVIS

# Run the tests in a temporary directory to make sure that we don't import
# the package from the source tree
Expand All @@ -34,7 +34,7 @@ extras =

commands =
pip freeze
pytest --pyargs solarmach {toxinidir}/docs --cov solarmach --cov-config={toxinidir}/setup.cfg {posargs}
pytest --pyargs solarmach {toxinidir}/docs --cov solarmach --cov-config={toxinidir}/setup.cfg {posargs} --mpl

[testenv:build_docs]
changedir = docs
Expand Down

0 comments on commit 45b6108

Please sign in to comment.