def test_title_render(): my_stuff = "items, items, items" el_object = Title(my_stuff) with open('testtitle', 'w') as out_file: el_object.render(out_file) with open('testtitle', 'r') as in_file: contents = in_file.read() assert contents.startswith('<title>') assert contents.endswith('</title>') assert my_stuff in contents
def test_step3(): f = StringIO() olt = OneLineTag('hi') olt.render(f) assert f.getvalue() == '<html>hi</html>\n' f = StringIO() title = Title('hi') title.render(f) assert f.getvalue() == '<title>hi</title>\n'
def test_title_render(): my_stuff = 'bye bye ms american pie' titleobj = Title(my_stuff) more_stuff = ' drove my chevy to the levy' titleobj.append(more_stuff) contents = render_element(titleobj) contents = contents.strip() assert contents.startswith('<title>') assert contents.endswith('</title>') assert my_stuff in contents assert more_stuff in contents
def test_title_indendation_twothings(): my_stuff = "Q: Where in the world is Grover Norquist?" more_stuff = "A: Pretending the Laffer curve is relevant" el_object = Title(my_stuff) body_object = Body(more_stuff) el_object.append(body_object) contents = render_element(el_object) contents = contents.strip() print(contents) lines = contents.split('\n') assert len(lines) == 1 assert lines[0].startswith('<title> ') assert my_stuff in lines[0]
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_single_line_element_with_attributes(): attr = {"id": "myTitle", "class": "red"} e = Title("a title", **attr) outfile_lines = get_output_lines(e) print(outfile_lines[0]) assert "<title " in outfile_lines[0] assert "id=\"myTitle\"" in outfile_lines[0] assert "class=\"red\"" in outfile_lines[0]
def test_attributes_one_line_tag(): """ tests that you can pass attributes in to the tag """ e = Title("some text", id="this", color="red") # could be any attributes file_contents = render_result(e) print(file_contents) assert 'id="this"' in file_contents assert 'color="red"' in file_contents
def test_title_tag(): # assert Title().tag == 'title' my_stuff = 'any string I like' titleobj = Title(my_stuff) contents = render_element(titleobj) contents = contents.strip() assert my_stuff in contents assert contents.startswith('<title>') assert contents.endswith('</title>')
def test_one_line_tag(): e1 = Html("") e2 = Head("") e3 = Title("Hark! A Title!") e2.append(e3) e1.append(e2) output = get_output(e1) print(output) output_lines = get_output_lines(e1) assert " <title>Hark! A Title!</title>" in output_lines
def test_title(): t = Title("Some title text") file_contents = render_result(t, ind=" ") print(file_contents) assert "\n" not in file_contents assert file_contents.startswith(" <title>") assert file_contents.endswith("</title>") assert "\n" not in file_contents
def test_title_indendation_onestring(): my_stuff = "Q: Where in the world is Grover Norquist?" el_object = Title(my_stuff) contents = render_element(el_object) contents = contents.strip() print(contents) lines = contents.split('\n') assert len(lines) == 1 assert lines[0].startswith('<title> ') assert my_stuff in lines[0] assert lines[0].endswith(' </title>')
def test_multiple_attributes_title(): p = Title("here is a paragraph of text", id="fred", color="red", size="12px") contents = render_element(p).strip() print(contents) lines = contents.split('\n') assert lines[0].startswith('<title ') assert lines[0].endswith('title>') assert 'id="fred"' in lines[0] assert 'color="red"' in lines[0] assert 'size="12px"' in lines[0]
def test_title(): """ This will implicitly test the OneLineTag element """ t = Title("Isn't this a nice title?") # making sure indentation still works file_contents = render_element(t, cur_ind=" ") print(file_contents) # no "strip()" -- making sure there are no extra newlines assert file_contents.startswith(" <title> I") assert file_contents.endswith("? </title>")
def test_OneLineTag(): # this is crating a html page with a single body() element in it el_object = Title('') contents = render_element( el_object, remove=False) # adding remove=False to see the output # make sure extra whitespace at beginning or end doesn't mess things up. contents = contents.strip() print(contents) # so we can see what's going on if a test fails assert contents.startswith('<') # Element.ind+'any' assert contents.endswith('>')
def test_Title(): element = Title('data1') element.append('data2') with open('file7.html', 'w') as file1fh: element.render(file1fh) with open('file7.html', 'r') as filefh: rendered = filefh.read() assert '<title> '+element.indent+'data1 '+element.indent+'data2 '+'</title>\n' == rendered # noqa: E501
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_title(): """ This will implicitly test the OneLineTag element """ t = Title("Isn't this a nice title?") # making sure indentation still works file_contents = render_result(t, ind=" ") print(file_contents) # no "strip()" -- making sure there are no extra newlines assert "\n" not in file_contents assert file_contents.startswith(" <title>") assert file_contents.endswith("</title>") # the only newline should be at the end assert "\n" not in file_contents
def test_multiple_attributes_title(): t = Title("Here is a paragraph of text", id="fred", color="red", size="12px", ) results = render_element(t) print(results) lines = results.split('\n') assert lines[0].startswith('<title ') assert lines[0].endswith('</title>') assert 'id="fred"' in lines[0] assert 'color="red"' in lines[0] assert 'size="12px"' in lines[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_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_Title(): outfile = io.StringIO() e = Title('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("<title>") assert file_contents.strip().endswith("</title>")
def test_title(): test = Title(content='a title tag') f = StringIO() test.render(f) assert f.getvalue() == '<title>a title tag</title>\n'
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_render(self): p = Title("Python Intro = Lesson 7") f = StringIO() p.render(f) expected = "<title>Python Intro = Lesson 7</title>\n" self.assertEqual(expected, f.getvalue())