Commit ad300b89 authored by BorjaEst's avatar BorjaEst
Browse files

Update blackbox tests for new conditions

parent a47a2a73
......@@ -41,28 +41,23 @@ def data_dir(tmpdir_factory):
# Source Tests ------------------------------------------------------
@pytest.fixture(scope='module')
def source_config(request, data_dir):
def source_name(request):
source_name = request.param
yield source_name, config[source_name]
yield source_name
@pytest.fixture(scope='class')
def source(source_config):
source_name, collections = source_config
yield o3skim.Source(source_name, collections)
def source(source_name, data_dir):
yield o3skim.Source(source_name, config[source_name])
@pytest.mark.parametrize('source_config', sources, indirect=True)
@pytest.mark.parametrize('source_name', sources, indirect=True)
class TestSource:
def test_constructor(self, source_config):
source_name, collections = source_config
source = o3skim.Source(source_name, collections)
def test_constructor(self, source_name, data_dir):
source = o3skim.Source(source_name, config[source_name])
assert type(source.name) is str
assert type(source.models) is list
for model in source.models:
assert isinstance(source[model], o3skim.Model)
assert source[model].time.size != 0
def test_skimming(self, source):
assert None == source.skim(groupby=None)
......@@ -72,48 +67,56 @@ class TestSource:
# Model Tests ------------------------------------------------------
@pytest.fixture(scope='class')
def model_config(request, source_config):
_, source_config = source_config
def model_name(request):
model_name = request.param
yield model_name, source_config[model_name]
yield model_name
@pytest.fixture(scope='class')
def model(model_config):
_, specifications = model_config
yield o3skim.Model(specifications)
def model(source, model_name):
yield source[model_name]
@pytest.mark.parametrize('source_config', sources, indirect=True)
@pytest.mark.parametrize('source_name', sources, indirect=True)
class TestModel:
@pytest.mark.parametrize('model_config', models, indirect=True)
def test_constructor(self, model_config):
_model_name, specifications = model_config
model = o3skim.Model(specifications)
@pytest.mark.parametrize('model_name', models, indirect=True)
def test_model_properties(self, model):
assert isinstance(model, xarray.Dataset)
assert model.time.size != 0
@pytest.mark.parametrize('model_config', models_tco3, indirect=True)
@pytest.mark.parametrize('model_name', ['ModelTCO3'], indirect=True)
def test_tco3_coordinates(self, model):
assert 'time' in model["tco3_zm"].coords
assert 'lat' in model["tco3_zm"].coords
assert not 'plev' in model["tco3_zm"].coords
assert not 'lon' in model["tco3_zm"].coords
assert 'time' in model.coords
assert not 'plev' in model.coords
assert 'lat' in model.coords
assert 'lon' in model.coords
@pytest.mark.parametrize('model_config', models_vmro, indirect=True)
@pytest.mark.parametrize('model_name', ['ModelVMRO3'], indirect=True)
def test_vmro3_coordinates(self, model):
assert 'time' in model["vmro3_zm"].coords
assert 'lat' in model["vmro3_zm"].coords
assert 'plev' in model["vmro3_zm"].coords
assert not 'lon' in model["vmro3_zm"].coords
assert 'time' in model.coords
assert 'plev' in model.coords
assert 'lat' in model.coords
assert 'lon' in model.coords
@pytest.mark.parametrize('model_name', ['ModelALL'], indirect=True)
def test_all_coordinates(self, model):
assert 'time' in model.coords
assert 'plev' in model.coords
assert 'lat' in model.coords
assert 'lon' in model.coords
# Skimming Tests ----------------------------------------------------
@pytest.fixture(scope='class')
def groupby(request):
return request.param
@pytest.fixture(scope='class')
def skimmed(request, source):
groupby = request.param
output_dir = source.name + "_group_" + str(groupby)
def skimmed(groupby, source):
output_dir = "{}_groupby_{}".format(source.name, groupby)
os.mkdir(output_dir)
with o3skim.utils.cd(output_dir):
source.skim(groupby=groupby)
......@@ -121,52 +124,51 @@ def skimmed(request, source):
@pytest.fixture(scope='class')
def skimmed_model(model_config, skimmed):
def skimmed_model(model_name, skimmed):
source_name = skimmed
model_name, _ = model_config
with o3skim.utils.cd(source_name + "_" + model_name):
yield source_name, model_name
@pytest.mark.parametrize('source_config', sources, indirect=True)
@pytest.mark.parametrize('skimmed', [None], indirect=True)
@pytest.mark.parametrize('source_name', sources, indirect=True)
@pytest.mark.parametrize('groupby', [None], indirect=True)
class TestSkimming_NoGroup:
@pytest.mark.parametrize('model_config', models_tco3, indirect=True)
@pytest.mark.parametrize('model_name', models_tco3, indirect=True)
def test_skimmed_tco3(self, skimmed_model):
assert os.path.isfile("tco3_zm.nc")
@pytest.mark.parametrize('model_config', models_vmro, indirect=True)
@pytest.mark.parametrize('model_name', models_vmro, indirect=True)
def test_skimmed_vmro3(self, skimmed_model):
assert os.path.isfile("vmro3_zm.nc")
@pytest.mark.parametrize('source_config', sources, indirect=True)
@pytest.mark.parametrize('skimmed', ['year'], indirect=True)
@pytest.mark.parametrize('source_name', sources, indirect=True)
@pytest.mark.parametrize('groupby', ['year'], indirect=True)
class TestSkimming_ByYear:
@pytest.mark.parametrize('model_config', models_tco3, indirect=True)
@pytest.mark.parametrize('model_name', models_tco3, indirect=True)
def test_skimmed_tco3(self, skimmed_model):
for y in year_line:
assert os.path.isfile("tco3_zm_{}-{}.nc".format(y, y + 1))
@pytest.mark.parametrize('model_config', models_vmro, indirect=True)
@pytest.mark.parametrize('model_name', models_vmro, indirect=True)
def test_skimmed_vmro3(self, skimmed_model):
for y in year_line:
assert os.path.isfile("vmro3_zm_{}-{}.nc".format(y, y + 1))
@pytest.mark.parametrize('source_config', sources, indirect=True)
@pytest.mark.parametrize('skimmed', ['decade'], indirect=True)
@pytest.mark.parametrize('source_name', sources, indirect=True)
@pytest.mark.parametrize('groupby', ['decade'], indirect=True)
class TestSkimming_ByDecade:
@pytest.mark.parametrize('model_config', models_tco3, indirect=True)
@pytest.mark.parametrize('model_name', models_tco3, indirect=True)
def test_skimmed_tco3(self, skimmed_model):
for y in year_line:
if y % 10 == 0:
assert os.path.isfile("tco3_zm_{}-{}.nc".format(y, y + 10))
@pytest.mark.parametrize('model_config', models_vmro, indirect=True)
@pytest.mark.parametrize('model_name', models_vmro, indirect=True)
def test_skimmed_vmro3(self, skimmed_model):
for y in year_line:
if y % 10 == 0:
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment