Commit a88a98a0 authored by BorjaEst's avatar BorjaEst
Browse files

Catch 100% coverage

parent 46612d9c
......@@ -41,7 +41,6 @@ def cmdline_args():
return(p.parse_args())
@utils.return_on_failure("Error processing model")
def skim_process(name, operations, split_by, configuration):
# Process start
logging.info("Process start for model %s", name)
......@@ -88,16 +87,16 @@ if __name__ == '__main__':
# Configuration load
logging.info("Looking for config at: '%s'", args.sources_file)
config = utils.load(args.sources_file)
configuration = utils.load(args.sources_file)
# Processing loop
logging.info("Processing loop for models")
for model_name in config:
skim_process(
name=model_name,
operations=args.operations,
split_by=args.split_by,
configuration=config[model_name])
for model in configuration:
try:
skim_process(model, args.operations, args.split_by,
configuration[model])
except Exception as e:
logging.error("Error processing model", exc_info=e)
# End of program
logging.info("End of program")
......@@ -33,29 +33,6 @@ def cd(dir):
logger.debug("Restoring directory: '%s'", prevdir)
def return_on_failure(message, default=None):
"""Decorator to do not break but log. Note that the error stack
is printed as well to do not lose relevant information.
:param message: Additional message to log when the function fails.
:type message: str
:param default: Value to return if fails.
:type default: any or None, optional
"""
def decorate(function):
def applicator(*args, **kwargs):
try:
return function(*args, **kwargs)
except:
# Log error with stack using root (not utils)
logging.error(message, exc_info=True)
return default
applicator.__doc__ = function.__doc__
return applicator
return decorate
def load(yaml_file):
"""Loads the .yaml file and returns a python dictionary with all
the yaml keys and values. Note a yaml file can have key:values
......
"""Pytest module to test sources as blackbox."""
import o3skim
import pytest
import tests.conftest as conftest
......@@ -41,3 +42,12 @@ class TestByDecade:
def test_splitted_datasets(self, splitted_ds):
decades = [y for y in conftest.year_line if y % 10 == 0]
assert len(splitted_ds) == len(decades)
@pytest.mark.parametrize('config', configs['correct'], indirect=True)
@pytest.mark.parametrize('model', models['all'], indirect=True)
@pytest.mark.parametrize('groupby', ['unknown'], indirect=True)
class TestExceptions:
def test_BadGroup(self, dataset, groupby):
pytest.raises(KeyError, o3skim.group, dataset, groupby)
"""Pytest module to test sources as blackbox."""
import itertools
import o3skim
import pytest
import tests.conftest as conftest
......@@ -26,6 +27,15 @@ class TestCommon:
assert dataset[o3var].attrs == processed[o3var].attrs
@pytest.mark.parametrize('config', configs['correct'], indirect=True)
@pytest.mark.parametrize('model', models['all'], indirect=True)
@pytest.mark.parametrize('actions', [['unknown_operation']], indirect=True)
class TestExceptions:
def test_BadOperation(self, dataset, actions):
pytest.raises(KeyError, o3skim.processing, dataset, actions)
@pytest.mark.parametrize('config', configs['correct'], indirect=True)
@pytest.mark.parametrize('model', models['all'], indirect=True)
class TestLonMean:
......
"""Pytest module to test sources as blackbox."""
import os
from numpy.core.fromnumeric import var
import o3skim
import pytest
import tests.conftest as conftest
import xarray as xr
......@@ -35,3 +35,12 @@ class TestMetadataSaving:
def test_content(self, metadata, metadata_file_content):
assert metadata == metadata_file_content
@pytest.mark.parametrize('config', configs['correct'], indirect=True)
@pytest.mark.parametrize('model', models['all'], indirect=True)
@pytest.mark.parametrize('groupby', ['unknown'], indirect=True)
class TestExceptions:
def test_BadGroup(self, output_cd, dataset, groupby):
pytest.raises(KeyError, o3skim.saving, dataset, groupby)
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