Commit 276e0ba5 authored by BorjaEst's avatar BorjaEst
Browse files

Edit test exceptions for loading

parent b1fe6955
......@@ -15,7 +15,7 @@ sources_example = "tests/sources_example.yaml"
sources_err = "tests/sources_err.yaml"
available_configurations = {
'correct': {sources_example},
'with_errors': {sources_err}
'errors': {sources_err}
}
# Sources
......@@ -34,17 +34,26 @@ vmro3_models = {
'SourceMerged_ModelVMRO3',
'SourceMerged_ModelALL'
}
error_models = {
'ModelBadVar',
'ModelBadKey',
'ModelBadName',
'ModelBadPath',
'ModelMissingCoords',
'ModelBadCoords',
'ModelExtraCoords'
}
available_models = {
'all': tco3_models | vmro3_models,
'with_tco3': tco3_models,
'only_tco3': tco3_models - vmro3_models,
'with_vmro3': vmro3_models,
'only_vmro3': vmro3_models - tco3_models
'only_vmro3': vmro3_models - tco3_models,
'errors': error_models
}
# session fixtures ---------------------------------------------------
# session fixtures ---------------------------------------------------
@pytest.fixture(scope='session')
def data_dir(tmpdir_factory):
data_dir = tmpdir_factory.mktemp("data")
......@@ -91,10 +100,14 @@ def config_dict(config):
@pytest.fixture(scope='session')
def load_model(data_dir, config_dict, model):
model_configuration = config_dict[model]
def model_config(config_dict, model):
return config_dict[model]
@pytest.fixture(scope='session')
def load_model(data_dir, model_config):
with o3skim.utils.cd(data_dir):
return o3skim.loading(**model_configuration)
return o3skim.loading(**model_config)
@pytest.fixture(scope='session')
......@@ -204,6 +217,12 @@ def metadata_file_content(metadata_dir, save_metadata):
# function fixtures -------------------------------------------------
@pytest.fixture()
def data_cd(data_dir):
with o3skim.utils.cd(data_dir):
yield None
@pytest.fixture()
def output_cd(output_dir):
with o3skim.utils.cd(output_dir):
......
SourceSplit:
ModelBadVar:
badvar_zm:
name: tco3
paths: SourceSplit/tco3_????.nc
coordinates:
time: time
lat: lat
lon: lon
ModelBadName:
tco3_zm:
name: NonExistingName
paths: SourceSplit/tco3_????.nc
coordinates:
time: time
lat: lat
lon: lon
ModelBadPath:
tco3_zm:
name: tco3
paths: SourceSplit/no_file_????.nc
coordinates:
time: time
lat: lat
ModelMissingCoords:
tco3_zm:
name: tco3
paths: SourceSplit/tco3_????.nc
coordinates:
time: time
lat: lat
ModelBadCoords:
tco3_zm:
name: tco3
paths: SourceSplit/tco3_????.nc
coordinates:
time: time
lat: lat
longitude: lon
ModelExtraCoords:
tco3_zm:
name: tco3
paths: SourceSplit/tco3_????.nc
coordinates:
time: time
plev: plev
lat: lat
lon: lon
ModelBadVar:
badvar_zm:
name: tco3
paths: SourceSplit/tco3_????.nc
coordinates:
time: time
lat: lat
lon: lon
ModelBadKey:
tco3_zm:
badKey: ABadKeyName
paths: SourceSplit/tco3_????.nc
coordinates:
time: time
lat: lat
lon: lon
ModelBadName:
tco3_zm:
name: NonExistingName
paths: SourceSplit/tco3_????.nc
coordinates:
time: time
lat: lat
lon: lon
ModelBadPath:
tco3_zm:
name: tco3
paths: SourceSplit/no_file_????.nc
coordinates:
time: time
lat: lat
ModelMissingCoords:
tco3_zm:
name: tco3
paths: SourceSplit/tco3_????.nc
coordinates:
time: time
lat: lat
ModelBadCoords:
tco3_zm:
name: tco3
paths: SourceSplit/tco3_????.nc
coordinates:
time: time
lat: lat
longitude: lon
ModelExtraCoords:
tco3_zm:
name: tco3
paths: SourceSplit/tco3_????.nc
coordinates:
time: time
plev: plev
lat: lat
lon: lon
"""Pytest module to test sources as blackbox."""
import o3skim
import pytest
import tests.conftest as conftest
......@@ -18,6 +19,38 @@ class TestO3CommonsLoad:
assert metadata["meta_2"]["meta_21"] == "Sub-metadata from Model"
@pytest.mark.parametrize('config', configs['errors'], indirect=True)
class TestExceptions:
@pytest.mark.parametrize('model', ['ModelBadVar'], indirect=True)
def test_BadVariable(self, data_cd, model_config):
pytest.raises(TypeError, o3skim.loading, **model_config)
@pytest.mark.parametrize('model', ['ModelBadKey'], indirect=True)
def test_BadFieldKey(self, data_cd, model_config):
pytest.raises(TypeError, o3skim.loading, **model_config)
@pytest.mark.parametrize('model', ['ModelMissingCoords'], indirect=True)
def test_MissingCoordinate(self, data_cd, model_config):
pytest.raises(TypeError, o3skim.loading, **model_config)
@pytest.mark.parametrize('model', ['ModelBadCoords'], indirect=True)
def test_WrongCoordinate(self, data_cd, model_config):
pytest.raises(TypeError, o3skim.loading, **model_config)
@pytest.mark.parametrize('model', ['ModelExtraCoords'], indirect=True)
def test_ExtraCoordinate(self, data_cd, model_config):
pytest.raises(TypeError, o3skim.loading, **model_config)
@pytest.mark.parametrize('model', ['ModelBadName'], indirect=True)
def test_NotFoundVariable(self, data_cd, model_config):
pytest.raises(KeyError, o3skim.loading, **model_config)
@pytest.mark.parametrize('model', ['ModelBadPath'], indirect=True)
def test_NotFoundDataset(self, data_cd, model_config):
pytest.raises(OSError, o3skim.loading, **model_config)
@pytest.mark.parametrize('config', configs['correct'], indirect=True)
class TestTCO3Load:
......
Markdown is supported
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