def testRender(self): """testRender validates a basic Head render operation.""" given = 'hello Head' want = [ "<head>", "{}{}".format(html_render.Head().ind, given), "</head>", ] got = open(self.file_out, 'w') html_render.Head(given).render(got) got.close() self.assertTrue(validate_output(self.file_out, want))
def test_Html_Head_Meta_Title_Body_H_P_Hr_Ul_Li_A_real_Content_charset_style_id( ): page = hr.Html() head = hr.Head() head.append(hr.Meta(charset="UTF-8")) head.append(hr.Title("PythonClass = Revision 1087:")) page.append(head) body = hr.Body() body.append(hr.H(2, "PythonClass - Example")) body.append( hr.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.Hr()) list = hr.Ul(id="TheList", style="line-height:200%") list.append(hr.Li("The first item in a list")) list.append(hr.Li("This is the second item", style="color: red")) item = hr.Li() item.append("And this is a ") item.append(hr.A("http://google.com", "link")) item.append("to google") list.append(item) body.append(list) page.append(body) render_page(page, "page.html") testdata = open("page.html").read() assert testdata == "<html>\n <head>\n <meta charset=\"UTF-8\" />\n <title>PythonClass = Revision 1087:</title>\n </head>\n <body>\n <h2>PythonClass - Example</h2>\n <p style=\"text-align: center; font-style: oblique;\">\n Here is a paragraph of text -- there could be more of them, but this is enough to show that we can do some text\n </p>\n <hr />\n <ul id=\"TheList\" style=\"line-height:200%\">\n <li>\n The first item in a list\n </li>\n <li style=\"color: red\">\n This is the second item\n </li>\n <li>\n And this is a \n <a href=\"http://google.com\">link</a>\n to google\n </li>\n </ul>\n </body>\n</html>"
def step8and9(): """ Steps 8 and 9 """ page = hr.Html() head = hr.Head() head.append(hr.Meta(charset="UTF-8")) head.append(hr.Title("PythonClass = Revision 1087:")) page.append(head) body = hr.Body() body.append(hr.H(2, "PythonClass - Class 6 example")) body.append( hr.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.Hr()) list = hr.Ul(id="TheList", style="line-height:200%") list.append(hr.Li("The first item in a list")) list.append(hr.Li("This is the second item", style="color: red")) item = hr.Li() item.append("And this is a") item.append(hr.A("http://google.com", "link")) item.append("to google") list.append(item) body.append(list) page.append(body) render_page(page, "test_html_output8.html") render_page(page, "test_html_output9.html", " ")
def test_head_element(): f = StringIO() test_head = h.Head() test_head.render(f) page = f.getvalue() expected_page = '<head>\n</head>\n' assert page == expected_page
def test_step6_output(step6_sample_output): """copied and pasted from run_html_render.py, step6. Expect this gives same result as test html""" page = hr.Html() head = hr.Head() head.append(hr.Title("PythonClass = Revision 1087:")) page.append(head) body = hr.Body() body.append( hr.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.Hr()) body.append("And this is a ") body.append(hr.A("http://google.com", "link")) body.append("to google") page.append(body) render_page(page, "test_html_output6.html") with open('test_html_output6.html') as f: generated_file = f.read() assert generated_file == step6_sample_output
def test_tags_element(): html_element = hr.Html('html content') assert html_element.tag == 'html', ('HTML tag Failure') assert html_element.indentation == 4, ('Html: Indentation Failure') assert html_element.contents == ['html content' ], ('Html: Contents Failure') body_element = hr.Body() assert body_element.tag == 'body', ('Body tag Failure') assert body_element.indentation == 4, ('Body: Indentation Failure') body_element.append('body append') assert body_element.contents == ['body append'], ('Body: Contents Failure') p_element = hr.P('initial', style="text-align: right") assert p_element.tag == 'p', ('P tag Failure') assert p_element.indentation == 4, ('P: Indentation Failure') p_element.append('appended') assert p_element.contents == ['initial', 'appended' ], ('P initial and append: Contents Failure') assert p_element.attrs == { 'style': 'text-align: right' }, ('P Dict: Attrs Failure') head_element = hr.Head('head content') assert head_element.tag == 'head', ('Head tag Failure') assert head_element.indentation == 4, ('Head: Indentation Failure') assert head_element.contents == ['head content' ], ('Head: Contents Failure')
def test_step3_output(step3_sample_output): """copied and pasted from run_html_render.py, step3. Expect this gives same result as test html""" page = hr.Html() head = hr.Head() head.append(hr.Title("PythonClass = Revision 1087:")) page.append(head) body = hr.Body() body.append( hr.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( hr. P("And here is another piece of text -- you should be able to add any number" )) page.append(body) render_page(page, "test_html_output3.html") with open('test_html_output3.html') as f: generated_file = f.read() assert generated_file == step3_sample_output
def test_step_6_html_output(): page = hr.Html() head = hr.Head() head.append(hr.Title("PythonClass = Revision 1087:")) page.append(head) body = hr.Body() body.append( hr.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.Hr()) body.append("And this is a ") body.append(hr.A("http://google.com", "link")) body.append("to google") page.append(body) f = StringIO() page.render(f) expected = "<!DOCTYPE html>\n" \ "<html>\n" \ " <head>\n" \ " <title>PythonClass = Revision 1087:</title>\n" \ " </head>\n" \ " <body>\n" \ ' <p style="text-align: center; font-style: oblique;">\n' \ " Here is a paragraph of text -- there could be more of them, but this is enough " \ " to show that we can do some text\n" \ " </p>\n" \ " <hr />\n" \ " And this is a \n" \ ' <a href="http://google.com">link</a>\n' \ " to google\n" \ " </body>\n" \ "</html>\n" assert f.getvalue() == expected
def test_step_3_html_output(): page = hr.Html() head = hr.Head() head.append(hr.Title("PythonClass = Revision 1087:")) page.append(head) body = hr.Body() body.append( hr.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( hr. P("And here is another piece of text -- you should be able to add any number" )) page.append(body) f = StringIO() page.render(f) expected = "<!DOCTYPE html>\n" \ "<html>\n" \ " <head>\n" \ " <title>PythonClass = Revision 1087:</title>\n" \ " </head>\n" \ " <body>\n" \ " <p>\n"\ " Here is a paragraph of text -- there could be more of them, but this is enough " \ " to show that we can do some text\n" \ " </p>\n" \ " <p>\n" \ " And here is another piece of text -- you should be able to add any number\n" \ " </p>\n" \ " </body>\n" \ "</html>\n" assert f.getvalue() == expected
def test_title(): page = hr.Html() head = hr.Head() head.append(hr.Title("PythonClass = Revision 1087:")) page.append(head) contents = render_result(page) assert "<title>PythonClass = Revision 1087:</title>" in contents
def test_Html_with_doctype_100(self): import html_render as hr # This repeated statement shouldn't # be needed, but I keep getting errors # without it here meta = hr.Meta(charset="\t UTF-8 \n") title = hr.Title("\n\nRandom \t Page \n\t ") head = hr.Head([meta, title]) li_1 = hr.Li(" First item: ") para = hr.P("\n\nExplanatory\t\ttext.\n\n", **consts.attrs_pass) link = hr.A("https://github.com/", "A useful site!") para.append(link) hr = hr.Hr() li_1.append([hr, para]) import html_render as hr # See previous comment li_2 = hr.Li("Second") br = hr.Br() li_2.append([br, "item"]) li_3 = hr.Li("Third item", onclick="\n\n\t EventHandler()\t \n") ul = hr.Ul([li_1, li_2, li_3]) body = hr.Body(ul) html = hr.Html((head, body)) with open(consts.test_filename, 'w') as self.fobj: self.assertTrue(html.render(self.fobj)) with open(consts.test_filename, 'r') as self.file: self.strs_out = self.file.readlines() self.assertEqual(len(self.strs_out), 27) # Verify total lines self.assertEqual(self.strs_out[0], '<!DOCTYPE html>\n') self.assertEqual(self.strs_out[1], '<html>\n') self.assertEqual(self.strs_out[2], '<head>\n') self.assertEqual(self.strs_out[3], '<meta charset="UTF-8" />\n') self.assertEqual(self.strs_out[4], '<title>Random Page</title>\n') self.assertEqual(self.strs_out[5], '</head>\n') self.assertEqual(self.strs_out[6], '<body>\n') self.assertEqual(self.strs_out[7], '<ul>\n') self.assertEqual(self.strs_out[8], '<li>\n') self.assertEqual(self.strs_out[9], 'First item:\n') self.assertEqual(self.strs_out[10], '<hr />\n') self.assertEqual(self.strs_out[11], '<p id="Marker" alt="Fancy Pants">\n') self.assertEqual(self.strs_out[12], 'Explanatory text.\n') self.assertEqual( self.strs_out[13], '<a href="https://github.com/">A useful site!</a>\n') self.assertEqual(self.strs_out[14], '</p>\n') self.assertEqual(self.strs_out[15], '</li>\n') self.assertEqual(self.strs_out[16], '<li>\n') self.assertEqual(self.strs_out[17], 'Second\n') self.assertEqual(self.strs_out[18], '<br />\n') self.assertEqual(self.strs_out[19], 'item\n') self.assertEqual(self.strs_out[20], '</li>\n') self.assertEqual(self.strs_out[21], '<li onclick="EventHandler()">\n') self.assertEqual(self.strs_out[22], 'Third item\n') self.assertEqual(self.strs_out[23], '</li>\n') self.assertEqual(self.strs_out[24], '</ul>\n') self.assertEqual(self.strs_out[25], '</body>\n') self.assertEqual(self.strs_out[26], '</html>\n') del meta, title, head, li_1, li_2, li_3, para, link, \ hr, br, ul, body, html
def test_Html_Head_Title_test_Content(): page = hr.Html() head = hr.Head() head.append(hr.Title("Test 8")) page.append(head) render_page(page, "page.html") testdata = open("page.html").read() assert testdata == "<html>\n <head>\n <title>Test 8</title>\n </head>\n</html>"
def test_doc_meta_tags(): """A function to test the added meta self-closing tag.""" page = hr.Html() head = hr.Head() head.append(hr.Meta(charset="UTF-8")) assert head.content[1].tag == ('<meta charset="UTF-8" />')
def test_3_Title(self): f = StringIO() head = hr.Head() head.append(hr.Title("Test Title")) head.content[0].render(f) current_element = f.getvalue() expected_element = '<title>Test Title</title>\n' self.assertEqual(current_element, expected_element)
def test_head_tag(self): comp_string = "<head>\n</head>\n" with open(path.join(self.test_dir, 'test.txt'), 'w') as f: test = hr.Head().render(f) with open(path.join(self.test_dir, 'test.txt')) as f: self.assertEqual(comp_string, f.read())
def test_head(): e = hr.Head() f = StringIO() e.render(f) f.seek(0) text = f.read().strip() assert text.startswith('<head>') assert text.endswith('</head>')
def test_render_head(self): """Test that render renders head tag.""" object = hr.Head("1") object.append("2") with open("outfile.html", "w") as outfile: object.render(outfile, cur_ind="") with open("outfile.html", "r") as infile: content = infile.read() assert content == "<head>\n1\n2\n</head>\n"
def test_head(): class_location = hr.Head("my_head") f = StringIO() class_location.render(f) f.seek(0) text = f.read().strip() assert text.startswith("<head>") assert text.endswith("</head>") assert "my_head" in text
def test_head(): e = hr.Head("this") f = StringIO() e.render(f) f.seek(0) text = f.read().strip() assert text.startswith("<head>") assert text.endswith("</head>") assert "this" in text
def test_head(): a = hr.Html() b = hr.Head('This is the header') a.append(b) output = StringIO() a.render(output) elements = ('<head>\n', 'This is the header \n', '</head>\n') for element in elements: assert element in output.getvalue()
def test_heading(): page = hr.Html() head = hr.Head() body = hr.Body() body.append(hr.H(2, "Heading 2")) body.append(hr.H(4, "Heading 4")) page.append(body) contents = render_result(page) assert "<h2>Heading 2</h2>" in contents assert "<h4>Heading 4</h4>" in contents
def setUp(self): self.html = hr.Html() self.head = hr.Head(hr.Title('The Title is Title')) self.body = hr.Body() self.paragraph = hr.P('This is my paragraph', style="color:blue;") self.horizontal_rule = hr.Hr() self.anchor = hr.A('http://chicktech.org', 'link') self.unorderedlist = hr.Ul(id="UL_List", style="line-height:100%") self.headertwo = hr.H(3, 'This is a Header 3 ') self.meta = hr.Meta(charset="UTF-8")
def generate_base(): taskList = routes.GatherData()._get() output = render.Html() header = render.Head() header.append(render.Meta(charset="UTF-8")) header.append(render.BootstrapLink()) header.append(render.Title("Task List")) output.append(header) body = render.Body() return taskList, output, body
def test_meta_tag(self): head = html.Head() head.append(html.Meta(charset="UTF-8")) outfile = io.StringIO() head.render(outfile) output = outfile.getvalue().strip().split('\n') print(output) self.assertEqual(output[0].strip(), '<head>') self.assertEqual(output[1].strip(), '<meta charset="UTF-8" />') self.assertEqual(output[-1].strip(), '</head>')
def test_head_tag_append(self): comp_string = '<head>\n <meta charset="UTF-8" /> \n</head>\n' with open(path.join(self.test_dir, 'test.txt'), 'w') as f: test = hr.Head() test.append(hr.Meta(charset="UTF-8")) test.render(f) with open(path.join(self.test_dir, 'test.txt')) as f: self.assertEqual(comp_string, f.read())
def test_Head(): eval = html_render.Head() eval.append('TESTING') top_eval = html_render.Html() top_eval.append(eval) f = StringIO() top_eval.render(f) actual = f.getvalue() expected = '<!DOCTYPE html>\n<html>\n<head>\n TESTING\n</head>\n</html>\n' assert actual == expected
def test_step8_html_output_using_ind_optional_input(): page = hr.Html(ind=0) head = hr.Head() head.append(hr.Meta(charset="UTF-8")) head.append(hr.Title("PythonClass = Revision 1087:")) page.append(head) body = hr.Body() body.append(hr.H(2, "PythonClass - Example")) body.append( hr.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.Hr()) list = hr.Ul(id="TheList", style="line-height:200%") list.append(hr.Li("The first item in a list")) list.append(hr.Li("This is the second item", style="color: red")) item = hr.Li() item.append("And this is a ") item.append(hr.A("http://google.com", "link")) item.append("to google") list.append(item) body.append(list) page.append(body) f = StringIO() page.render(f) expected = "<!DOCTYPE html>\n" \ "<html>\n" \ "<head>\n" \ '<meta charset="UTF-8" />\n' \ "<title>PythonClass = Revision 1087:</title>\n" \ "</head>\n" \ "<body>\n" \ "<h2>PythonClass - Example</h2>\n" \ '<p style="text-align: center; font-style: oblique;">\n' \ "Here is a paragraph of text -- there could be more of them, but this is enough " \ " to show that we can do some text\n" \ "</p>\n" \ "<hr />\n" \ '<ul id="TheList" style="line-height:200%">\n' \ "<li>\n" \ "The first item in a list\n" \ "</li>\n" \ '<li style="color: red">\n' \ "This is the second item\n" \ "</li>\n" \ "<li>\n" \ "And this is a \n" \ '<a href="http://google.com">link</a>\n' \ "to google\n" \ "</li>\n" \ "</ul>\n" \ "</body>\n" \ "</html>\n" assert f.getvalue() == expected
def test_Html_Head_Title_Body_P_test_Content_style(): page = hr.Html() head = hr.Head() head.append(hr.Title("Test 21")) page.append(head) body = hr.Body() body.append(hr.P("Test 22", style="Test 23")) page.append(body) render_page(page, "page.html") testdata = open("page.html").read() assert testdata == "<html>\n <head>\n <title>Test 21</title>\n </head>\n <body>\n <p style=\"Test 23\">\n Test 22\n </p>\n </body>\n</html>"
def test_head(): # pylint: disable=missing-function-docstring elem = hr.Head("this is some text") elem.append("and this is some more text") file_contents = render_result(elem).strip() assert "this is some text" in file_contents assert "and this is some more text" in file_contents assert file_contents.startswith("<head>") assert file_contents.endswith("</head>")
def test_Html_Head_Title_Body_P_test_Content(): page = hr.Html() head = hr.Head() head.append(hr.Title("Test 9")) page.append(head) body = hr.Body() body.append(hr.P("Test 10")) page.append(body) render_page(page, "page.html") testdata = open("page.html").read() assert testdata == "<html>\n <head>\n <title>Test 9</title>\n </head>\n <body>\n <p>\n Test 10\n </p>\n </body>\n</html>"