def testRender(self):
        """testRender validates a basic TextHtml render operation."""
        given = 'hello Html'
        want = [
            "<!DOCTYPE html>",
            "<html>",
            "{}{}".format(html_render.Html().ind, given),
            "</html>",
        ]

        got = open(self.file_out, 'w')
        html_render.Html(given).render(got)
        got.close()

        self.assertTrue(validate_output(self.file_out, want))
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_html_element_render_w_indent_w_two_lines():
    page = hr.Html("one")
    page.append("two")
    f = StringIO()
    page.render(f, "   ")
    expected = "   <!DOCTYPE html>\n   <html>\n      one\n      two\n   </html>\n"
    assert f.getvalue() == expected
Ejemplo n.º 5
0
    def test_sub_element_2(self):
        """
        Test that you can add another element and still render properly
        """

        page = hr.Html()
        page.append(hr.Title('Some HTML Page'))
        page.append(hr.Body('This is my body'))
        page.append("some plain text.")
        page.append(hr.P("A simple paragraph of text"))
        page.append("Some more plain text.")

        file_contents = render_result(page)
        print(file_contents)  # so we can see it if the test fails

        assert "Some HTML Page" in file_contents
        assert "This is my body" in file_contents
        assert "some plain text" in file_contents
        assert "A simple paragraph of text" in file_contents
        assert "Some more plain text." in file_contents
        # but make sure the embedded element's tags get rendered!
        assert "<p" in file_contents
        assert "</p>" in file_contents
        assert '<title' in file_contents
        assert '<html' in file_contents
        assert '<body' in file_contents
Ejemplo n.º 6
0
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_html_element():
    f = StringIO()
    test_html = h.Html()
    test_html.render(f)
    page = f.getvalue()
    expected_page = '<!DOCTYPE html>\n<html>\n</html>\n'
    assert page == expected_page
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_html_class_creation():
    """A function to test the creation of html
    objects on the page."""
    page = hr.Html()

    assert page.open_tag == ("<html>")
    assert page.close_tag == ("</html>")
 def test_append_body_html(self):
     f = StringIO()
     testelement = hr.Html()
     body = hr.Body()
     testelement.append(body)
     testelement.render(f)
     print(f.getvalue())
def test_Html_Body():
    page = hr.Html()
    body = hr.Body()
    page.append(body)
    render_page(page, "page.html")
    testdata = open("page.html").read()
    assert testdata == "<html>\n    <body>\n    </body>\n</html>"
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_html():
    """Test that the html tag displays the DOCTYPE line"""
    html = h.Html()
    f = cStringIO.StringIO()
    html.render(f)
    f.reset()
    assert f.read() == "<!DOCTYPE html>\n<html></html>\n"
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", "    ")
Ejemplo n.º 15
0
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
Ejemplo n.º 16
0
def test_append():
    page = hr.Html()
    body = hr.Body()
    body.append("this is a test")
    page.append(body)
    contents = render_result(page)
    assert "this is a test" in contents
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_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
Ejemplo n.º 19
0
def test_Html_DOCTYPE():
    e = hr.Html()
    f = StringIO()
    e.render(f)
    f.seek(0)
    text = f.read().strip()
    assert text.startswith('<!DOCTYPE html>\n')
    assert text.endswith('</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_Html_Body_P_test_Content_style():
    page = hr.Html()
    body = hr.Body()
    body.append(hr.P("Test 19", style="Test 20"))
    page.append(body)
    render_page(page, "page.html")
    testdata = open("page.html").read()
    assert testdata == "<html>\n    <body>\n        <p style=\"Test 20\">\n            Test 19\n        </p>\n    </body>\n</html>"
Ejemplo n.º 22
0
def test_html():
    a = hr.Html('Some Content.')
    a.append('Some more Content.')
    output = StringIO()
    a.render(output)
    assert f'<html>\n    Some Content. Some more Content. \n</html>\n' in output.getvalue()
    assert '<!DOCTYPE html>\n' in output.getvalue()
    output.close()
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" />')
Ejemplo n.º 24
0
 def test_render_html(self):
     """Test that render renders html tag."""
     object = hr.Html("1")
     with open("outfile.html", "w") as outfile:
         object.render(outfile, cur_ind="")
     with open("outfile.html", "r") as infile:
         content = infile.read()
         assert content == "<!DOCTYPE html>\n<html>\n1\n</html>\n"
 def test_html_class(self):
     '''Verify the Html.render function overrides Element.render'''
     new_html = hr.Html()
     self.assertEqual(new_html.tag, 'html')
     output = StringIO()
     new_html.render(output)
     self.assertEqual(output.getvalue(),
                      '<!DOCTYPE html>\n<html>\n</html>\n')
 def test_Html_append(self):
     f = StringIO()
     testelement = hr.Html()
     testelement.append('test1')
     testelement.append('test2')
     testelement.render(f)
     self.assertEqual(f.getvalue(),
                      "<!DOCTYPE html>\n<html>\ntest1\ntest2\n</html>\n")
Ejemplo n.º 27
0
 def test_basic_tags(self):
     """Run a test for html, body, and p tags"""
     test_content = hr.Html(hr.Body(hr.P("test string")))
     f = StringIO()
     test_content.render(f)
     expected = "<!DOCTYPE html>\n<html>\n    <body>\n        <p>\n            test string\n        </p>\n    </body>\n</html>\n"
     actual = f.getvalue()
     self.assertEqual(expected, actual)
Ejemplo n.º 28
0
def test_html():
    e = hr.Html("this is some text")
    e.append("and this is some more text")
    file_contents = render_result(e).strip()
    assert "this is some text" in file_contents
    assert "and this is some more text" in file_contents
    print(file_contents)
    assert file_contents.endswith("</html>")
Ejemplo n.º 29
0
    def test_html_tag(self):

        comp_string = "<!DOCTYPE html>\n<html>\n</html>\n"

        with open(path.join(self.test_dir, 'test.txt'), 'w') as f:
            test = hr.Html().render(f)

        with open(path.join(self.test_dir, 'test.txt')) as f:
            self.assertEqual(comp_string, f.read())
def test_Html_Body_P_test_Content():
    page = hr.Html()
    body = hr.Body()
    body.append(hr.P("Test 4"))
    body.append(hr.P("Test 5"))
    page.append(body)
    render_page(page, "page.html")
    testdata = open("page.html").read()
    assert testdata == "<html>\n    <body>\n        <p>\n            Test 4\n        </p>\n        <p>\n            Test 5\n        </p>\n    </body>\n</html>"