mirror of
https://github.com/safishamsi/graphify.git
synced 2026-07-13 10:57:13 +00:00
ce47198be1
skill.md with full pipeline steps, Obsidian as default output (canvas, tags, dataview, graph colors), two-command install, 71 tests, .gitignore, deps
55 lines
1.6 KiB
Python
55 lines
1.6 KiB
Python
import json
|
|
import tempfile
|
|
from pathlib import Path
|
|
from graphify.build import build_from_json
|
|
from graphify.cluster import cluster
|
|
from graphify.export import to_json, to_cypher
|
|
|
|
FIXTURES = Path(__file__).parent / "fixtures"
|
|
|
|
def make_graph():
|
|
return build_from_json(json.loads((FIXTURES / "extraction.json").read_text()))
|
|
|
|
def test_to_json_creates_file():
|
|
G = make_graph()
|
|
communities = cluster(G)
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
out = Path(tmp) / "graph.json"
|
|
to_json(G, communities, str(out))
|
|
assert out.exists()
|
|
|
|
def test_to_json_valid_json():
|
|
G = make_graph()
|
|
communities = cluster(G)
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
out = Path(tmp) / "graph.json"
|
|
to_json(G, communities, str(out))
|
|
data = json.loads(out.read_text())
|
|
assert "nodes" in data
|
|
assert "links" in data
|
|
|
|
def test_to_json_nodes_have_community():
|
|
G = make_graph()
|
|
communities = cluster(G)
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
out = Path(tmp) / "graph.json"
|
|
to_json(G, communities, str(out))
|
|
data = json.loads(out.read_text())
|
|
for node in data["nodes"]:
|
|
assert "community" in node
|
|
|
|
def test_to_cypher_creates_file():
|
|
G = make_graph()
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
out = Path(tmp) / "cypher.txt"
|
|
to_cypher(G, str(out))
|
|
assert out.exists()
|
|
|
|
def test_to_cypher_contains_merge_statements():
|
|
G = make_graph()
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
out = Path(tmp) / "cypher.txt"
|
|
to_cypher(G, str(out))
|
|
content = out.read_text()
|
|
assert "MERGE" in content
|