def test_H_100(self):
     self.e2 = [hr.H(i, consts.strs_before[i - 1]) for i in range(1, 6)]
     self.e3 = hr.P("\tText   under \n heading   \t5.    \n\t")
     self.e2.append(self.e3)
     self.e2.append(hr.H(6, consts.strs_after[5], alt='Some hover text'))
     self.e1 = hr.Body(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), 11)  # Verify total lines
         self.assertEqual(self.strs_out[0], '<body>\n')
         self.assertEqual(self.strs_out[1],
                          f'  <h1>{consts.strs_after[0]}</h1>\n')
         self.assertEqual(self.strs_out[2],
                          f'  <h2>{consts.strs_after[1]}</h2>\n')
         self.assertEqual(self.strs_out[3],
                          f'  <h3>{consts.strs_after[2]}</h3>\n')
         self.assertEqual(self.strs_out[4],
                          f'  <h4>{consts.strs_after[3]}</h4>\n')
         self.assertEqual(self.strs_out[5],
                          f'  <h5>{consts.strs_after[4]}</h5>\n')
         self.assertEqual(self.strs_out[6], f'  <p>\n')
         self.assertEqual(self.strs_out[7], f'    Text under heading 5.\n')
         self.assertEqual(self.strs_out[8], f'  </p>\n')
         self.assertEqual(
             self.strs_out[9],
             f'  <h6 alt="Some hover text">{consts.strs_after[5]}</h6>\n')
         self.assertEqual(self.strs_out[10], '</body>\n')
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 test_h(self):
        h1 = hr.H(1, 'Heading 1')
        h3 = hr.H(3, 'Heading 3')
        h5 = hr.H(5, 'Heading 5')

        h1 = self.render_page(h1, "")
        h3 = self.render_page(h3, "")
        h5 = self.render_page(h5, "")

        self.assertTrue(h1.startswith("<h1>"))
        self.assertTrue(h3.startswith("<h3>"))
        self.assertTrue(h5.startswith("<h5>"))
def test_heading_building():
    page = hr.Html()
    page.append(hr.H(1, "this is heading 1"))
    page.append(hr.H(2, "this is heading 2"))
    page.append(hr.H(1, "this is a red heading 1", color="red"))
    f = StringIO()
    page.render(f)
    expected = "<!DOCTYPE html>\n" \
               "<html>\n" \
               "   <h1>this is heading 1</h1>\n" \
               "   <h2>this is heading 2</h2>\n" \
               '   <h1 color="red">this is a red heading 1</h1>\n' \
               "</html>\n"
    assert f.getvalue() == expected
Beispiel #5
0
 def test_7_H(self):
     f = StringIO()
     header = hr.H(2, "PythonClass - Class 6 example")
     header.render(f)
     actual = f.getvalue()
     expected = '<h2>PythonClass - Class 6 example</h2>\n'
     self.assertEqual(actual, expected)
 def test_h(self):
     object = hr.H(2, "PythonClass - Class 6 example")
     with open("outfile.html", "w") as outfile:
         object.render(outfile, cur_ind="")
     with open("outfile.html", "r") as infile:
         content = infile.read()
         assert content == '<h2> PythonClass - Class 6 example </h2>\n'
Beispiel #7
0
 def test_H(self):
     """Test a header class to create this tag:
     <h2>PythonClass - Class 6 example</h2>"""
     h2_class = hr.H(2, "PythonClass - Class 6 example")
     file_contents = render_result(h2_class)
     print(file_contents)
     assert '<h2>PythonClass - Class 6 example</h2>' in file_contents
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_header_tag():
    headertest = hr.H(2, "Happy Header Test")
    f = StringIO()
    headertest.render(f)
    assert f.getvalue() == "<h2>Happy Header Test</h2>\n"    
    
    
def test_H():
    eval = html_render.H(2, 'TESTING')
    f = StringIO()
    eval.render(f)
    actual = f.getvalue()
    expected = '<h2>TESTING</h2>\n'
    assert actual == expected
def test_header():
    """Test headers are constructed and rendered as expected"""
    h2 = h.H(2, "Second-level-heading")
    f = cStringIO.StringIO()
    h2.render(f)
    f.reset()
    assert f.read() == "<h2>Second-level-heading</h2>\n"
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>"
Beispiel #13
0
def test_header():
    sometext = "Header text"
    h = html_render.H(2, sometext)
    output = render_element(h, indent_spaces)
    print("\n" + output)
    assert "{}{}{}{}".format(indent_spaces, "<h2>", sometext,
                             "</h2>\n") == output
def test_h_element():
    f = StringIO()
    test_a = h.H(8, "Google")
    test_a.render(f)
    page = f.getvalue()
    expected_page = '<h8>Google</h8>\n'
    assert page == expected_page
Beispiel #15
0
def test_h():
    """Test h element"""
    for h_number in [1, 2, 3]:
        elem = hr.H(h_number, "some spam", style="eggs")

        assert (get_opening_line(elem) ==
                f'<h{h_number:d} style="eggs">some spam</h{h_number:d}>')
 def test_body_content(self):
     body = html.Body()
     body.append(html.H(2, "PythonClass - Example"))
     content = MyTestCase.render_element(body)
     self.assertTrue(content.startswith('<body>'))
     self.assertIn('<h2>PythonClass - Example</h2>', content)
     self.assertTrue(content.endswith('</body>'))
     print(content)
Beispiel #17
0
 def removeTask(input):
     taskList, output, body = renderFile().generate_base()
     body.append(render.H(1, "Remove Task: " + input.replace("-", " ")))
     body.append(render.Form("/task/" + input + "/remove"))
     body.append(render.Submit("Remove", input))
     body.append(render.A("/tasklist", "Cancel"))
     output.append(body)
     return render.render_page(output, "index.html")
 def test_H(self):
     ''' Tests for a proper H1level '''
     test = hr.H(1, "Test")
     test_correct = "<h1>Test</h1>\n"
     f = StringIO()
     test.render(f)
     print(f.getvalue())
     self.assertEqual(f.getvalue(), test_correct)
Beispiel #19
0
 def test_H(self):
     self.assertTrue(issubclass(hr.H, hr.Element))
     obj = hr.H(2, 'headertext')
     self.assertIsInstance(obj, hr.H)
     self.assertIsInstance(obj, hr.Element)
     self.assertTrue(obj.tag == 'h')
     self.assertTrue(type(obj.size) == int)
     self.assertTrue(type(obj.text) == str)
     self.assertTrue(hasattr(obj, 'render'))
Beispiel #20
0
def test_H():
    e = hr.H(1, 'this')
    f = StringIO()
    e.render(f)
    f.seek(0)
    text = f.read().strip()
    assert text.startswith('<h1>')
    assert text.endswith('</h1>')
    assert 'this' in text
    assert '\n' not in text
Beispiel #21
0
def test_header_links():
    h_tag = hr.H(3, "Testing H = 3")
    assert h_tag.tag == 'h3', ('H: tag failure')
    assert h_tag.contents == ['Testing H = 3'], ('H: content failure')
    link_tag = hr.A("http://google.com", "link")
    assert link_tag.tag == 'a', ('A: tag failure')
    assert link_tag.contents == ['link'], ('A link: content failure')
    assert link_tag.attrs == {
        'href': 'http://google.com'
    }, ('attrs: link failure')
def test_h_level_two_element():
    """ Test rendering of h2 element
    """
    h = hr.H(2, "Level Two")

    f = StringIO()
    h.render(f, "    ")

    f.seek(0)
    assert f.read() == "    <h2>Level Two</h2>\n"
def test_h_level_element():
    """ Test rendering of h1 element
    """
    h = hr.H(1, "Level 1")

    f = StringIO()
    h.render(f, "    ")

    f.seek(0)
    assert f.read() == "    <h1>Level 1</h1>\n"
Beispiel #24
0
 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")
Beispiel #25
0
 def updateTask(input):
     taskList, output, body = renderFile().generate_base()
     body.append(render.H(1, "Update Task: " + input.replace("-", " ")))
     body.append(render.Form("/tasklist/" + input.replace(
         "%20", " ") + "/update"))
     body.append(render.Input("update", input))
     body.append(render.Submit("Update", input))
     body.append(render.A("/tasklist", "Cancel"))
     output.append(body)
     return render.render_page(output, "index.html")
Beispiel #26
0
 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_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 testRender(self):
        """testRender validates a basic H render operation."""
        given = 'hello H'
        given_level = 2
        want = ["<h2>{}</h2>".format(given)]

        got = open(self.file_out, 'w')
        html_render.H(given_level, given).render(got, '', True)
        got.close()

        self.assertTrue(validate_output(self.file_out, want))
def test_header():
    """
    Verify header tag was created correctly
    """
    output = io.StringIO()
    h1 = hr.H(1, "More tests! We need more tests!")
    h1.render(output, "")
    file_cont = output.getvalue()
    assert file_cont.strip().startswith("<h1>")
    assert file_cont.strip().endswith("</h1>")
    assert "More tests! We need more tests!" in file_cont
def test_h2():
    html = hr.Html()
    body = hr.Body()
    body.append(hr.H(2, "sample"))
    html.append(body)

    f = StringIO()
    html.render(f)
    f.seek(0)
    text = f.read().strip()
    print(text)
    assert text.find("<h2>sample</h2>") != -1