Skip to content

Commit

Permalink
Add tests for backward compatibility of import strategies
Browse files Browse the repository at this point in the history
  • Loading branch information
jameswilburlewis committed Aug 29, 2024
1 parent 3e16347 commit 0039e65
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pyspedas/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
submodules = ['ace', 'akebono', 'barrel', 'cluster', 'cnofs', 'csswe', 'de2', 'dscovr',
'elfin', 'equator_s', 'erg', 'fast', 'geotail', 'goes', 'image', 'kompsat',
'kyoto', 'lanl', 'maven', 'mica', 'mms', 'noaa', 'omni', 'poes', 'polar', 'psp',
'rbsp', 'secs', 'soho', 'solo', 'st5', 'stereo', 'swarm', 'themis', 'twins',
'rbsp', 'secs', 'soho', 'solo', 'st5', 'stereo', 'swarm', 'themis', 'themis.state', 'twins',
'ulysses'
]

Expand Down
57 changes: 57 additions & 0 deletions pyspedas/utilities/tests/misc_tests.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Test functions in the utilites folder."""
import unittest

import pyspedas
from pyspedas.utilities.dailynames import dailynames
from pyspedas import tcopy
from pyspedas import themis
Expand Down Expand Up @@ -160,5 +161,61 @@ def test_find_datasets_label(self):
self.assertTrue('MMS1_FGM_BRST_L2' in ds)
self.assertTrue('MMS2_FGM_BRST_L2' in ds)

def test_imports(self):
import pyspedas
from pytplot import del_data, data_exists, tplot_names
# fully qualified name without .projects.
del_data('*')
pyspedas.themis.state(probe='a')
self.assertTrue(data_exists('tha_pos'))
# fully qualified name with .projects.
del_data('*')
pyspedas.projects.themis.state(probe='a')
self.assertTrue(data_exists('tha_pos'))

# import themis without .projects.
from pyspedas import themis
del_data('*')
themis.state(probe='a')
self.assertTrue(data_exists('tha_pos'))
# import themis with .projects.
from pyspedas.projects import themis
del_data('*')
themis.state(probe='a')
self.assertTrue(data_exists('tha_pos'))

# import state without .projects.
# PyCharm's static analysis doesn't like this (red underlines) but it works at runtime
from pyspedas.themis import state
del_data('*')
state(probe='a')
self.assertTrue(data_exists('tha_pos'))
# import state with .projects.
from pyspedas.projects.themis import state
del_data('*')
state(probe='a')
self.assertTrue(data_exists('tha_pos'))

from pyspedas import mms
del_data('*')
mms.fgm()
self.assertTrue(data_exists('mms1_fgm_b_gsm_srvy_l2'))

from pyspedas.mms import fgm
del_data('*')
fgm()
self.assertTrue(data_exists('mms1_fgm_b_gsm_srvy_l2'))

# import state without .projects.
from pyspedas.themis.state.state import state
del_data('*')
state(probe='a')
self.assertTrue(data_exists('tha_pos'))
# import state with .projects.
from pyspedas.projects.themis.state.state import state
del_data('*')
state(probe='a')
self.assertTrue(data_exists('tha_pos'))

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

0 comments on commit 0039e65

Please sign in to comment.