Coverage for tests / unit / views / test_csv.py: 100%
31 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.csv import create_topology_csv, export_topology_csv
11class TestCSV:
12 @fixture
13 def graph_fixture(self):
14 a = Graphable("A")
15 b = Graphable("B")
16 g = Graph()
17 g.add_edge(a, b)
18 return g, a, b
20 def test_create_topology_csv_default(self, graph_fixture):
21 g, a, b = graph_fixture
22 csv_str = create_topology_csv(g)
24 assert "source,target" in csv_str
25 assert "A,B" in csv_str
27 def test_create_topology_csv_no_header(self, graph_fixture):
28 g, a, b = graph_fixture
29 csv_str = create_topology_csv(g, include_header=False)
31 assert "source,target" not in csv_str
32 assert "A,B" in csv_str
34 def test_export_topology_csv(self, graph_fixture):
35 g, _, _ = graph_fixture
36 output_path = Path("output.csv")
38 with patch("builtins.open", mock_open()) as mock_file:
39 export_topology_csv(g, output_path)
41 mock_file.assert_called_with(output_path, "w+", newline="")
42 mock_file().write.assert_called()