File: test_html.py

package info (click to toggle)
python-pygraphviz 1.14-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 732 kB
  • sloc: ansic: 5,100; python: 2,669; makefile: 57
file content (72 lines) | stat: -rw-r--r-- 2,046 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import pygraphviz as pgv

stringify = pgv.testing.stringify


long_html_string = """<<TABLE BORDER=0>
  <TR>
      <TD> meow </TD>
  </TR>
  <TR>
      <TD>
        <TABLE>
          <TR>
          <TD align=left>Count</TD>
          <TD align=right> 4 </TD>
          </TR>
          <TR>
          <TD align=left>Earliest Run</TD>
          <TD align=right> yesterday </TD>
          </TR>
          <TR>
          <TD align=left>Latest Run</TD>
          <TD align=right> tomorrow </TD>
          </TR>
          <TR>
          <TD align=left>Avg Runtime</TD>
          <TD align=right> 4 seconds </TD>
          </TR>
          <TR>
          <TD align=left>Avg Failure Rate</TD>
          <TD align=right> 38.1% </TD>
          </TR>
        </TABLE>
      </TD>
  </TR>
</TABLE>>"""


def test_long_html_string():
    G = pgv.AGraph(label="<Hello<BR/>Graph>")
    G.add_node("a", label=long_html_string)
    s = G.add_subgraph("b", label="<Hello<BR/>Subgraph>")
    s.add_node("sa", label="<Hello<BR/>Subgraph Node b>")
    G.add_edge("a", "b", label="<Hello<BR/>Edge>")
    ans = f"""strict graph {{
              graph [label=<Hello<BR/>Graph>];
              {{
                graph [label=<Hello<BR/>Subgraph>];
                sa     [label=<Hello<BR/>Subgraph Node b>];
              }}
              a  [label={long_html_string}];
              a -- b   [label=<Hello<BR/>Edge>];
            }}"""
    assert stringify(G) == " ".join(ans.split())


def test_html():
    G = pgv.AGraph(label="<Hello<BR/>Graph>")
    G.add_node("a", label="<Hello<BR/>Node>")
    s = G.add_subgraph("b", label="<Hello<BR/>Subgraph>")
    s.add_node("sa", label="<Hello<BR/>Subgraph Node b>")
    G.add_edge("a", "b", label="<Hello<BR/>Edge>")
    ans = """strict graph {
      graph [label=<Hello<BR/>Graph>];
      {
        graph [label=<Hello<BR/>Subgraph>];
        sa [label=<Hello<BR/>Subgraph Node b>];
      }
      a  [label=<Hello<BR/>Node>];
      a -- b [label=<Hello<BR/>Edge>];
    }"""
    assert stringify(G) == " ".join(ans.split())