Skip to content

Commit 07f7640

Browse files
authored
Merge pull request #130 from pysat/maint/nose_dep
MAINT: testing standards
2 parents 25f4a36 + 714bde7 commit 07f7640

File tree

9 files changed

+51
-101
lines changed

9 files changed

+51
-101
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ This project adheres to [Semantic Versioning](https://semver.org/).
1212
* Added manual test for pysat and pysatNASA Release Candidates
1313
* Added manual test for pysatModels RC pip install
1414
* Updated tests to new pysat and pytest standards
15+
* Added a cap for pysatNASA
1516
* Documentation
1617
* Added badges and instructions for PyPi and Zenodo
1718

README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
pysatModels handles model-centric data loading through pysat and contains a
1414
variety of tools to perform model-data analysis, including model validation.
1515

16-
Come join us on Slack! An invitation to the pysat workspace is available
16+
Come join us on Slack! An invitation to the pysat workspace is available
1717
in the 'About' section of the
1818
[pysat GitHub Repository.](https://github.com/pysat/pysat)
1919

@@ -27,13 +27,13 @@ examples on how to use the routines
2727
pysatModels uses common Python modules, as well as modules developed by and for
2828
the Space Physics community. This module officially supports Python 3.6+.
2929

30-
| Common modules | Community modules |
31-
| ------------------ | ----------------- |
32-
| numpy | pyForecastTools |
33-
| pandas >= 1.4.0 | pysat >= 3.0.4 |
34-
| requests | pysatNASA |
35-
| scipy | |
36-
| xarray | |
30+
| Common modules | Community modules |
31+
| ------------------ | ------------------ |
32+
| numpy | pyForecastTools |
33+
| pandas >= 1.4.0 | pysat >= 3.0.4 |
34+
| requests | pysatNASA <= 0.0.4 |
35+
| scipy | |
36+
| xarray | |
3737

3838
## Installation through PyPi
3939

docs/installation.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ the Space Physics community. This module officially supports Python 3.6+.
2424
Common modules Community modules
2525
============== =================
2626
numpy pysat
27-
pandas pyForecastTools
28-
requests
27+
pandas pysatNASA
28+
requests pyForecastTools
2929
scipy
3030
xarray
3131
============== =================
@@ -85,7 +85,7 @@ is set up, you may choose to register the the :py:mod:`pysatModel` model
8585

8686
.. code:: python
8787
88-
88+
8989
import pysat
9090
import pysatModels as pymod
9191

pysatModels/tests/test_methods_general.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@
1414
class TestMethodsGeneralLogging(object):
1515
"""Unit tests for log messages raised by general methods."""
1616

17-
def setup(self):
17+
def setup_method(self):
1818
"""Set up the unit test environment."""
1919
self.ch = logging.StreamHandler()
2020
self.ch.setLevel(logging.INFO)
2121
self.model = pysat.Instrument("pysat", "testmodel")
2222

2323
return
2424

25-
def teardown(self):
25+
def teardown_method(self):
2626
"""Clean up the unit test environment."""
2727

2828
del self.ch, self.model
@@ -50,7 +50,7 @@ def test_general_clean(self, caplog):
5050
class TestMethodsGeneralDownload(object):
5151
"""Unit tests for general methods handling downloads."""
5252

53-
def setup(self):
53+
def setup_method(self):
5454
"""Set up the unit test environment."""
5555
# TODO(#100): remove if-statement when it is always triggered
5656
tkwargs = {}
@@ -65,7 +65,7 @@ def setup(self):
6565

6666
return
6767

68-
def teardown(self):
68+
def teardown_method(self):
6969
"""Clean up the unit test environment."""
7070

7171
if os.path.isfile(self.out_file):

pysatModels/tests/test_models.py

Lines changed: 9 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -14,78 +14,27 @@
1414
import sys
1515
import tempfile
1616

17+
# Import the test classes from pysat
1718
import pysat
18-
from pysat.tests.instrument_test_class import InstTestClass
19+
from pysat.tests.classes import cls_instrument_library as clslib
1920

2021
import pysatModels
2122

2223
# Retrieve the lists of Model instruments and testing methods
23-
instruments = pysat.utils.generate_instrument_list(inst_loc=pysatModels.models)
24-
method_list = [func for func in dir(InstTestClass)
25-
if callable(getattr(InstTestClass, func))]
26-
27-
# Search tests for iteration via pytestmark, update instrument list
28-
for method in method_list:
29-
if hasattr(getattr(InstTestClass, method), 'pytestmark'):
30-
# Get list of names of pytestmarks
31-
mark_name = [mod_mark.name for mod_mark
32-
in getattr(InstTestClass, method).pytestmark]
33-
34-
# Add instruments from your library
35-
if 'all_inst' in mark_name:
36-
mark = pytest.mark.parametrize("inst_name", instruments['names'])
37-
getattr(InstTestClass, method).pytestmark.append(mark)
38-
elif 'download' in mark_name:
39-
mark = pytest.mark.parametrize("inst_dict",
40-
instruments['download'])
41-
getattr(InstTestClass, method).pytestmark.append(mark)
42-
elif 'no_download' in mark_name:
43-
mark = pytest.mark.parametrize("inst_dict",
44-
instruments['no_download'])
45-
getattr(InstTestClass, method).pytestmark.append(mark)
46-
47-
48-
class TestModels(InstTestClass):
24+
instruments = clslib.InstLibTests.initialize_test_package(
25+
clslib.InstLibTests, inst_loc=pysatModels.models)
26+
27+
28+
class TestModels(clslib.InstLibTests):
4929
"""Main class for instrument tests.
5030
5131
Note
5232
----
53-
Uses class level setup and teardown so that all tests use the same
54-
temporary directory. We do not want to geneate a new tempdir for each test,
55-
as the load tests need to be the same as the download tests.
33+
All standard tests, setup, and teardown inherited from the core pysat
34+
instrument test class.
5635
5736
"""
5837

59-
def setup_class(self):
60-
"""Initialize the testing setup once before all tests are run."""
61-
# Make sure to use a temporary directory so that the user setup is not
62-
# altered
63-
# TODO(#100): remove if-statement when it is always triggered
64-
tkwargs = {}
65-
if sys.version_info.major >= 3 and sys.version_info.minor >= 10:
66-
tkwargs = {"ignore_cleanup_errors": True}
67-
self.tempdir = tempfile.TemporaryDirectory(**tkwargs)
68-
self.saved_path = pysat.params['data_dirs']
69-
pysat.params.data['data_dirs'] = [self.tempdir.name]
70-
71-
# Assign the location of the model Instrument sub-modules
72-
self.inst_loc = pysatModels.models
73-
return
74-
75-
def teardown_class(self):
76-
"""Clean up downloaded files and parameters from tests."""
77-
78-
pysat.params.data['data_dirs'] = self.saved_path
79-
80-
# TODO(#100): Remove try/except when Python 3.10 is the lowest version
81-
try:
82-
self.tempdir.cleanup()
83-
except Exception:
84-
pass
85-
86-
del self.inst_loc, self.saved_path, self.tempdir
87-
return
88-
8938

9039
class TestSAMIPysatVersion(object):
9140
"""Test SAMI load code for pysat version differences across v3.0.2."""

pysatModels/tests/test_utils_convert.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def eval_xarray_output(inst, xdata):
6464
class TestUtilsConvertLoadModelXarray(object):
6565
"""Unit tests for `utils.convert.load_model_xarray`."""
6666

67-
def setup(self):
67+
def setup_method(self):
6868
"""Create a clean testing setup before each method."""
6969
self.ftime = pysat.instruments.pysat_testing_xarray._test_dates['']['']
7070
self.filename = "%Y-%m-%d.nofile"
@@ -76,7 +76,7 @@ def setup(self):
7676
self.xout = None
7777
self.temp_file = 'None'
7878

79-
def teardown(self):
79+
def teardown_method(self):
8080
"""Clean up test environment after each method."""
8181
if os.path.isfile(self.temp_file):
8282
os.remove(self.temp_file)
@@ -130,11 +130,11 @@ def test_load_inst(self, mkey, mval):
130130
class TestUtilsConvertPysatXarray(object):
131131
"""Unit tests for utils.convert.convert_pysat_to_xarray."""
132132

133-
def setup(self):
133+
def setup_method(self):
134134
"""Create a clean testing setup before each method."""
135135
self.ref_time = pysat.instruments.pysat_testing._test_dates['']['']
136136

137-
def teardown(self):
137+
def teardown_method(self):
138138
"""Clean up test environment after each method."""
139139
del self.ref_time
140140

pysatModels/tests/test_utils_extract.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
class TestUtilsExtractInstThroughMod(object):
2121
"""Unit tests for `instrument_view_through_model`."""
2222

23-
def setup(self):
23+
def setup_method(self):
2424
"""Set up the unit test environment for each method."""
2525

2626
self.inst = pysat.Instrument(platform='pysat', name='testing')
@@ -51,7 +51,7 @@ def setup(self):
5151
self.out = []
5252
return
5353

54-
def teardown(self):
54+
def teardown_method(self):
5555
"""Clean up the unit test environment after each method."""
5656

5757
del self.inst, self.model, self.input_args, self.out, self.input_kwargs
@@ -205,7 +205,7 @@ def test_success_for_some_already_ran_data(self, caplog):
205205
class TestUtilsExtractModObs(TestUtilsExtractInstThroughMod):
206206
"""Unit tests for `utils.extract.extract_modelled_observations`."""
207207

208-
def setup(self):
208+
def setup_method(self):
209209
"""Set up the unit test environment for each method."""
210210

211211
self.inst = pysat.Instrument(platform='pysat', name='testing')
@@ -233,7 +233,7 @@ def setup(self):
233233
self.out = []
234234
return
235235

236-
def teardown(self):
236+
def teardown_method(self):
237237
"""Clean up the unit test environment after each method."""
238238

239239
del self.inst, self.model, self.input_args, self.out, self.input_kwargs
@@ -351,7 +351,7 @@ def test_success_for_some_already_ran_data(self, caplog):
351351
class TestUtilsExtractModObsXarray(TestUtilsExtractModObs):
352352
"""Xarray unit tests for `utils.extract.extract_modelled_observations`."""
353353

354-
def setup(self):
354+
def setup_method(self):
355355
"""Set up the unit test environment for each method."""
356356

357357
self.inst = pysat.Instrument(platform='pysat', name='testing_xarray')
@@ -379,7 +379,7 @@ def setup(self):
379379
self.out = []
380380
return
381381

382-
def teardown(self):
382+
def teardown_method(self):
383383
"""Clean up the unit test environment after each method."""
384384

385385
del self.inst, self.model, self.input_args, self.out, self.input_kwargs
@@ -393,7 +393,7 @@ def teardown(self):
393393
class TestUtilsExtractModObsXarray2D(TestUtilsExtractModObs):
394394
"""Xarray unit tests for `utils.extract.extract_modelled_observations`."""
395395

396-
def setup(self):
396+
def setup_method(self):
397397
"""Set up the unit test environment for each method."""
398398

399399
self.inst = pysat.Instrument(platform='pysat', name='testing2d_xarray')
@@ -421,7 +421,7 @@ def setup(self):
421421
self.out = []
422422
return
423423

424-
def teardown(self):
424+
def teardown_method(self):
425425
"""Clean up the unit test environment after each method."""
426426

427427
del self.inst, self.model, self.input_args, self.out, self.input_kwargs
@@ -431,7 +431,7 @@ def teardown(self):
431431
class TestUtilsExtractInstModViewXarray(TestUtilsExtractInstThroughMod):
432432
"""Xarray unit tests for `instrument_view_through_model`."""
433433

434-
def setup(self):
434+
def setup_method(self):
435435
"""Run before every method to create a clean testing setup."""
436436

437437
self.inst = pysat.Instrument(platform='pysat', name='testing2d_xarray')
@@ -464,7 +464,7 @@ def setup(self):
464464

465465
return
466466

467-
def teardown(self):
467+
def teardown_method(self):
468468
"""Run after every method to clean up previous testing."""
469469

470470
del self.inst, self.model, self.input_args, self.out, self.input_kwargs
@@ -482,7 +482,7 @@ def teardown(self):
482482
class TestUtilsAltitudePressure(object):
483483
"""Unit tests for `utils.extract.instrument_altitude_to_model_pressure`."""
484484

485-
def setup(self):
485+
def setup_method(self):
486486
"""Set up the unit test environment for each method."""
487487

488488
self.inst = pysat.Instrument(platform='pysat', name='testing')
@@ -509,7 +509,7 @@ def setup(self):
509509
self.out = []
510510
return
511511

512-
def teardown(self):
512+
def teardown_method(self):
513513
"""Clean up the unit test environment after each method."""
514514

515515
del self.inst, self.model, self.input_args, self.out
@@ -618,7 +618,7 @@ def test_alternate_output_names(self):
618618
class TestUtilsAltitudePressureXarray(TestUtilsAltitudePressure):
619619
"""Xarray unit tests for `instrument_altitude_to_model_pressure`."""
620620

621-
def setup(self):
621+
def setup_method(self):
622622
"""Set up the unit test environment for each method."""
623623

624624
self.inst = pysat.Instrument(platform='pysat', name='testing2d_xarray')
@@ -645,7 +645,7 @@ def setup(self):
645645
self.out = []
646646
return
647647

648-
def teardown(self):
648+
def teardown_method(self):
649649
"""Clean up the unit test environment after each method."""
650650

651651
del self.inst, self.model, self.input_args, self.out
@@ -660,7 +660,7 @@ def teardown(self):
660660
class TestUtilsExtractInstModIrregView(object):
661661
"""Unit tests for `utils.extract.instrument_view_irregular_model`."""
662662

663-
def setup(self):
663+
def setup_method(self):
664664
"""Run before every method to create a clean testing setup."""
665665

666666
self.inst = pysat.Instrument(platform='pysat', name='testing',
@@ -689,7 +689,7 @@ def setup(self):
689689

690690
return
691691

692-
def teardown(self):
692+
def teardown_method(self):
693693
"""Run after every method to clean up previous testing."""
694694

695695
del self.inst, self.model, self.input_args, self.out, self.in_kwargs
@@ -773,7 +773,7 @@ def test_bad_kwarg_input(self, bad_key, bad_val, err_msg):
773773
class TestUtilsExtractInstModIrregViewXarray(TestUtilsExtractInstModIrregView):
774774
"""Xarray unit tests for `instrument_view_irregular_model`."""
775775

776-
def setup(self):
776+
def setup_method(self):
777777
"""Run before every method to create a clean testing setup."""
778778

779779
self.inst = pysat.Instrument(platform='pysat', name='testing2d_xarray',
@@ -802,7 +802,7 @@ def setup(self):
802802

803803
return
804804

805-
def teardown(self):
805+
def teardown_method(self):
806806
"""Run after every method to clean up previous testing."""
807807

808808
del self.inst, self.model, self.input_args, self.out, self.in_kwargs

0 commit comments

Comments
 (0)