def test_header():
    h = H(3, "A nice header line")
    file_contents = render_result(h)
    print(file_contents)
    assert file_contents.startswith('<h3>')
    assert file_contents.endswith('</h3>')
    assert "A nice header line" in file_contents
示例#2
0
def test_H():
    element = H(2, 'data1')
    with open('file13.html', 'w') as file1fh:
        element.render(file1fh)
    with open('file13.html', 'r') as filefh:
        rendered = filefh.read()
    assert '<h2> '+element.indent+'data1 '+'</h2>\n' == rendered  # noqa: E501
示例#3
0
def test_header2():
    """
    adding an attribute to a header
    """
    h = H(2, "A nice header line", align="center")
    file_contents = render_result(h)
    print(file_contents)
    assert file_contents.startswith('<h2')
    assert file_contents.endswith('</h2>')
    assert "A nice header line" in file_contents
    assert ' align="center"' in file_contents
示例#4
0
def test_header_element():
    # <h2> The text of the header </h2>
    # THIS TEST IS PASSING BUT THE RENDERED EXAMPLE LOOKS BAD
    text = 'The text of the header'
    p = H(2, text)
    contents = render_element(p).strip()
    lines = contents.split('\n')
    print(contents)
    assert len(lines) == 1
    assert lines[0].startswith('<h2>')
    assert lines[0].endswith('</h2>')
    assert contents.index(text) < contents.index('</h2>')
    assert contents.index(text) > contents.index('<h2>')
示例#5
0
def test_h():
    page = Html()
    body = Body()
    body.append(H(1, "Top Heading"))
    page.append(body)

    f = StringIO()
    page.render(f, "")

    assert f.getvalue() == '<!DOCTYPE html>\n<html>\n'\
        '    <body>\n'\
        '        <h1>Top Heading</h1>\n'\
        '    </body>\n'\
        '</html>'
示例#6
0
def test_whole_thing():
    """
    Render a complete page

    This is not really a unit test, and does not test that the results
    are correct, but does ensure that it all runs, and provides output
    to look at
    """
    page = Html()

    head = Head()
    head.append(Meta(charset="UTF-8"))
    head.append(Title("Python Class Sample page"))
    page.append(head)

    body = Body()

    body.append(H(2, "Python Class - Html rendering example"))

    body.append(
        P(
            "Here is a paragraph of text -- there could be more of them, "
            "but this is enough to show that we can do some text",
            style="text-align: center; font-style: oblique;"))

    body.append(Hr())

    list = Ul(id="TheList", style="line-height:200%")

    list.append(Li("The first item in a list"))
    list.append(Li("This is the second item", style="color: red"))

    item = Li()
    item.append("And this is a ")
    item.append(A("http://google.com", "link"))
    item.append("to google")

    list.append(item)

    body.append(list)

    page.append(body)

    # Element.indent = "        "
    # now render it:
    with open("sample_output.html", 'w') as f:
        page.render(f)
def test_step7():
    li = Li('something')
    ul = Ul('something')
    h = H(2, 'something')
    assert li.tag == 'li'
    assert ul.tag == 'ul'
    assert h.tag == 'h2'
    assert h.content == ['something']

    f = StringIO()
    ul = Ul(Li('something'))
    ul.render(f)
    assert f.getvalue() == ('<ul>\n    <li>\n        something\n    </li>\n'
                            '</ul>\n')

    f = StringIO()
    h.render(f)
    assert f.getvalue() == ('<h2>something</h2>\n')
 def test_init(self):
     p = H(4, "Lesson7 - HTML")
     f = StringIO()
     p.render(f)
     expected = "<h4>Lesson7 - HTML</h4>\n"
     self.assertEqual(expected, f.getvalue())
def test_header():
    attr = {"class": "tiny-header"}
    h = H(4, "a header", **attr)
    output = get_output(h)
    print(output)
    assert output == "<h4 class=\"tiny-header\">a header</h4>"
示例#10
0
def test_h():
    test = H(2, content='an h2 tag')
    f = StringIO()
    test.render(f)
    assert f.getvalue() == '<h2>an h2 tag</h2>\n'
示例#11
0
def test_heading1_with_one_attribute():
    heading = H(1, "Heading 1", align="left")
    results = render_element(heading)
    assert results.startswith('<h1 align="left">Heading 1</h1>')
    print(results)