(kind, payload, tmp_path, monkeypatch, *, graph=True, out_name="graphify-out")
| 21 | # Direct-call harness: hermetic w.r.t. the ambient GRAPHIFY_OUT env. |
| 22 | # --------------------------------------------------------------------------- # |
| 23 | def _invoke(kind, payload, tmp_path, monkeypatch, *, graph=True, out_name="graphify-out"): |
| 24 | monkeypatch.setattr("graphify.paths.GRAPHIFY_OUT", out_name) |
| 25 | monkeypatch.setattr("graphify.paths.GRAPHIFY_OUT_NAME", out_name) |
| 26 | monkeypatch.chdir(tmp_path) |
| 27 | if graph: |
| 28 | (tmp_path / out_name).mkdir(parents=True, exist_ok=True) |
| 29 | (tmp_path / out_name / "graph.json").write_text("{}", encoding="utf-8") |
| 30 | |
| 31 | if isinstance(payload, (bytes, bytearray)): |
| 32 | data = bytes(payload) |
| 33 | elif payload is None: |
| 34 | data = b"" |
| 35 | else: |
| 36 | data = json.dumps(payload).encode("utf-8") |
| 37 | |
| 38 | class _Stdin: |
| 39 | def __init__(self, b): |
| 40 | self.buffer = io.BytesIO(b) |
| 41 | |
| 42 | monkeypatch.setattr(sys, "stdin", _Stdin(data)) |
| 43 | buf = io.StringIO() |
| 44 | monkeypatch.setattr(sys, "stdout", buf) |
| 45 | m._run_hook_guard(kind) |
| 46 | return buf.getvalue() |
| 47 | |
| 48 | |
| 49 | # --------------------------------------------------------------------------- # |
no test coverage detected