def test_doctype_meta(): page = Html() head = Head() head.append(Meta(charset="UTF-8")) page.append(head) f = StringIO() page.render(f, "") assert f.getvalue() == '<!DOCTYPE html>\n<html>\n'\ ' <head>\n'\ ' <meta charset="UTF-8" />\n'\ ' </head>\n'\ '</html>'
def test_OneLineTag(): page = Html() head = Head() head.append(Title("Here is some title text")) page.append(head) f = StringIO() page.render(f, "") assert f.getvalue() == '<!DOCTYPE html>\n<html>\n'\ ' <head>\n'\ ' <title>Here is some title text</title>\n'\ ' </head>\n'\ '</html>'
def test_head(): """ testing Head with a title in it -- it should never be blank """ h = Head() h.append(Title("A nifty title for the page")) file_contents = render_element(h, cur_ind=' ') print(file_contents) assert file_contents.startswith(" <head>") assert file_contents.endswith(" </head>") assert "<title>" in file_contents assert "</title>" in file_contents assert "A nifty title for the page" in file_contents
def test_head_tag(): # assert newobj.tag == 'head' my_stuff = 'any string I like' head_obj = Head(my_stuff) contents = render_element(head_obj) contents = contents.strip() assert my_stuff in contents assert contents.startswith('<head>') assert contents.endswith('</head>')
def test_Head(): element = Head('data1') element.append('data2') with open('file5.html', 'w') as file1fh: element.render(file1fh) with open('file5.html', 'r') as filefh: rendered = filefh.read() assert '<head>\n'+element.indent+'data1\n'+element.indent+'data2\n'+'</head>\n' == rendered # noqa: E501
def test_step3(): outfile = io.StringIO() p = Html() h = Head() h.append(Title('This is TITLE')) p.append(h) b = Body() b.append(P('This is P')) p.append(b) p.render(outfile) outfile.seek(0) file_contents = outfile.read() print(file_contents) assert('This is TITLE') in file_contents assert('This is P') in file_contents assert file_contents.startswith("<html>") assert file_contents.strip().endswith("</html>")
def test_full_page_with_title(): """ not much to actually test here, but good to see it put together. everything should have already been tested. """ page = Html() head = Head() head.append(Title("PythonClass Example")) page.append(head) body = Body() 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")) body.append(P("And here is another piece of text -- you should be able to add any number")) page.append(body) file_contents = render_result(page) print(file_contents)
def test_head(): outfile = io.StringIO() e = Head("this is some text") e.append("and this is some more text") e.render(outfile) outfile.seek(0) file_contents = outfile.read() assert ("this is some text") in file_contents assert ("and this is some more text") in file_contents
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_Head(): outfile = io.StringIO() e = Head('This is some text') e.append('This is some more text') e.render(outfile) outfile.seek(0) file_contents = outfile.read() print(file_contents) assert('This is some text') in file_contents assert('This is some more text') in file_contents assert file_contents.startswith("<head>") assert file_contents.strip().endswith("</head>")
def test_head(): """ testing Head with a title in it -- it should never be blank """ h = Head() h.append(Title("A nifty title for the page"))
def test_head(): test = Head(content='a head tag') f = StringIO() test.render(f) assert f.getvalue() == '<head>\n a head tag\n</head>\n'
def test_type_Head(): test_element = Head(content=None) assert isinstance(test_element, Head) is True