import ergodic
from ergodic import MixedGraph, dag

# 1. Print the graph format this ergodic reads and writes.
print(ergodic.GRAPH_FORMAT)

# 2. Write a DAG as a dict: the payload Welt builds for a declared DAG.
graph = dag(["Z -> X", "Z -> Y", "X -> Y"])
payload = graph.to_dict()
print(payload["format"], payload["kind"], sorted(payload["nodes"]))
print(payload["edges"][0])

# 3. Read it back.
print(MixedGraph.from_dict(payload) == graph)

# 4. A payload with another format is refused, not guessed.
try:
    MixedGraph.from_dict({**payload, "format": "ergodic.graph/2"})
except ValueError as error:
    print("ValueError:", error)
