Skip to content

Commit 7dfbebb

Browse files
committed
refactor: rename status
Signed-off-by: ktro2828 <kotaro.uetake@tier4.jp>
1 parent f72c0f6 commit 7dfbebb

4 files changed

Lines changed: 33 additions & 55 deletions

File tree

docs/cli/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
## CLI Support
1+
# CLI Support
22

33
Following command line tools are supported:
44

docs/cli/t4sanity.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,11 @@ $ t4sanity <DATA_ROOT>
5959
STR008: ✅
6060
...
6161

62-
+-----------+---------+---------+-------+---------+----------+-------+----------+
63-
| DatasetID | Version | Status | Rules | Success | Failures | Skips | Warnings |
64-
+-----------+---------+---------+-------+---------+----------+-------+----------+
65-
| dataset1 | | SUCCESS | 49 | 43 | 0 | 2 | 4 |
66-
+-----------+---------+---------+-------+---------+----------+-------+----------+
62+
+-----------+---------+--------+--------+---------+----------+
63+
| DatasetID | Version | Passed | Failed | Skipped | Warnings |
64+
+-----------+---------+--------+--------+---------+----------+
65+
| dataset1 | | 49 | 0 | 2 | 3 |
66+
+-----------+---------+--------+--------+---------+----------+
6767
```
6868
6969
### Dump Results as JSON
@@ -86,8 +86,8 @@ Then a JSON file named `result.json` will be generated as follows:
8686
"name": "<RuleName: str>",
8787
"severity": "<WARNING/ERROR: str>",
8888
"description": "<Description: str>",
89-
"status": "<SUCCESS/FAILURE/SKIPPED: str>",
90-
"reasons": "<[<Reason1>, <Reason2>, ...]: [str; N] | null>" // Failure or skipped reasons, null if success
89+
"status": "<PASSED/FAILED/SKIPPED: str>",
90+
"reasons": "<[<Reason1>, <Reason2>, ...]: [str; N] | null>" // Failed or skipped reasons, null if passed
9191
},
9292
]
9393
}

t4_devkit/cli/sanity.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def main(
5656
serialized = serialize_dataclass(result)
5757
save_json(serialized, output)
5858

59-
if result.is_success(strict=strict):
59+
if result.is_passed(strict=strict):
6060
sys.exit(0)
6161
else:
6262
sys.exit(1)

t4_devkit/sanity/result.py

Lines changed: 24 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
class Status(str, Enum):
1818
"""Runtime outcome per checker."""
1919

20-
SUCCESS = "SUCCESS"
21-
FAILURE = "FAILURE"
20+
PASSED = "PASSED"
21+
FAILED = "FAILED"
2222
SKIPPED = "SKIPPED"
2323

2424

@@ -46,23 +46,23 @@ class Report:
4646
reasons: list[Reason] | None = field(default=None)
4747

4848
def __attrs_post_init__(self) -> None:
49-
if self.status == Status.SUCCESS:
50-
assert self.reasons is None, "Success report cannot have reasons"
49+
if self.status == Status.PASSED:
50+
assert self.reasons is None, "Passed report cannot have reasons"
5151
else:
52-
assert self.reasons is not None, "Non-success report must have reasons"
52+
assert self.reasons is not None, "Non-passed report must have reasons"
5353

54-
def is_success(self, *, strict: bool = False) -> bool:
55-
"""Check if the status is success."""
54+
def is_passed(self, *, strict: bool = False) -> bool:
55+
"""Check if the status is passed."""
5656
return (
57-
self.status == Status.SUCCESS
57+
self.status == Status.PASSED
5858
or self.is_skipped()
5959
or (not strict and self.severity.is_warning())
6060
)
6161

62-
def is_failure(self, *, strict: bool = False) -> bool:
63-
"""Check if the status is failure."""
64-
return (self.status == Status.FAILURE and self.severity.is_error()) or not (
65-
self.is_success(strict=strict) or self.is_skipped()
62+
def is_failed(self, *, strict: bool = False) -> bool:
63+
"""Check if the status is failed."""
64+
return (self.status == Status.FAILED and self.severity.is_error()) or not (
65+
self.is_passed(strict=strict) or self.is_skipped()
6666
)
6767

6868
def is_skipped(self) -> bool:
@@ -79,9 +79,9 @@ def make_report(
7979
) -> Report:
8080
"""Make a report for the given rule."""
8181
if reasons:
82-
return Report(id, name, severity, description, Status.FAILURE, reasons)
82+
return Report(id, name, severity, description, Status.FAILED, reasons)
8383
else:
84-
return Report(id, name, severity, description, Status.SUCCESS)
84+
return Report(id, name, severity, description, Status.PASSED)
8585

8686

8787
def make_skipped(
@@ -122,16 +122,16 @@ def from_context(cls, context: SanityContext, reports: list[Report]) -> Self:
122122
reports=reports,
123123
)
124124

125-
def is_success(self, *, strict: bool = False) -> bool:
126-
"""Return True if all reports are successful, False otherwise.
125+
def is_passed(self, *, strict: bool = False) -> bool:
126+
"""Return True if all reports are passed, False otherwise.
127127
128128
Args:
129129
strict (bool): Whether to consider warnings as failures.
130130
131131
Returns:
132-
True if all reports are successful, False otherwise.
132+
True if all reports are passed, False otherwise.
133133
"""
134-
return all(report.is_success(strict=strict) for report in self.reports)
134+
return all(report.is_passed(strict=strict) for report in self.reports)
135135

136136
def to_str(self, *, strict: bool = False) -> str:
137137
"""Return a string representation of the result.
@@ -144,7 +144,7 @@ def to_str(self, *, strict: bool = False) -> str:
144144
"""
145145
string = f"=== DatasetID: {self.dataset_id} ===\n"
146146
for report in self.reports:
147-
if not report.is_success(strict=strict):
147+
if not report.is_passed(strict=strict):
148148
string += f"\033[31m {report.id}:\033[0m\n"
149149
for reason in report.reasons or []:
150150
string += f"\033[31m - {reason}\033[0m\n"
@@ -171,41 +171,19 @@ def print_sanity_result(result: SanityResult, *, strict: bool = False) -> None:
171171
print(result.to_str(strict=strict))
172172

173173
# print summary result
174-
success = sum(1 for rp in result.reports if rp.is_success(strict=strict))
175-
failures = sum(1 for rp in result.reports if not rp.is_success(strict=strict))
176-
skips = sum(1 for rp in result.reports if rp.is_skipped())
174+
passed = sum(1 for rp in result.reports if rp.is_passed(strict=strict))
175+
failed = sum(1 for rp in result.reports if not rp.is_passed(strict=strict))
176+
skipped = sum(1 for rp in result.reports if rp.is_skipped())
177177

178178
# just count the number of warnings
179179
warnings = sum(1 for rp in result.reports if rp.severity.is_warning() and rp.reasons)
180180

181-
summary_rows = [
182-
[
183-
result.dataset_id,
184-
result.version,
185-
"\033[32mSUCCESS\033[0m"
186-
if result.is_success(strict=strict)
187-
else "\033[31mFAILURE\033[0m",
188-
len(result.reports),
189-
success,
190-
failures,
191-
skips,
192-
warnings,
193-
]
194-
]
181+
summary_rows = [[result.dataset_id, result.version, passed, failed, skipped, warnings]]
195182

196183
print(
197184
tabulate(
198185
summary_rows,
199-
headers=[
200-
"DatasetID",
201-
"Version",
202-
"Status",
203-
"Rules",
204-
"Success",
205-
"Failures",
206-
"Skips",
207-
"Warnings",
208-
],
186+
headers=["DatasetID", "Version", "Passed", "Failed", "Skipped", "Warnings"],
209187
tablefmt="pretty",
210188
),
211189
)

0 commit comments

Comments
 (0)