From 0bd900b3cc02a7d8e8a8deccff1311eb5ee5bccb Mon Sep 17 00:00:00 2001 From: "Alexander Drozdov (Sasha)" Date: Mon, 20 Nov 2023 15:14:23 -0800 Subject: [PATCH] libs pytplot tests are added --- pyspedas/utilities/tests/libs_tests.py | 49 ++++++++++++++++++++++---- 1 file changed, 43 insertions(+), 6 deletions(-) diff --git a/pyspedas/utilities/tests/libs_tests.py b/pyspedas/utilities/tests/libs_tests.py index f4e74f1b..60bdcbac 100644 --- a/pyspedas/utilities/tests/libs_tests.py +++ b/pyspedas/utilities/tests/libs_tests.py @@ -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 @@ -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()