summaryrefslogtreecommitdiff
path: root/test/test_utiltohtml.py
blob: 316a620e0e5e61682639df1efdfbe0ada24f9d6e (plain)
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104

from __future__ import print_function

import io
import sys
import subprocess

from roundtrip import dedent

from test_util import check_output, call_util


def to_html(s, file_name, mp, td, options=None):
    cmd = ['yaml', 'htmltable', file_name]
    if options:
        cmd.extend(options)
    return call_util(s, file_name, cmd, mp, td)


class TestUtilToHTML:
    def test_html_01(self, tmpdir, monkeypatch):
        file_name = "html.yaml"
        res = to_html(u"""
        - 1
        - 2
        """, file_name, mp=monkeypatch, td=tmpdir, options=["--level"])
        assert res == "levels: 1\n"

    def test_html_02(self, tmpdir, monkeypatch):
        file_name = "html.yaml"
        res = to_html(u"""
        abc:
        - 1
        - 2
        ghi:
        - 3
        - 4
        """, file_name, mp=monkeypatch, td=tmpdir, options=["--level"])
        assert res == "levels: 2\n".format(file_name)

    def test_html_03(self, tmpdir, monkeypatch):
        file_name = "html.yaml"
        res = to_html(u"""
        -
          - 1
          - 2
        -
          - 3
          - 4
        """, file_name, mp=monkeypatch, td=tmpdir, options=["--level"])
        assert res == "levels: 2\n"

    def test_html_03(self, tmpdir, monkeypatch):
        file_name = "html.yaml"
        res = to_html(u"""
        -
          abc:
          - 1
          - 2
          def:
          - 3
          - 4
        """, file_name, mp=monkeypatch, td=tmpdir, options=["--level"])
        assert res == "levels: 3\n"

    def test_html_04(self, tmpdir, monkeypatch):
        file_name = "html.yaml"
        res = to_html(u"""
        title:
        - fruit
        - legume
        local:
        - apple
        - sprouts
        import:
        - orange
        - broccoli
        """, file_name, mp=monkeypatch, td=tmpdir)
        assert res == dedent("""\
        <HTML>
        <HEAD>
        </HEAD>
        <BODY>
        <TABLE>
          <TR>
            <TD>title</TD>
            <TD>fruit</TD>
            <TD>legume</TD>
          </TR>
          <TR>
            <TD>local</TD>
            <TD>apple</TD>
            <TD>sprouts</TD>
          </TR>
          <TR>
            <TD>import</TD>
            <TD>orange</TD>
            <TD>broccoli</TD>
          </TR>
        <TABLE>
        </BODY>
        </HTML>

        """)