diff options
author | alevitskii <[email protected]> | 2025-09-04 10:00:21 +0300 |
---|---|---|
committer | alevitskii <[email protected]> | 2025-09-04 10:19:32 +0300 |
commit | 8da3e97c84353501738d1ff485708bf8b7185eb8 (patch) | |
tree | dfe1363035f5daa04064c8cdacc3835b3a5cdf90 /library/python/testing/custom_linter_util/reporter.py | |
parent | 4c3f3af78aac956c2d034edb4a0d7c778b9fe9d3 (diff) |
DEPENDS on linter wrappers to get them exported to opensource
DEPENDS on linter wrappers to get them exported to oss
commit_hash:286fa6981744f667a509749a33afcc3421903842
Diffstat (limited to 'library/python/testing/custom_linter_util/reporter.py')
-rw-r--r-- | library/python/testing/custom_linter_util/reporter.py | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/library/python/testing/custom_linter_util/reporter.py b/library/python/testing/custom_linter_util/reporter.py new file mode 100644 index 00000000000..5e3d11bd339 --- /dev/null +++ b/library/python/testing/custom_linter_util/reporter.py @@ -0,0 +1,41 @@ +# XXX: This module is used in linter tools in `tools/` which are run by test_tool. +# test_tool and `tools/` have different release cycles. Beware when modifying. +import json +import sys +from enum import Enum +from typing import Optional + + +class LintStatus(Enum): + GOOD = "GOOD" + FAIL = "FAIL" + SKIPPED = "SKIPPED" + + +class LintReport(): + def __init__(self): + self._report = {} + + def add(self, file_name: str, status: LintStatus, message: str = "", elapsed: float = 0.0): + self._report[file_name] = { + "status": status.value, + "message": message, + "elapsed": elapsed, + } + + def dump(self, report_file, pretty: Optional[bool] = None): + data = { + "report": self._report, + } + if report_file == "-": + if pretty is None: + pretty = True + self._do_dump(sys.stdout, data, pretty) + else: + with open(report_file, "w") as f: + self._do_dump(f, data, pretty) + + @staticmethod + def _do_dump(dest, data, pretty): + indent = 4 if pretty else None + json.dump(data, dest, indent=indent) |