예제 #1
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
def test_Title():
    eval = html_render.Title('TESTING')
    f = StringIO()
    eval.render(f)
    actual = f.getvalue()
    expected = '<title>TESTING</title>\n'
    assert actual == expected
예제 #3
0
def test_onelinetag():
    e = hr.Title("this")
    f = StringIO()
    e.render(f)
    f.seek(0)
    text = f.read().strip()
    assert text == ("<title>this</title>")
예제 #4
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
def test_OneLineTag_render(
):  #using title subclass as simple content to test render function with
    sample = html_render.Title()
    f = StringIO()
    sample.render(f)
    g = f.getvalue()
    assert g == "<title></title>\n"
def test_title_element():
    f = StringIO()
    test_title = h.Title()
    test_title.render(f)
    page = f.getvalue()
    expected_page = '<title></title>\n'
    assert page == expected_page
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_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>"
예제 #9
0
 def test_Title(self):
     self.assertTrue(issubclass(hr.Title, hr.Element))
     obj = hr.Title('this is a test')
     self.assertIsInstance(obj, hr.Title)
     self.assertIsInstance(obj, hr.Element)
     self.assertTrue(obj.tag == 'title')
     self.assertTrue(hasattr(obj, 'render'))
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_render_append_to_nonempty_content():
    page = hr.Title("this is a title")
    page.append("this is a second title")
    f = StringIO()
    page.render(f)
    expected = "<title>this is a title this is a second title</title>\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_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_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>"
예제 #17
0
 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)
예제 #18
0
    def test_title_tag(self):
        comp_string = '    <title>Title</title>\n'

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

        with open(path.join(self.test_dir, 'test.txt')) as f:
            self.assertEqual(comp_string, f.read())
예제 #19
0
def test_title():
    e = hr.Title("this")
    f = StringIO()
    e.render(f)
    f.seek(0)
    text = f.read().strip()
    assert text.startswith("<title>")
    assert text.endswith("</title>")
    assert "this" in text
예제 #20
0
 def test_attributes(self):
     title = hr.Title("A Title",
                      style="text-align: center; font-style: oblique;")
     f = StringIO()
     title.render(f)
     self.assertEqual(
         f.getvalue(),
         "<title style=\"text-align: center; font-style: oblique;\">A Title</title>\n"
     )
예제 #21
0
 def test_title(self):
     """Test that renders single line title."""
     object = hr.Title("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 == "<title> 12 </title>\n"
예제 #22
0
def test_one_line_element():
    title = hr.Title("this is the title")
    # test with no attribute
    p = hr.P()
    contents = render_result(title)
    assert contents.startswith("<title>this is the title</title>")
    contents = render_result(p)
    assert contents.startswith("<p></p>")
    print(contents)
예제 #23
0
    def test_Title(self):
        """Test that Title renders one line encapsulated with html title."""
        e = hr.Title("This is a Title")
        file_contents = render_result(e).strip()

        assert "This is a Title" in file_contents
        print(file_contents)
        assert file_contents.startswith("<title>")
        assert file_contents.endswith("</title>")
def test_title_oneline():
    """Test that the title tag displays on one line (implicitly tests inline performance)"""
    t = h.Title(
        "PythonClass - Session 6 example blah blah I'm so long blaaaaaaah")
    f = cStringIO.StringIO()
    t.render(f)
    f.reset()
    assert f.read(
    ) == "<title>PythonClass - Session 6 example blah blah I'm so long blaaaaaaah</title>\n"
예제 #25
0
def test_title_tag():
    """ Test rendering of a title element
    """
    title = hr.Title("This is my title")

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

    f.seek(0)
    assert f.read() == "    <title>This is my title</title>\n"
예제 #26
0
def test_subclasses():
    onelinetag = hr.OneLineTag()
    assert onelinetag.tag == '', ('onelinetag: Tag Failure')
    title_tag = hr.Title('Title Of')
    assert title_tag.tag == 'title', ('Title: Tag Failure')
    assert title_tag.contents == ['Title Of'], ('Title: Content Failure')
    self_closing = hr.SelfClosingTag('SCT')
    assert self_closing.tag == '', ('SelfClosingTag: Tag Failure')
    assert self_closing.contents == ['SCT'
                                     ], ('SelfClosingTag: Content Failure')
    def testRender(self):
        """testRender validates a basic Title render operation."""
        given = 'hello Title'
        want = ["<title>{}</title>".format(given)]

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

        self.assertTrue(validate_output(self.file_out, want))
예제 #28
0
 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
예제 #29
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")
예제 #30
0
def test_title():
    e = hr.Title('this')
    f = StringIO()
    e.render(f)
    f.seek(0)
    text = f.read().strip()
    assert text.startswith('<title>')
    assert text.endswith('</title>')
    assert 'this' in text
    assert '\n' not in text