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
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)
def test_ul_element(): atts = {"size": "12px"} list_name = "These are a few of my favorite things" p = Ul(list_name, **atts) contents = render_element(p).strip() print(contents) lines = contents.split('\n') assert len(lines) == 3 assert lines[0].startswith('<ul size=') assert lines[2].endswith('</ul>') assert list_name in lines[1] assert 'size="12px"' in lines[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_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_ul(): test = Ul('an unordered list tag') f = StringIO() test.render(f) assert f.getvalue() == '<ul>\n an unordered list tag\n</ul>\n'
def test_unordered_list_with_one_attribute(): unord_list = Ul(align="left") results = render_element(unord_list) print(results) assert results.startswith('<ul align="left"> \n</ul>')