Skip to content

Commit

Permalink
Modified tests to avoid displaying plots in Github CI tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jameswilburlewis committed Apr 19, 2024
1 parent 2aa5b27 commit b8765e6
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 33 deletions.
2 changes: 1 addition & 1 deletion pyspedas_examples/examples/ex_avg.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def ex_avg(plot=True):
return 1


def ex_avg2():
def ex_avg2(plot=True):
"""Load some random data and find the time average.
The same example can be run on IDL to compare results.
Expand Down
5 changes: 3 additions & 2 deletions pyspedas_examples/examples/ex_colors.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from pyspedas.themis import state


def ex_colors():
def ex_colors(plot=True):
"""Get state data for THEMIS
Load position and velocity from THEMIS and plot with different colors.
Expand All @@ -24,7 +24,8 @@ def ex_colors():

# choose line colors
options('tha_pos', 'color', ['black', 'magenta', 'cyan'])
tplot(['tha_pos', 'tha_vel', ])
if plot:
tplot(['tha_pos', 'tha_vel', ])

# Return 1 as indication that the example finished without problems.
return 1
Expand Down
5 changes: 3 additions & 2 deletions pyspedas_examples/examples/ex_cotrans.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from pyspedas.themis import state


def ex_cotrans():
def ex_cotrans(plot=True):
"""Transform state data for THEMIS from GEI to GSE.
Load position and velocity from THEMIS.
Expand Down Expand Up @@ -42,7 +42,8 @@ def ex_cotrans():
options(vel_in, 'legend_names', ["Vx, GEI", "Vy, GEI", "Vz, GEI"])
options(vel_out, 'ytitle', vel_out)
options(vel_out, 'legend_names', ["Vx, GSE", "Vy, GSE", "Vz, GSE"])
tplot([pos_in, vel_in, pos_out, vel_out])
if plot:
tplot([pos_in, vel_in, pos_out, vel_out])

# Return 1 as indication that the example finished without problems.
return 1
Expand Down
5 changes: 3 additions & 2 deletions pyspedas_examples/examples/ex_mpause_2.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from pyspedas import mpause_2


def ex_mpause_2():
def ex_mpause_2(plot=True):

# Call the function without parameters to use default values
xmp, ymp = mpause_2()
Expand All @@ -36,7 +36,8 @@ def ex_mpause_2():
plt.title("Magnetopause Locations")

# Display the plot
plt.show()
if plot:
plt.show()


# Run the example code
Expand Down
5 changes: 3 additions & 2 deletions pyspedas_examples/examples/ex_mpause_t96.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from pyspedas import cotrans, mpause_t96


def ex_mpause_t96():
def ex_mpause_t96(plot=True):

# Set the date and load one day of data
date_start = '2019-01-05/00:00:00'
Expand Down Expand Up @@ -47,7 +47,8 @@ def ex_mpause_t96():
plt.ylabel('Y (Re)')
plt.title('Magnetopause Boundary')
plt.grid(True)
plt.show()
if plot:
plt.show()


# Run the example code
Expand Down
39 changes: 15 additions & 24 deletions tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,38 @@

import unittest

global_display=False

class LoadTestCases(unittest.TestCase):
"""Run tests on examples."""

def test_version(self):
"""Test ex_avg."""
"""Test version"""
from pyspedas_examples.version import version
self.assertFalse(version())

def test_ex_analysis(self):
"""Test ex_analysis."""
from pyspedas_examples.examples.ex_analysis import ex_analysis
ex = ex_analysis()
ex = ex_analysis(plot=global_display)
self.assertEqual(ex, 1)

def test_ex_avg(self):
"""Test ex_avg."""
from pyspedas_examples.examples.ex_avg import ex_avg
ex = ex_avg()
ex = ex_avg(plot=global_display)
self.assertEqual(ex, 1)

def test_ex_avg2(self):
"""Test ex_avg."""
from pyspedas_examples.examples.ex_avg import ex_avg2
ex = ex_avg2()
ex = ex_avg2(plot=global_display)
self.assertAlmostEqual(ex[0], 1044.22)

def test_ex_basic(self):
"""Test ex_basic."""
from pyspedas_examples.examples.ex_basic import ex_basic
ex = ex_basic()
ex = ex_basic(plot=global_display)
self.assertEqual(ex, 1)

def test_ex_cdagui(self):
Expand All @@ -47,58 +48,47 @@ def test_ex_cdasws(self):
ex = ex_cdasws()
self.assertEqual(ex, 1)

def test_ex_create(self):
"""Test ex_basic."""
from pyspedas_examples.examples.ex_create import ex_create
ex = ex_create()
self.assertEqual(ex, 1)

def test_ex_deriv(self):
"""Test ex_basic."""
from pyspedas_examples.examples.ex_deriv import ex_deriv
ex = ex_deriv()
ex = ex_deriv(plot=global_display)
self.assertEqual(ex, 1)

def test_ex_deriv2(self):
"""Test ex_basic."""
from pyspedas_examples.examples.ex_deriv import ex_deriv2
ex = ex_deriv2()
self.assertEqual(ex, 1)

def test_ex_dsl2gse(self):
"""Test ex_dsl2gse."""
from pyspedas_examples.examples.ex_dsl2gse import ex_dsl2gse
ex = ex_dsl2gse()
ex = ex_dsl2gse(plot=global_display)
self.assertEqual(ex, 1)

def test_ex_gmag(self):
"""Test ex_dsl2gse."""
from pyspedas_examples.examples.ex_gmag import ex_gmag
ex = ex_gmag()
ex = ex_gmag(plot=global_display)
self.assertEqual(ex, 1)

def test_ex_smooth(self):
"""Test ex_dsl2gse."""
from pyspedas_examples.examples.ex_smooth import ex_smooth
ex = ex_smooth()
ex = ex_smooth(plot=global_display)
self.assertEqual(ex, 1)

def test_ex_spectra(self):
"""Test ex_spectra."""
from pyspedas_examples.examples.ex_spectra import ex_spectra
ex = ex_spectra()
ex = ex_spectra(plot=global_display)
self.assertEqual(ex, 1)

def test_ex_spikes(self):
"""Test ex_spectra."""
from pyspedas_examples.examples.ex_spikes import ex_spikes
ex = ex_spikes()
ex = ex_spikes(plot=global_display)
self.assertEqual(ex, 1)

def test_ex_wavelet(self):
"""Test ex_spectra."""
from pyspedas_examples.examples.ex_wavelet import ex_wavelet
ex = ex_wavelet()
ex = ex_wavelet(plot=global_display)
self.assertEqual(ex, 1)

def test_pseudovar_right_axis(self):
Expand All @@ -110,7 +100,8 @@ def test_pseudovar_right_axis(self):
store_data('spec', data=['mms1_des_energyspectr_omni_fast', 'mms1_edp_scpot_fast_l2'])
options('spec', 'right_axis', True)
tplot_options('xmargin', [0.1, 0.2])
tplot('spec', xsize=12)
if global_display:
tplot('spec', xsize=12)

if __name__ == '__main__':
unittest.main()

0 comments on commit b8765e6

Please sign in to comment.