Coverage for tests / unit / views / test_html.py: 100%
38 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.html import (
9 HtmlStylingConfig,
10 create_topology_html,
11 export_topology_html,
12)
15class TestHtml:
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_html_default(self, graph_fixture):
25 g, a, b = graph_fixture
26 html = create_topology_html(g)
28 assert "<!DOCTYPE html>" in html
29 assert "cytoscape.min.js" in html
30 assert "Graphable Visualization" in html
31 assert 'id="search"' in html
32 assert 'id="sidebar"' in html
33 assert '"source": "A"' in html
34 assert '"target": "B"' in html
36 def test_create_topology_html_custom_config(self, graph_fixture):
37 g, a, b = graph_fixture
38 config = HtmlStylingConfig(title="My Graph", theme="dark", node_color="red")
39 html = create_topology_html(g, config)
41 assert "<title>My Graph</title>" in html
42 assert "background-color: #222" in html
43 assert "'background-color': 'red'" in html
45 def test_export_topology_html(self, graph_fixture):
46 g, _, _ = graph_fixture
47 output_path = Path("output.html")
49 with patch("builtins.open", mock_open()) as mock_file:
50 export_topology_html(g, output_path)
52 mock_file.assert_called_with(output_path, "w+")
53 mock_file().write.assert_called()