test_manifest.py
1.2 kB · python · 44 lines
1import importlib2import json3import keyword4import pathlib56import mrlypy78MANIFEST = pathlib.Path(__file__).resolve().parents[3] / "bridge" / "manifest.json"91011def load():12 return json.loads(MANIFEST.read_text())131415def name_of(word):16 return word + "_" if keyword.iskeyword(word) else word171819def locate(fn, kinds):20 module = importlib.import_module("mrlypy." + fn["module"].replace("::", "."))21 exported = name_of(fn["path"].rsplit("::", 1)[-1])22 owner = fn["owner"]23 if owner and kinds[owner] in ("class", "plain", "enum"):24 return getattr(getattr(module, owner.rsplit("::", 1)[-1]), exported)25 return getattr(module, exported)262728def test_every_ok_function_is_callable_under_its_rust_doc():29 manifest = load()30 kinds = {t["path"]: t["cross"]["kind"] for t in manifest["types"]}31 count = 032 for fn in manifest["functions"]:33 if fn["cross"]["status"] != "ok":34 continue35 target = locate(fn, kinds)36 assert callable(target), fn["path"]37 doc = target.__doc__ or ""38 if fn["docs"]:39 if fn["dims"]:40 assert fn["docs"][0] in doc, fn["path"]41 else:42 assert doc.startswith(fn["docs"][0]), fn["path"]43 count += 144 assert count == 1120