示例#1
0
def test_Ul():
    element = Ul('data1')
    element.append('data2')
    with open('file11.html', 'w') as file1fh:
        element.render(file1fh)
    with open('file11.html', 'r') as filefh:
        rendered = filefh.read()
    assert '<ul>\n'+element.indent+'data1\n'+element.indent+'data2\n'+'</ul>\n' == rendered  # noqa: E501
def test_ul():
    ul = Ul()
    ul.append(Li("item one in a list"))
    ul.append(Li("item two in a list"))
    file_contents = render_result(ul)
    print(file_contents)
    assert file_contents.startswith('<ul>')
    assert file_contents.endswith('</ul>')
    assert "item one in a list" in file_contents
    assert "item two in a list" in file_contents
    assert file_contents.count("<li>") == 2
    assert file_contents.count("</li>") == 2
示例#3
0
def test_li_element():
    list_name = "These are a few of my favorite things"
    thing1 = "Roses on raindrops"
    atts1 = {"size": "12px"}
    thing2 = "Whiskers on kittens"
    atts2 = {"size": "14px"}
    p = Ul(list_name)
    p.append(Li(thing1, **atts1))
    p.append(Li(thing2, **atts2))
    contents = render_element(p).strip()
    lines = contents.split('\n')
    print(contents)
    assert len(lines) == 9
    assert lines[0].startswith('<ul')
    assert 'size="14px"' in lines[5]
    assert lines[2].startswith(Element.extra_indent + '<li size=')
    assert lines[3].startswith(2 * Element.extra_indent + thing1)
    assert lines[6].startswith(2 * Element.extra_indent + thing2)
示例#4
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)