Coverage for tests / unit / views / test_asciiflow.py: 100%
51 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 pathlib import Path
2from unittest.mock import mock_open, patch
4from pytest import fixture
6from graphable.graph import Graph
7from graphable.graphable import Graphable
8from graphable.views.asciiflow import (
9 AsciiflowStylingConfig,
10 create_topology_ascii_flow,
11 export_topology_ascii_flow,
12)
15class TestAsciiFlow:
16 @fixture
17 def graph_fixture(self):
18 a = Graphable("A")
19 b = Graphable("B")
20 g = Graph()
21 g.add_edge(a, b)
22 return g, a, b
24 def test_create_topology_ascii_flow_default(self, graph_fixture):
25 g, a, b = graph_fixture
26 flow = create_topology_ascii_flow(g)
28 assert "+---+" in flow
29 assert "| A |" in flow
30 assert " +--> B" in flow
31 assert "| B |" in flow
33 def test_create_topology_ascii_flow_with_tags(self, graph_fixture):
34 g, a, b = graph_fixture
35 a.add_tag("source")
37 config = AsciiflowStylingConfig(show_tags=True)
38 flow = create_topology_ascii_flow(g, config)
40 assert "| A [source] |" in flow
41 assert "+------------+" in flow
43 def test_create_topology_ascii_flow_custom_text(self, graph_fixture):
44 g, a, b = graph_fixture
45 config = AsciiflowStylingConfig(node_text_fnc=lambda n: f"Node {n.reference}")
46 flow = create_topology_ascii_flow(g, config)
48 assert "| Node A |" in flow
49 assert " +--> Node B" in flow
51 def test_create_topology_ascii_flow_multiple_dependents(self):
52 a = Graphable("A")
53 b = Graphable("B")
54 c = Graphable("C")
55 g = Graph()
56 g.add_edge(a, b)
57 g.add_edge(a, c)
59 flow = create_topology_ascii_flow(g)
60 # Check for multiple arrows from A
61 assert " +--> B" in flow
62 assert " +--> C" in flow
64 def test_export_topology_ascii_flow(self, graph_fixture):
65 g, _, _ = graph_fixture
66 output_path = Path("output.txt")
68 with patch("builtins.open", mock_open()) as mock_file:
69 export_topology_ascii_flow(g, output_path)
71 mock_file.assert_called_with(output_path, "w+")
72 mock_file().write.assert_called()