Skip to content

Commit

Permalink
feat: allow more returns from pipeline tests
Browse files Browse the repository at this point in the history
  • Loading branch information
z3z1ma committed Aug 20, 2024
1 parent 7f965c5 commit 11afa91
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
22 changes: 19 additions & 3 deletions src/cdf/core/component/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
t.Callable[..., "LoadInfo"],
t.Callable[..., t.Iterator["LoadInfo"]],
], # run
t.List[t.Callable[..., None]], # tests
t.List[t.Callable[..., t.Optional[t.Union[bool, t.Tuple[bool, str]]]]], # tests
]


Expand Down Expand Up @@ -43,5 +43,21 @@ def run_tests(self) -> None:
_, _, tests = self.main()
if not tests:
raise ValueError("No tests found for pipeline")
for test in tests:
test()
tpl = "{nr}. {message} ({state})"
for nr, test in enumerate(tests, 1):
result_struct = test()
if isinstance(result_struct, bool) or result_struct is None:
result, message = result_struct, "No message"
elif isinstance(result_struct, tuple):
result, message = result_struct
else:
raise ValueError(f"Invalid return type for test: {result_struct}")

if result is True:
print(tpl.format(nr=nr, state="PASS", message=message))
elif result is False:
raise ValueError(tpl.format(nr=nr, state="FAIL", message=message))
elif result is None:
print(tpl.format(nr=nr, state="SKIP", message=message))
else:
raise ValueError(f"Invalid return value for test: {result}")
6 changes: 5 additions & 1 deletion src/cdf/core/workspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,11 @@ def run():
)
return load

return pipeline, run, []
def test():
print("Do some testing")
return True, "Validated all columns are present in resource."

return pipeline, run, [test]

def ff_provider():
return 1
Expand Down

0 comments on commit 11afa91

Please sign in to comment.