Skip to content

Latest commit

 

History

History
73 lines (52 loc) · 2.14 KB

File metadata and controls

73 lines (52 loc) · 2.14 KB

Sanity Check

Quick Start

sanity_check(...) function performs a series of sanity checks to ensure the integrity of the dataset.

About the defined rules, please refer to requirement.md.

from t4_devkit.common import save_json, serialize_dataclass
from t4_devkit.sanity import sanity_check, print_sanity_result


result = sanity_check("<path/to/dataset>")

# display detailed results and summary
print_sanity_result(result)

# save result to JSON file if you want
save_json(serialize_dataclass(result), "result.json")

How to Add New Checkers

The following diagram shows the logic of the checkers:

flowchart LR
    Start --> A{Can skip?}
    A --> |Yes| B[Skip check and <br/>returns skipped report]
    A --> |No| C[Perform check]
    C --> D{Failed and --fix=True?}
    D --> |Yes| E[Fix issues]
    E --> F[Return report]
    D --> |No| F
Loading

All checkers must follow:

  • Implement a class that inherits from Checker class.
  • Its ID must be unique and belong to one of RuleGroup enum.
  • Register the checker using CHECKERS.register() decorator.
  • Override the check(...) -> list[Reason] | None method to perform the specific check.
  • [OPTIONAL] The following methods can be overridden if needed:
    • Override can_skip(...) -> Maybe[Reason] method to determine whether the checker can be skipped.
    • Override fix(...) -> bool method to fix the issue if possible.
from __future__ import annotations

from typing import TYPE_CHECKING

from t4_devkit.sanity.checker import Checker, RuleID, RuleName, Severity
from t4_devkit.sanity.registry import CHECKERS
from t4_devkit.sanity.result import Reason

if TYPE_CHECKING:
    from t4_devkit.sanity.context import SanityContext


@CHECKERS.register()
class STR000(Checker):
    """This is a custom checker."""

    id = RuleID("STR000")
    name = RuleName("my-custom-checker")
    severity = Severity.ERROR
    description = "This is a custom checker."

    def check(self, context: SanityContext) -> list[Reason] | None:
        # Return a list of reasons if the check fails, or None if it passes.
        return None