mirror of
https://github.com/ProjectLeonida/mandy.git
synced 2026-12-06 08:58:36 +00:00
Merge pull request #480 from kotekompotek/work/gen-gdk-classes-makedirs
Why merged: --out now creates its missing parent folder instead of failing.
Why it's good: security-reviewed; tested on Windows 11 merged onto main c023a36: the new test errors on main and passes here; a 3-line change.
AI-assisted (Claude Code, Claude Opus 5.5).
This commit is contained in:
32
tests/test_gen_gdk_classes_out_dir.py
Normal file
32
tests/test_gen_gdk_classes_out_dir.py
Normal file
@ -0,0 +1,32 @@
|
||||
"""Regression test for --out parent directory creation in tools/gen_gdk_runtime_classes.py."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import sys
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
from tempfile import TemporaryDirectory
|
||||
from unittest import mock
|
||||
|
||||
REPO = Path(__file__).resolve().parent.parent
|
||||
sys.path.insert(0, str(REPO / "tools"))
|
||||
|
||||
import gen_gdk_runtime_classes as gen # noqa: E402
|
||||
|
||||
|
||||
class TestGenGdkOutDir(unittest.TestCase):
|
||||
def test_main_creates_missing_out_parent_directory(self) -> None:
|
||||
with TemporaryDirectory() as tmp:
|
||||
docs = Path(tmp) / "docs"
|
||||
(docs / "COM").mkdir(parents=True)
|
||||
out_json = Path(tmp) / "nested" / "dir" / "classes.json"
|
||||
with mock.patch.object(gen, "revision", return_value="abc123"):
|
||||
rc = gen.main([str(docs), "--out", str(out_json)])
|
||||
self.assertEqual(rc, 0)
|
||||
self.assertTrue(out_json.is_file())
|
||||
self.assertEqual(json.loads(out_json.read_text(encoding="utf-8"))["classes"], {})
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@ -133,6 +133,9 @@ def main(argv: list[str] | None = None) -> int:
|
||||
problems = check(table["classes"], table["interfaces"])
|
||||
for p in problems:
|
||||
print(f"warning: {p}", file=sys.stderr)
|
||||
parent = os.path.dirname(os.path.abspath(a.out))
|
||||
if parent:
|
||||
os.makedirs(parent, exist_ok=True)
|
||||
with open(a.out, "w", encoding="utf-8", newline="\n") as f:
|
||||
json.dump(table, f, indent=1, sort_keys=True)
|
||||
f.write("\n")
|
||||
|
||||
Reference in New Issue
Block a user