Coverage for tests / unit / parsers / test_yaml.py: 100%

30 statements  

« 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.yaml import load_graph_yaml 

3from graphable.views.yaml import create_topology_yaml 

4 

5 

6def test_load_graph_yaml_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) 

13 

14 yaml_str = create_topology_yaml(g) 

15 

16 loaded_g = load_graph_yaml(yaml_str) 

17 

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 

23 

24 

25def test_load_graph_yaml_from_file(tmp_path): 

26 output_file = tmp_path / "graph.yaml" 

27 content = """ 

28nodes: 

29 - id: A 

30 reference: A 

31 tags: ["important"] 

32edges: [] 

33""" 

34 output_file.write_text(content) 

35 

36 loaded_g = load_graph_yaml(output_file) 

37 assert len(loaded_g) == 1 

38 assert "A" in loaded_g 

39 assert loaded_g["A"].is_tagged("important") 

40 

41 

42def test_load_graph_yaml_wrapped(): 

43 yaml_data = """ 

44graph: 

45 nodes: 

46 - id: A 

47 - id: B 

48 edges: 

49 - source: A 

50 target: B 

51""" 

52 g = load_graph_yaml(yaml_data) 

53 assert len(g) == 2 

54 assert "A" in g 

55 assert "B" in g