Coverage for tests / unit / parsers / test_toml.py: 100%
32 statements
« prev ^ index » next coverage.py v7.13.3, created at 2026-02-16 21:32 +0000
« prev ^ index » next coverage.py v7.13.3, created at 2026-02-16 21:32 +0000
1from graphable.graph import Graph, Graphable
2from graphable.parsers.toml import load_graph_toml
3from graphable.views.toml import create_topology_toml
6def test_load_graph_toml_roundtrip():
7 # A -> B
8 a = Graphable("A")
9 a.add_tag("t1")
10 b = Graphable("B")
11 g = Graph()
12 g.add_edge(a, b)
14 toml_str = create_topology_toml(g)
16 loaded_g = load_graph_toml(toml_str)
18 assert len(loaded_g) == 2
19 assert "A" in loaded_g
20 assert "B" in loaded_g
21 assert loaded_g["A"].is_tagged("t1")
22 assert loaded_g["B"] in loaded_g["A"].dependents
25def test_load_graph_toml_from_file(tmp_path):
26 output_file = tmp_path / "graph.toml"
27 content = """
28[[nodes]]
29id = "A"
30reference = "A"
31tags = ["important"]
33[[edges]]
34source = "A"
35target = "B"
37[[nodes]]
38id = "B"
39reference = "B"
40tags = []
41"""
42 output_file.write_text(content)
44 loaded_g = load_graph_toml(output_file)
45 assert len(loaded_g) == 2
46 assert "A" in loaded_g
47 assert "B" in loaded_g
48 assert loaded_g["A"].is_tagged("important")
49 assert loaded_g["B"] in loaded_g["A"].dependents
52def test_load_graph_toml_wrapped():
53 toml_data = """
54[graph]
55[[graph.nodes]]
56id = "A"
57[[graph.nodes]]
58id = "B"
59[[graph.edges]]
60source = "A"
61target = "B"
62"""
63 g = load_graph_toml(toml_data)
64 assert len(g) == 2
65 assert "A" in g
66 assert "B" in g