Skip to content

Commit

Permalink
chore: improve test results parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
z3z1ma committed Sep 1, 2024
1 parent d889d86 commit 3d0c8bd
Showing 1 changed file with 26 additions and 11 deletions.
37 changes: 26 additions & 11 deletions src/cdf/core/component/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@
from dlt.common.pipeline import LoadInfo
from dlt.pipeline.pipeline import Pipeline as DltPipeline

_GRN = "\033[32;1m"
_YLW = "\033[33;1m"
_RED = "\033[31;1m"
_CLR = "\033[0m"

TEST_RESULT_MAP = {
None: f"{_YLW}SKIP{_CLR}",
True: f"{_GRN}PASS{_CLR}",
False: f"{_RED}FAIL{_CLR}",
}

DataPipelineProto = t.Tuple[
"DltPipeline",
Expand All @@ -32,9 +42,16 @@ def __call__(self, *args: t.Any, **kwargs: t.Any) -> t.List["LoadInfo"]:
return list(runner())
return [t.cast("LoadInfo", runner())]

run = __call__

def unwrap(self) -> "DltPipeline":
"""Get the dlt pipeline object."""
pipeline, _, _ = self.main()
return pipeline

def get_schemas(self, destination: t.Optional["DltDestination"] = None):
"""Get the schemas for the pipeline."""
pipeline, _, _ = self.main()
pipeline = self.unwrap()
pipeline.sync_destination(destination=destination)
return pipeline.schemas

Expand All @@ -52,15 +69,13 @@ def run_tests(self) -> None:
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, tot=tot, state="PASS", message=reason))
elif result is False:
raise ValueError(
tpl.format(nr=nr, tot=tot, state="FAIL", message=reason)
f"Invalid return type `{type(result_struct)}`, expected none, bool, or tuple(bool, str)"
)
elif result is None:
print(tpl.format(nr=nr, state="SKIP", tot=tot, message=reason))
else:
raise ValueError(f"Invalid return value for test: {result}")
if result not in TEST_RESULT_MAP:
raise ValueError(f"Invalid return status for test: `{result}`")
print(
tpl.format(
nr=nr, tot=tot, state=TEST_RESULT_MAP[result], message=reason
)
)

0 comments on commit 3d0c8bd

Please sign in to comment.