@@ -39,6 +39,12 @@ class Report:
3939 status : Status
4040 reasons : list [Reason ] | None = field (default = None )
4141
42+ def __attrs_post_init__ (self ) -> None :
43+ if self .is_success ():
44+ assert self .reasons is None , "Success report cannot have reasons"
45+ else :
46+ assert self .reasons is not None , "Failure report must have reasons"
47+
4248 def is_success (self ) -> bool :
4349 return self .status == Status .SUCCESS
4450
@@ -68,10 +74,10 @@ def make_failure(id: RuleID, name: RuleName, description: str, reasons: list[Rea
6874class SanityResult :
6975 dataset_id : str
7076 version : str | None
71- reports : dict [ str , Report ]
77+ reports : list [ Report ]
7278
7379 @classmethod
74- def from_context (cls , context : SanityContext , reports : dict [ RuleID , Report ]) -> Self :
80+ def from_context (cls , context : SanityContext , reports : list [ Report ]) -> Self :
7581 return cls (
7682 dataset_id = context .dataset_id .value_or ("UNKNOWN" ),
7783 version = context .version .value_or (None ),
@@ -80,15 +86,15 @@ def from_context(cls, context: SanityContext, reports: dict[RuleID, Report]) ->
8086
8187 def __repr__ (self ) -> str :
8288 string = f"=== DatasetID: { self .dataset_id } ===\n "
83- for id , report in self .reports . items () :
89+ for report in self .reports :
8490 if report .is_failure ():
85- string += f"\033 [31m { id } :\033 [0m\n "
91+ string += f"\033 [31m { report . id } :\033 [0m\n "
8692 for reason in report .reasons or []:
8793 string += f"\033 [31m - { reason } \033 [0m\n "
8894 elif report .is_skipped ():
89- string += f"\033 [33m { id } :\033 [0m\n "
95+ string += f"\033 [33m { report . id } :\033 [0m\n "
9096 for reason in report .reasons or []:
9197 string += f"\033 [33m - { reason } \033 [0m\n "
9298 else :
93- string += f"\033 [32m { id } : ✅\033 [0m\n "
99+ string += f"\033 [32m { report . id } : ✅\033 [0m\n "
94100 return string
0 commit comments