def test_br(): a = hr.Br() output = StringIO() a.render(output) assert "<br />\n" in output.getvalue() with pytest.raises(TypeError): a = hr.Br('some stuff')
def test_self_closing_element(): br = hr.Br() contents = render_result(br) assert contents.startswith("<br>") with pytest.raises(TypeError): br = hr.Br("this shouldn't work") contents = render_result(br)
def newTask(): taskList, output, body = renderFile().generate_base() body.append(render.H(1, "Add New Task")) body.append(render.Form("/tasklist/new")) body.append(render.Input("task")) body.append(render.Br()) body.append(render.Br()) body.append(render.Submit("Add Task")) output.append(body) return render.render_page(output, "index.html")
def test_br_element(): f = StringIO() test_br = h.Br() test_br.render(f) page = f.getvalue() expected_page = '<br />\n' assert page == expected_page
def test_Br_20(self): self.e1 = hr.Br(**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, '<br id="Marker" alt="Fancy Pants" />\n')
def test_Br_10(self): self.e1 = hr.Br() 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, '<br />\n')
def test_self_closing(): """Test that self-closing tags display as expected""" br = h.Br(id="br1") f = cStringIO.StringIO() br.render(f) f.reset() assert f.read() == '<br id="br1" />\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_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_br_with_content(): e = hr.Br('content that should not display') f = StringIO() e.render(f) f.seek(0) text = f.read().strip() assert text == '<br />' assert 'content that should not display' not in text
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_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(self): ''' Tests if a Br self closing tag is properly formatted. ''' test = hr.Br() test.tag_name = 'br' test_correct = '<br />\n' # need the newline f = StringIO() test.render(f) self.assertEqual(f.getvalue(), test_correct)
def test_Br1(self): """Verify formatting a passing works in Br""" Br = hr.Br(id="Format id", style="Format style") file_contents = render_result(Br).strip() print(file_contents) assert 'style="Format style"' in file_contents assert 'id="Format id"' in file_contents assert '<br ' in file_contents
def testRender(self): """testRender validates a basic Br render operation.""" want = ["<br />"] got = open(self.file_out, 'w') html_render.Br().render(got) got.close() self.assertTrue(validate_output(self.file_out, want))
def test_br_element(): """ Test rendering of br element """ h = hr.Br() f = StringIO() h.render(f, " ") f.seek(0) assert f.read() == " <br />\n"
def test_selfclosingtag_br(): """ Verifies that the self closing tag br is one line and outputed correctly. """ output = io.StringIO() e = hr.Br() e.render(output, "") file_cont = output.getvalue() assert "\n" not in file_cont[:-2] assert file_cont == "<br />"
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_br_in_p(): """ Test the creation f the br tag within the p tag. """ output = io.StringIO() p = hr.P("Testing, 1 2 3..") p.append(hr.Br()) p.append("More tests! We need more tests!") p.render(output, "") file_cont = output.getvalue().split('\n') print(file_cont) assert file_cont[2].strip() == "<br />"
def homepage(): taskList, output, body = renderFile().generate_base() body.append(render.H(1, "Task List")) body.append(render.A("/tasklist/new", "Add New Task")) unorderedList = render.Ul(id="unordered-task-list") for task in taskList: item = render.Li() item.append(task) item.append( render.A("/tasklist/"+(task).replace(" ", "-")+"/remove", "Delete")) item.append( render.A("/tasklist/"+(task).replace(" ", "-") + "/update", "Update")) item.append(render.Br()) unorderedList.append(item) body.append(unorderedList) output.append(body) return render.render_page(output, "index.html")
def test_Ul_100(self): self.e3 = hr.Br() self.e2 = [hr.Li(consts.strs_before[i]) for i in range(3)] self.e2.append( hr.Li(id=" \n \t First \n \n \t ", alt=" Hi \t\t there! \n")) self.e2[3].append( [consts.strs_before[3], self.e3, consts.strs_before[4]]) self.e2.append(hr.Li(consts.strs_before[-1])) self.e1 = hr.Ul(**consts.attrs_pass) self.e1.append(self.e2) 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: self.strs_out = self.file.readlines() self.assertEqual(len(self.strs_out), 19) # Verify total lines self.assertEqual(self.strs_out[0], '<ul id="Marker" alt="Fancy Pants">\n') self.assertEqual(self.strs_out[1], ' <li>\n') self.assertEqual(self.strs_out[2], f' {consts.strs_after[0]}\n') self.assertEqual(self.strs_out[3], ' </li>\n') self.assertEqual(self.strs_out[4], ' <li>\n') self.assertEqual(self.strs_out[5], f' {consts.strs_after[1]}\n') self.assertEqual(self.strs_out[6], ' </li>\n') self.assertEqual(self.strs_out[7], ' <li>\n') self.assertEqual(self.strs_out[8], f' {consts.strs_after[2]}\n') self.assertEqual(self.strs_out[9], ' </li>\n') self.assertEqual(self.strs_out[10], ' <li id="First" alt="Hi there!">\n') self.assertEqual(self.strs_out[11], f' {consts.strs_after[3]}\n') self.assertEqual(self.strs_out[12], ' <br />\n') self.assertEqual(self.strs_out[13], f' {consts.strs_after[4]}\n') self.assertEqual(self.strs_out[14], ' </li>\n') self.assertEqual(self.strs_out[15], ' <li>\n') self.assertEqual(self.strs_out[16], f' {consts.strs_after[5]}\n') self.assertEqual(self.strs_out[17], ' </li>\n') self.assertEqual(self.strs_out[18], '</ul>\n')
def test_Br_2(self): with self.assertRaises(TypeError): self.e1 = hr.Br(consts.strs_before[0], **consts.attrs_pass)
def test_Br_3(self): self.e1, self.e2 = hr.Br(), hr.Title() with self.assertRaises(TypeError): self.e1.append(self.e2)
def test_br_render(self): trial_elem = hr.Br() f = StringIO() trial_elem.render(f, cur_ind=1) standard = ' <br />\n' self.assertEqual(standard, f.getvalue())
def test_Br(): element = hr.Br() assert (element.tag_name == 'br')
def test_br(): br = hr.Br() contents = render_result(br) assert contents.startswith("<br>")
def test_append_to_br(): # Make sure our exception in the self-closing element works with pytest.raises(TypeError): br = hr.Br() br.append("this shouldn't work") contents = render_result(br)
def test_br_obj(self): # Tests br tag br_obj = hr.Br() self.assertEqual(br_obj.tag, "br /")
def test_br(): """Test br element""" elem = hr.Br(style="eggs") elem.set_attributes(id="spam") assert get_opening_line(elem) == '<br style="eggs" id="spam" />'
def test_Br(self): test = h.Br() f = StringIO() test.render(f) self.assertEqual(f.getvalue(), "<br>\n</br>\n")