def test_hr(self): hzr = hr.Hr() self.assertEqual(self.rendercap(hzr), '<hr />\n') hzr = hr.Hr('', style='text-align: center;') self.assertEqual(self.rendercap(hzr), '<hr style="text-align: center;" />\n')
def test_hr(): a = hr.Hr() output = StringIO() a.render(output) assert "<hr />\n" in output.getvalue() with pytest.raises(TypeError): a = hr.Hr('some stuff')
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 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_Hr(): eval = html_render.Hr() f = StringIO() eval.render(f) actual = f.getvalue() expected = '<hr />\n' assert actual == expected
def test_SelfClosingTag_render( ): #using hr subclass as simple content to test render function with sample = html_render.Hr() f = StringIO() sample.render(f) g = f.getvalue() assert g == "<hr />\n"
def test_hr(): e = hr.Hr() f = StringIO() e.render(f) f.seek(0) text = f.read().strip() assert text == '<hr />'
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_Hr_20(self): self.e1 = hr.Hr(**consts.attrs_pass) with open(consts.test_filename, 'w') as self.fobj: self.assertTrue(self.e1.render(self.fobj, ' ')) with open(consts.test_filename, 'r') as self.file: str_out = self.file.read() self.assertEqual(str_out, '<hr id="Marker" alt="Fancy Pants" />\n')
def test_SelfClosingTag_25(self): # Within large doc hierarchy horizontal_rule = hr.Hr(**consts.attrs_pass) line_break = hr.Br(id='My' + consts.attrs_pass['id'], alt=consts.attrs_pass['alt'] + ' and Shirts') para = hr.P(consts.strs_before[0]) para.append(line_break) para.append(consts.strs_before[1]) body = hr.Body() body.append(horizontal_rule) body.append(para) with open(consts.test_filename, 'w') as self.fobj: self.assertTrue(body.render(self.fobj, ' ')) with open(consts.test_filename, 'r') as self.file: self.strs_out = self.file.readlines() self.assertEqual(len(self.strs_out), 8) # Verify total lines self.assertEqual(self.strs_out[0], '<body>\n') self.assertEqual(self.strs_out[1], ' <hr id="Marker" alt="Fancy Pants" />\n') self.assertEqual(self.strs_out[2], ' <p>\n') self.assertEqual(self.strs_out[3], f' {consts.strs_after[0]}\n') self.assertEqual( self.strs_out[4], ' <br id="MyMarker" alt="Fancy Pants and Shirts" />\n') self.assertEqual(self.strs_out[5], f' {consts.strs_after[1]}\n') self.assertEqual(self.strs_out[6], ' </p>\n') self.assertEqual(self.strs_out[7], '</body>\n') del horizontal_rule, line_break, para, body
def test_Hr_10(self): self.e1 = hr.Hr() with open(consts.test_filename, 'w') as self.fobj: self.assertTrue(self.e1.render(self.fobj, ' ')) with open(consts.test_filename, 'r') as self.file: str_out = self.file.read() self.assertEqual(str_out, '<hr />\n')
def test_Hr(self): self.assertTrue(issubclass(hr.Hr, hr.SelfClosingTag)) obj = hr.Hr() self.assertIsInstance(obj, hr.Hr) self.assertIsInstance(obj, hr.SelfClosingTag) self.assertIsInstance(obj, hr.Element) self.assertTrue(obj.tag == 'hr')
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 test_hr_element(): f = StringIO() test_hr = h.Hr() test_hr.render(f) page = f.getvalue() expected_page = '<hr />\n' assert page == expected_page
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_self_closing_tags(): hr_tag = hr.Hr() assert hr_tag.tag == 'hr', ('Hr: tag failure') br_tag = hr.Br('BR Value') assert br_tag.contents == ['BR Value'], ('Br: contents failure') assert br_tag.tag == 'br', ('Br: tag failure') meta_tag = hr.Meta() assert meta_tag.tag == 'meta', ('Meta: tag failure')
def test_self_closing_tag_init_w_content_raises_error(): message = "" try: _ = hr.Hr("this is content") except TypeError as e: message = e.args[0] finally: assert message == "'SelfClosingTag' object cannot have any content"
def test_hrtag(self): """Test that renders hr tag.""" object = hr.Hr() with open("outfile.html", "w") as outfile: object.render(outfile, cur_ind="") with open("outfile.html", "r") as infile: content = infile.read() assert content == "<hr />\n"
def test_self_closing_tags(): """A function to test the creation and implementation of the self-closing tag objects.""" horiz_rule = hr.Hr() line_break = hr.Br() assert horiz_rule.tag == ("<hr />") assert line_break.tag == ("<br />")
def test_Html_Boidy_P_Hr_test_Content_style(): page = hr.Html() body = hr.Body() body.append(hr.P("Test 26", style="Test 27")) body.append(hr.Hr()) page.append(body) render_page(page, "page.html") testdata = open("page.html").read() assert testdata == "<html>\n <body>\n <p style=\"Test 27\">\n Test 26\n </p>\n <hr />\n </body>\n</html>"
def testRender(self): """testRender validates a basic Hr render operation.""" want = ["<hr />"] got = open(self.file_out, 'w') html_render.Hr().render(got) got.close() self.assertTrue(validate_output(self.file_out, want))
def test_5_SelfClosingTag(self): try: horizontal = hr.Hr('unexpected content') except TypeError: actual = 'TypeError' else: actual = 'OK' expected = 'TypeError' self.assertEqual(actual, expected)
def test_hr_element(): """ Test rendering of hr element """ h = hr.Hr() f = StringIO() h.render(f, " ") f.seek(0) assert f.read() == " <hr />\n"
def test_selfclosingtag_hr(): """ Verifies that the self closing tag hr is one line and outputed correctly. """ output = io.StringIO() e = hr.Hr() e.render(output, "") file_cont = output.getvalue() assert "\n" not in file_cont[:-2] assert file_cont == "<hr />"
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 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_5(): page_test = hr.Html() body = hr.Body() body.append(hr.Hr()) page_test.append(body) hr.render_page(page_test, "test_5_hr_class.htm") test_file = f"{tmp_directory}test_5_hr_class.htm" hash_object_open = hashlib.md5() with open(test_file, 'rb') as afile: buf = afile.read() hash_object_open.update(buf) assert hash_object_open.hexdigest() == "e19ef5bfaf2983b57fc6cbeeb6e55341"
def test_Html_Head_Title_Body_P_Hr_test_Content_style(): page = hr.Html() head = hr.Head() head.append(hr.Title("Test 28")) page.append(head) body = hr.Body() body.append(hr.P("Test 29", style="Test 30")) body.append(hr.Hr()) page.append(body) render_page(page, "page.html") testdata = open("page.html").read() assert testdata == "<html>\n <head>\n <title>Test 28</title>\n </head>\n <body>\n <p style=\"Test 30\">\n Test 29\n </p>\n <hr />\n </body>\n</html>"
def test_sc_tags(self): comp_string = '<hr /> \n<br /> \n' with open(path.join(self.test_dir, 'test.txt'), 'w') as f: test = hr.Hr() test.indent = "" test.render(f, "") test = hr.Br() test.indent = "" test.render(f, "") with open(path.join(self.test_dir, 'test.txt')) as f: self.assertEqual(comp_string, str(f.read()))
def test_Html_Head_Title_Body_P_Hr_A_test_Content(): page = hr.Html() head = hr.Head() head.append(hr.Title("Test 42")) page.append(head) body = hr.Body() body.append(hr.P("Test 43", style="Test 44")) body.append(hr.Hr()) body.append("Test 45 ") body.append(hr.A("Test 46", "Test 47")) body.append(" Test 48") page.append(body) render_page(page, "page.html") testdata = open("page.html").read() assert testdata == "<html>\n <head>\n <title>Test 42</title>\n </head>\n <body>\n <p style=\"Test 44\">\n Test 43\n </p>\n <hr />\n Test 45 \n <a href=\"Test 46\">Test 47</a>\n Test 48\n </body>\n</html>"