Skip to content

Commit

Permalink
libs pytplot tests are added
Browse files Browse the repository at this point in the history
  • Loading branch information
xandrd committed Nov 20, 2023
1 parent 2e29b22 commit 0bd900b
Showing 1 changed file with 43 additions and 6 deletions.
49 changes: 43 additions & 6 deletions pyspedas/utilities/tests/libs_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,20 @@
from io import StringIO
import sys
import pyspedas
import pytplot
from pyspedas.utilities.libs import libs


class LibsTestCase(unittest.TestCase):

def setUp(self):
# Call function once to import all the submodules to silence the output
try:
libs('')
except Exception as e:
self.fail("Unexpected exception %s" % e)

# We do not need this anymore:
# # Call function once to import all the submodules to silence the output
# try:
# libs('')
# except Exception as e:
# self.fail("Unexpected exception %s" % e)

# Redirect stdout to capture print statements
self.held_stdout = sys.stdout
Expand All @@ -39,12 +42,46 @@ def test_partial_function_name(self):
output = sys.stdout.getvalue()
self.assertIn('mms_', output)

def test_different_package(self):
def test_known_function_subpackage(self):
libs('fgm', package=pyspedas.themis)
output = sys.stdout.getvalue()
self.assertIn('fgm', output)
self.assertNotIn('mms', output)

def test_known_function_pytplot(self):
libs('get_data')
output = sys.stdout.getvalue()
self.assertIn('get_data', output)
self.assertIn('Function:', output)

def test_known_function_version_pyspeds_subpackage(self):
libs('version', package=pyspedas)
output = sys.stdout.getvalue()
self.assertIn('version', output)
self.assertNotIn('Function: pytplot', output)

def test_known_function_version_pyspeds_themis_subpackage(self):
libs('fgm', package=pyspedas.themis)
output = sys.stdout.getvalue()
self.assertIn('fgm', output)

def test_known_function_pytplot_get_data(self):
libs('get_data')
output = sys.stdout.getvalue()
self.assertIn('get_data', output)
self.assertIn('Function:', output)

def test_known_function_data_pytplot_subpackage_only(self):
libs('data', package=pytplot)
output = sys.stdout.getvalue()
self.assertIn('get_data', output)
self.assertNotIn('Function: pyspedas', output)

def test_qtplotter_error_exception(self):
# This test is probably not the best way to handle this exception
libs('qtplotter', package=pytplot) # This can be changed to anything. qtplotter error is during pytplot import search
output = sys.stdout.getvalue()
self.assertNotIn('Error importing module pytplot.QtPlotter', output)

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

0 comments on commit 0bd900b

Please sign in to comment.