diff --git a/src/cdf/core/component/pipeline.py b/src/cdf/core/component/pipeline.py index d90f411..a3e38d9 100644 --- a/src/cdf/core/component/pipeline.py +++ b/src/cdf/core/component/pipeline.py @@ -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 ] @@ -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, reason = result_struct, "No message" + elif isinstance(result_struct, tuple): + result, reason = 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=reason)) + elif result is False: + raise ValueError(tpl.format(nr=nr, state="FAIL", message=reason)) + elif result is None: + print(tpl.format(nr=nr, state="SKIP", message=reason)) + else: + raise ValueError(f"Invalid return value for test: {result}") diff --git a/src/cdf/core/workspace.py b/src/cdf/core/workspace.py index ea83968..289300f 100644 --- a/src/cdf/core/workspace.py +++ b/src/cdf/core/workspace.py @@ -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