test_formatters   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 86
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 17
dl 0
loc 86
rs 10
c 0
b 0
f 0
wmc 3

3 Functions

Rating   Name   Duplication   Size   Complexity  
A test_markdown() 0 9 1
A test_html_without_title() 0 34 1
A test_html_with_title() 0 35 1
1
from networkx_mermaid.formatters import html, markdown
2
3
4
def test_markdown():
5
    # Arrange
6
    diagram = "graph LR\nA-->B"
7
8
    # Act
9
    result = markdown(diagram)
10
11
    # Assert
12
    assert result == "```mermaid\ngraph LR\nA-->B\n```"
13
14
15
def test_html_without_title():
16
    # Arrange
17
    diagram = "graph LR\nA-->B"
18
    expected_html_template = """<!doctype html>
19
<html lang="en">
20
  <head>
21
    <link rel="icon" type="image/x-icon" href="https://mermaid.js.org/favicon.ico">
22
    <meta charset="utf-8">
23
    <title>Mermaid Diagram</title>
24
    <style>
25
    pre.mermaid {
26
      font-family: "Fira Mono", "Roboto Mono", "Source Code Pro", monospace;
27
    }
28
    </style>
29
  </head>
30
  <body>
31
    <pre class="mermaid">
32
graph LR
33
A-->B
34
    </pre>
35
    <script type="module">
36
      import mermaid from 'https://cdn.jsdelivr.net/npm/mermaid@11/dist/mermaid.esm.min.mjs';
37
      let config = { startOnLoad: true, flowchart: { useMaxWidth: false, htmlLabels: true } };
38
      mermaid.initialize(config);
39
    </script>
40
  </body>
41
</html>
42
"""
43
44
    # Act
45
    result = html(diagram)
46
47
    # Assert
48
    assert result == expected_html_template
49
50
51
def test_html_with_title():
52
    # Arrange
53
    diagram = "graph LR\nA-->B"
54
    title = "My Diagram"
55
    expected_html_template = """<!doctype html>
56
<html lang="en">
57
  <head>
58
    <link rel="icon" type="image/x-icon" href="https://mermaid.js.org/favicon.ico">
59
    <meta charset="utf-8">
60
    <title>My Diagram</title>
61
    <style>
62
    pre.mermaid {
63
      font-family: "Fira Mono", "Roboto Mono", "Source Code Pro", monospace;
64
    }
65
    </style>
66
  </head>
67
  <body>
68
    <pre class="mermaid">
69
graph LR
70
A-->B
71
    </pre>
72
    <script type="module">
73
      import mermaid from 'https://cdn.jsdelivr.net/npm/mermaid@11/dist/mermaid.esm.min.mjs';
74
      let config = { startOnLoad: true, flowchart: { useMaxWidth: false, htmlLabels: true } };
75
      mermaid.initialize(config);
76
    </script>
77
  </body>
78
</html>
79
"""
80
81
    # Act
82
    result = html(diagram, title=title)
83
84
    # Assert
85
    assert result == expected_html_template
86