Skip to content

Commit

Permalink
Merge pull request #16 from pysat/inst_test_develop-3
Browse files Browse the repository at this point in the history
MAINT: instrument tests update
  • Loading branch information
aburrell committed Oct 9, 2020
2 parents 8b9a79b + 67c802b commit 00c3e3b
Showing 1 changed file with 37 additions and 20 deletions.
57 changes: 37 additions & 20 deletions pysatMadrigal/tests/test_instruments.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,34 @@
import tempfile
import pytest

import pysatMadrigal
from pysat.tests.instrument_test_class import generate_instrument_list
import pysat
from pysat.utils import generate_instrument_list
from pysat.tests.instrument_test_class import InstTestClass

instruments = generate_instrument_list(package=pysatMadrigal.instruments)
import pysatMadrigal

instruments = generate_instrument_list(inst_loc=pysatMadrigal.instruments)
method_list = [func for func in dir(InstTestClass)
if callable(getattr(InstTestClass, func))]

# Search tests for iteration via pytestmark, update instrument list
for method in method_list:
if hasattr(getattr(InstTestClass, method), 'pytestmark'):
# Get list of names of pytestmarks
Nargs = len(getattr(InstTestClass, method).pytestmark)
names = [getattr(InstTestClass, method).pytestmark[j].name
for j in range(0, Nargs)]
mark_name = [mod_mark.name for mod_mark
in getattr(InstTestClass, method).pytestmark]

# Add instruments from your library
if 'all_inst' in names:
mark = pytest.mark.parametrize("name", instruments['names'])
if 'all_inst' in mark_name:
mark = pytest.mark.parametrize("inst_name", instruments['names'])
getattr(InstTestClass, method).pytestmark.append(mark)
elif 'download' in names:
mark = pytest.mark.parametrize("inst", instruments['download'])
elif 'download' in mark_name:
mark = pytest.mark.parametrize("inst_dict",
instruments['download'])
getattr(InstTestClass, method).pytestmark.append(mark)
elif 'no_download' in names:
mark = pytest.mark.parametrize("inst", instruments['no_download'])
elif 'no_download' in mark_name:
mark = pytest.mark.parametrize("inst_dict",
instruments['no_download'])
getattr(InstTestClass, method).pytestmark.append(mark)

# remote_file_list not functional in current code. Disabling for now
Expand All @@ -33,11 +38,23 @@


class TestInstruments(InstTestClass):

def setup(self):
"""Runs before every method to create a clean testing setup."""
self.package = pysatMadrigal.instruments

def teardown(self):
"""Runs after every method to clean up previous testing."""
del self.package
def setup_class(self):
"""Runs once before the tests to initialize the testing setup
"""
# Make sure to use a temporary directory so that the user's setup is
# not altered
self.tempdir = tempfile.TemporaryDirectory()
self.saved_path = pysat.data_dir
pysat.utils.set_data_dir(self.tempdir.name, store=False)

# Developers for instrument libraries should update the following line
# to point to their own subpackage location, e.g.,
# self.inst_loc = mypackage.instruments
self.inst_loc = pysatMadrigal.instruments

def teardown_class(self):
"""Runs after every method to clean up previous testing
"""
pysat.utils.set_data_dir(self.saved_path, store=False)
self.tempdir.cleanup()
del self.inst_loc, self.saved_path, self.tempdir

0 comments on commit 00c3e3b

Please sign in to comment.