Пример #1
0
def test_hr_multiple_attributes():
    hrule = Hr(align="left",
               width="50%",
               )
    results = render_element(hrule)
    print(results)
    assert results.startswith('<hr align="left" width="50%">')
Пример #2
0
def test_self_closing_tag():
    atts = {"id": "fred", "class": "special", "size": "12px"}
    p = Hr(**atts)
    contents = render_element(p).strip()
    lines = contents.split('\n')
    print(contents)
    assert lines[0].startswith('<hr')
    assert lines[0].endswith("/>")
    assert 'id="fred"' in lines[0]
    assert 'class="special"' in lines[0]
    assert 'size="12px"' in lines[0]
    assert len(lines) == 1
Пример #3
0
def test_selfclosingtag_with_content():
    with pytest.raises(TypeError) as excinfo:
        page = Html()
        body = Body()
        attributes = {"class": "main bordered", "id": "top-spacer"}
        body.append(Hr("This should break stuff!", **attributes))
        page.append(body)

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

        raise TypeError("This element does not accept nested content.")

    assert str(excinfo.value) == "This element does not accept nested content."
Пример #4
0
def test_selfclosingtag():
    page = Html()
    body = Body()
    attributes = {"class": "main bordered", "id": "top-spacer"}
    body.append(Hr(**attributes))
    page.append(body)

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

    assert f.getvalue() == '<!DOCTYPE html>\n<html>\n'\
        '    <body>\n'\
        '        <hr class="main bordered" id="top-spacer" />\n'\
        '    </body>\n'\
        '</html>'
Пример #5
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_step5():
    hr = Hr()
    f = StringIO()
    hr.render(f)
    assert f.getvalue() == ('<hr />\n')

    br = Br()
    f = StringIO()
    br.render(f)
    assert f.getvalue() == ('<br />\n')

    with pytest.raises(TypeError):
        hr = Hr('anything')

    with pytest.raises(TypeError):
        br = Br('anything')
 def test_render2(self):
     """Test TypeError Exception"""
     p = Hr()
     self.assertRaises(TypeError, p.append, "Test exception")
 def test_render1(self):
     p = Hr()
     f = StringIO()
     p.render(f)
     expected = "<hr/> \n"
     self.assertEqual(expected, f.getvalue())
def test_hr():
    hr = Hr(width=400)
    file_contents = render_result(hr)
    print(file_contents)
    assert file_contents == '<hr width="400" />'
Пример #10
0
def test_self_closing_tag():
    e = Hr()
    output = get_output(e)
    print(output)
    assert output == "<hr />"
Пример #11
0
def test_hr():
    test = Hr()
    f = StringIO()
    test.render(f)
    assert f.getvalue() == '<hr />\n'
Пример #12
0
def test_hr_single_attribute():
    hrule = Hr(align="left")
    results = render_element(hrule)
    print(results)
    assert results.startswith('<hr align="left">')