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

Function _run_fallback

tests/test_query_fallback_edges.py:31–66  ·  view source on GitHub ↗
(
    tmp_path: Path,
    monkeypatch: pytest.MonkeyPatch,
    graph: nx.Graph,
    *,
    question: str,
    mode: str,
    token_budget: int = 2000,
)

Source from the content-addressed store, hash-verified

29
30
31def _run_fallback(
32 tmp_path: Path,
33 monkeypatch: pytest.MonkeyPatch,
34 graph: nx.Graph,
35 *,
36 question: str,
37 mode: str,
38 token_budget: int = 2000,
39) -> str:
40 try:
41 data = json_graph.node_link_data(graph, edges="links")
42 except TypeError: # NetworkX before the ``edges`` keyword.
43 data = json_graph.node_link_data(graph)
44 output_dir = tmp_path / "graphify-out"
45 output_dir.mkdir()
46 (output_dir / "graph.json").write_text(json.dumps(data), encoding="utf-8")
47
48 script = _fallback_script()
49 # The payload is embedded in a double-quoted shell argument. Unescape the
50 # quotes that the shell would remove before compiling its Python body.
51 script = script.replace(chr(92) + '"', '"')
52 script = script.replace("question = 'QUESTION'", f"question = {question!r}")
53 script = script.replace("mode = 'MODE' # 'bfs' or 'dfs'", f"mode = {mode!r}")
54 script = script.replace(
55 "token_budget = BUDGET # default 2000",
56 f"token_budget = {token_budget}",
57 )
58 assert "'QUESTION'" not in script
59 assert "'MODE'" not in script
60 assert "BUDGET" not in script
61
62 monkeypatch.chdir(tmp_path)
63 output = io.StringIO()
64 with redirect_stdout(output):
65 exec(compile(script, str(QUERY_FRAGMENT), "exec"), {"__name__": "__main__"})
66 return output.getvalue()
67
68
69@pytest.mark.parametrize("mode", ["bfs", "dfs"])

Calls 1

_fallback_scriptFunction · 0.85

Tested by

no test coverage detected