Skip to content

Commit

Permalink
adding a warning if tasks are returning non-integer result types.
Browse files Browse the repository at this point in the history
  • Loading branch information
toumorokoshi committed Mar 20, 2017
1 parent cc1c883 commit 937c511
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
10 changes: 10 additions & 0 deletions tests/tasks/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,13 @@ def bar(build):
t.append(bar, foo)
assert t.run("bar", build) == 1
assert x == ["bar"]


def test_non_integer_result_types_are_considered_passing(tmpdir, build):
t = Tasks()

def foo(build):
return "oogecuaenuc"

t.add(foo)
assert t.run("foo", build) == 0
19 changes: 17 additions & 2 deletions uranium/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,9 @@ def _run(self, name_or_func, build):
with build.as_current_build():
self._execute_prepends_for(name, build)
result = func(build)
if result is not None and result != 0:
raise ExitCodeException(name, int(result))
result = _coerce_to_int(name, result)
if result != 0:
raise ExitCodeException(name, result)
self._execute_appends_for(name, build)

def _execute_prepends_for(self, task_name, build):
Expand Down Expand Up @@ -81,3 +82,17 @@ def _extract_name(name_or_func):
if is_callable(name_or_func):
return name_or_func.__name__
return name_or_func


def _coerce_to_int(task_name, maybe_int):
if maybe_int is None:
maybe_int = 0
try:
maybe_int = int(maybe_int)
except ValueError:
LOGGER.warn(
"non-integer or none result received from task '{0}'".format(task_name) +
". Non-integer results are not valid and default to passing."
)
maybe_int = 0
return maybe_int

0 comments on commit 937c511

Please sign in to comment.