Commit e1c15480 authored by Amir MOHAMMADI's avatar Amir MOHAMMADI
Browse files

improve error handling

parent 2ec484bb
Pipeline #17515 failed with stage
in 37 minutes and 23 seconds
......@@ -26,7 +26,7 @@ class FailSafe(Annotator):
def annotate(self, sample, **kwargs):
if 'annotations' not in kwargs or kwargs['annotations'] is None:
kwargs['annotations'] = None
kwargs['annotations'] = {}
for annotator in self.annotators:
try:
annotations = annotator(sample, **kwargs)
......
......@@ -77,9 +77,9 @@ def annotate(database, annotator, output_dir, force, array, **kwargs):
outpath = biofile.make_path(output_dir, '.json')
if isfile(outpath):
if force:
logger.debug("Overwriting the annotations file `%s'", outpath)
logger.info("Overwriting the annotations file `%s'", outpath)
else:
logger.debug("The annotation `%s' already exists", outpath)
logger.info("The annotation `%s' already exists", outpath)
continue
logger.info(
......
from random import random
from bob.bio.base.annotator import FailSafe, Callable
def simple_annotator(image, **kwargs):
return {
'topleft': (0, 0),
'bottomright': image.shape,
}
def moody_annotator(image, **kwargs):
if random() < 0.5:
return {
'topleft': (0, 0),
}
else:
return {
'topleft': (0, 0),
'bottomright': image.shape,
}
def fail_annotator(image, **kwargs):
......@@ -14,6 +20,6 @@ def fail_annotator(image, **kwargs):
annotator = FailSafe(
[Callable(fail_annotator),
Callable(simple_annotator)],
Callable(moody_annotator)],
required_keys=['topleft', 'bottomright'],
)
......@@ -13,7 +13,13 @@ def test_annotate():
runner = CliRunner()
result = runner.invoke(annotate, args=(
'-d', 'dummy', '-a', 'dummy', '-o', tmp_dir))
assert result.exit_code == 0, result.output
assertion_error_message = (
'Command exited with this output: `{}\' \n'
'If the output is empty, you can run this script locally to see '
'what is wrong:\n'
'bin/bob bio annotate -vvv --force -d dummy -a dummy -o /tmp/temp_annotations'
''.format(result.output))
assert result.exit_code == 0, assertion_error_message
# test if annotations exist
for dirpath, dirnames, filenames in os.walk(tmp_dir):
......
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