Skip to content

Commit ac2847d

Browse files
committed
feat: store reports as list instead of dict
Signed-off-by: ktro2828 <kotaro.uetake@tier4.jp>
1 parent ea3b717 commit ac2847d

4 files changed

Lines changed: 20 additions & 13 deletions

File tree

docs/tutorials/cli/t4sanity.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,15 +108,15 @@ Then a JSON file named `results.json` will be generated as follows:
108108
{
109109
"dataset_id": "<DatasetID: str>",
110110
"version": <Version: int>,
111-
"reports": {
112-
"<RuleID: str>": {
111+
"reports": [
112+
{
113113
"id": "<RuleID: str>",
114114
"name": "<RuleName: str>",
115115
"description": "<Description: str>",
116116
"status": "<SUCCESS/FAILURE/SKIPPED: str>",
117117
"reasons": "<[<Reason1>, <Reason2>, ...]: [str; N] | null>" // Failure or skipped reasons, null if success
118118
},
119-
}
119+
]
120120
}
121121
]
122122
```
@@ -126,5 +126,6 @@ Then a JSON file named `results.json` will be generated as follows:
126126
With `-e; --excludes` option enables us to exclude specific checks by specifying the **rule IDs or groups**:
127127
128128
```shell
129+
# Exclude STR001 and all FMT-relevant rules
129130
t4sanity <DB_PARENT> -e STR001 -e FMT
130131
```

t4_devkit/cli/sanity.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ def _run_sanity_check(
3636
def _print_table(results: list[SanityResult], *, detail: bool = False) -> str:
3737
summary_rows = []
3838
for result in results:
39-
success = sum(1 for rp in result.reports.values() if rp.is_success())
40-
failures = sum(1 for rp in result.reports.values() if rp.is_failure())
41-
skips = sum(1 for rp in result.reports.values() if rp.is_skipped())
39+
success = sum(1 for rp in result.reports if rp.is_success())
40+
failures = sum(1 for rp in result.reports if rp.is_failure())
41+
skips = sum(1 for rp in result.reports if rp.is_skipped())
4242
summary_rows.append(
4343
[
4444
result.dataset_id,

t4_devkit/sanity/result.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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
6874
class 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

t4_devkit/sanity/run.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,6 @@ def sanity_check(
2626
context = SanityContext.from_path(data_root, revision=revision)
2727

2828
checkers = CHECKERS.build(excludes=excludes)
29-
reports = {checker.id: checker(context) for checker in checkers}
29+
reports = [checker(context) for checker in checkers]
3030

3131
return SanityResult.from_context(context, reports)

0 commit comments

Comments
 (0)