MCPcopy Create free account
hub / github.com/Graphify-Labs/graphify / _invoke

Function _invoke

tests/test_hook_guard.py:23–46  ·  view source on GitHub ↗
(kind, payload, tmp_path, monkeypatch, *, graph=True, out_name="graphify-out")

Source from the content-addressed store, hash-verified

21# Direct-call harness: hermetic w.r.t. the ambient GRAPHIFY_OUT env.
22# --------------------------------------------------------------------------- #
23def _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# --------------------------------------------------------------------------- #

Calls 1

_StdinClass · 0.70

Tested by

no test coverage detected