#!/usr/bin/env python3 import json import shutil import tempfile from pathlib import Path from check_package import check_package ROOT = Path(__file__).resolve().parent def main(): result = check_package(ROOT / "sample-package") assert result == json.loads((ROOT / "expected.json").read_text(encoding="utf-8")) assert result["status"] == "structure_checked" and result["warnings"] with tempfile.TemporaryDirectory() as folder: package = Path(folder) / "package" shutil.copytree(ROOT / "sample-package", package) filename = package / "model_info.json" original = json.loads(filename.read_text()) for change in ( {"weights_path": "../outside.onnx"}, {"weights_path": "weights/missing.onnx"}, {"img_size": {"height": True, "width": 640}}, {"deploy_profile": {"profiles": ["cpu"], "default_profile": "gpu"}}, ): filename.write_text(json.dumps({**original, **change}), encoding="utf-8") assert check_package(package)["errors"], change filename.write_text(json.dumps(original), encoding="utf-8") catfile = package / "coco_categories.json" cats = json.loads(catfile.read_text()) cats["categories"].append(cats["categories"][0].copy()) catfile.write_text(json.dumps(cats), encoding="utf-8") assert any("повторяется" in e for e in check_package(package)["errors"]) print("PASS: structure, warnings, path escape, missing weights, boolean size, profile mismatch, duplicate category") if __name__ == "__main__": main()