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

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

        self.assertTrue(validate_output(self.file_out, want))
def test_ul_element():
    f = StringIO()
    test_ul = h.Ul()
    test_ul.render(f)
    page = f.getvalue()
    expected_page = '<ul>\n</ul>\n'
    assert page == expected_page
Ejemplo n.º 3
0
def test_ul():
    a = hr.Ul()
    output = StringIO()
    a.render(output)
    tags = ('<ul>', '</ul>')
    for tag in tags:
        assert tag in output.getvalue()
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_Ul_render(self):
     f = StringIO()
     testelement = hr.Ul(id="TheList", style="line-height:200%")
     testelement.render(f)
     self.assertEqual(
         f.getvalue(),
         '<ul id="TheList" style="line-height:200%">\n</ul>\n')
 def test_Li_render(self):
     f = StringIO()
     testelement = hr.Ul()
     testelement.append(hr.Li("test1"))
     testelement.render(f)
     self.assertEqual(f.getvalue(),
                      '<ul>\n    <li>\n        test1\n    </li>\n</ul>\n')
Ejemplo n.º 7
0
 def test_ul(self):
     object = hr.Ul(id="TheList", style="line-height:200%")
     with open("outfile.html", "w") as outfile:
         object.render(outfile, cur_ind="")
     with open("outfile.html", "r") as infile:
         content = infile.read()
         assert content == '<ul id="TheList", style="line-height:200%">\n</ul>\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>"
 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.º 10
0
def test_ul():
    e = hr.Ul()
    f = StringIO()
    e.render(f)
    f.seek(0)
    text = f.read().strip()
    assert text.startswith('<ul>')
    assert text.endswith('</ul>')
def test_Ul_Li_A_test_Content_id_style():
    unordered = hr.Ul(id="Test 56", style="Test 57")
    item = hr.Li()
    item.append("Test 58")
    item.append(hr.A("Test 59", "Test 60"))
    item.append(" Test 61")
    unordered.append(item)
    testdata = unordered.content
    assert testdata == "<ul id=\"Test 56\" style=\"Test 57\">\n    <li>\n        Test 58\n        <a href=\"Test 59\">Test 60</a>\n         Test 61\n    </li>\n</ul>"
Ejemplo n.º 12
0
 def test_ul(self):
     """Test the bulleted list <ul> tag."""
     ul_class = hr.Ul(style="line-height:200%", id="TheList")
     ul_class.append(hr.Li('The first item in a list.'))
     ul_class.append(hr.Li('The second item in a list', style="color:red"))
     file_contents = render_result(ul_class)
     print(file_contents)
     assert '<ul style="line-height:200%" id="TheList">' in file_contents
     assert '</ul>' in file_contents
Ejemplo n.º 13
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")
Ejemplo n.º 14
0
 def test_list_tags(self):
     """Run a test for list tags"""
     test_list = hr.Ul("Test List")
     test_list.append(hr.Li("Thing one"))
     test_list.append(hr.Li("Thing two"))
     f = StringIO()
     test_list.render(f)
     expected = '<ul>\n    Test List\n    <li>\n        Thing one\n    </li>\n    <li>\n        Thing two\n    </li>\n</ul>\n'
     actual = f.getvalue()
     self.assertEqual(expected, actual)
Ejemplo n.º 15
0
    def test_ul_tag_style(self):
        comp_string = '<ul id="TheList" style="line-height:200%">\n</ul>\n'

        with open(path.join(self.test_dir, 'test.txt'), 'w') as f:
            test = hr.Ul(id="TheList", style="line-height:200%")
            test.indent = ''
            test.render(f)

        with open(path.join(self.test_dir, 'test.txt')) as f:
            self.assertEqual(comp_string, f.read())
Ejemplo n.º 16
0
    def test_ul_tag(self):
        comp_string = '<ul>\n</ul>\n'

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

        with open(path.join(self.test_dir, 'test.txt')) as f:
            self.assertEqual(comp_string, f.read())
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_Ul_Li_A_test_Content_id_style_2():
    unordered = hr.Ul(id="Test 62", style="Test 63")
    unordered.append(hr.Li("Test 64"))
    unordered.append(hr.Li("Test 65", style="Test 66"))
    item = hr.Li()
    item.append("Test 67")
    item.append(hr.A("Test 68", "Test 69"))
    item.append(" Test 70")
    unordered.append(item)
    testdata = unordered.content
    assert testdata == "<ul id=\"Test 62\" style=\"Test 63\">\n    <li>\n        Test 64\n    </li>\n    <li style=\"Test 66\">\n        Test 65\n    </li>\n    <li>\n        Test 67\n        <a href=\"Test 68\">Test 69</a>\n         Test 70\n    </li>\n</ul>"
def test_lists():
    """A function to test the creation and implementation of
    unordered list and list item objects."""
    u_list = hr.Ul(id="TheList", style="line-height:200%")

    assert u_list.open_tag == ('<ul style="line-height:200%" id="TheList">')

    u_list.append(hr.Li("The first item in a list"))
    u_list.append(hr.Li("This is the second item", style="color: red"))

    assert u_list.content[1].content[0] == ("The first item in a list")
    assert u_list.content[2].content[0] == ("This is the second item")
Ejemplo n.º 20
0
 def test_Ul(self):
     self.assertTrue(issubclass(hr.Ul, hr.Element))
     obj = hr.Ul()
     self.assertIsInstance(obj, hr.Ul)
     self.assertIsInstance(obj, hr.Element)
     self.assertTrue(obj.tag == 'ul')
     self.assertTrue(hasattr(obj, 'props'))
     self.assertTrue(type(obj.props) == list)
     self.assertTrue(len(obj.props) == 0)
     self.assertTrue(hasattr(obj, 'propstring'))
     self.assertTrue(type(obj.propstring) == str)
     self.assertTrue(len(obj.propstring) == 0)
Ejemplo n.º 21
0
def test_ul():
    """
    Verify ul tag is displayed correctly.
    """
    output = io.StringIO()
    ul = hr.Ul("Testing, 1 2 3..", style="line-height:200%", id="TheList")
    ul.render(output, "")
    file_cont = output.getvalue()
    assert file_cont.strip().startswith('<ul')
    assert 'style="line-height:200%"' in file_cont
    assert 'id="TheList"' in file_cont
    assert file_cont.strip().endswith('</ul>')
Ejemplo n.º 22
0
def test_list_tags():
    ul_tag = hr.Ul(id="myUnorderedList", style="line-height:250%")
    assert ul_tag.tag == 'ul', ('Ul: tag failure')
    assert ul_tag.attrs == {
        'id': 'myUnorderedList',
        'style': 'line-height:250%'
    }, ('Ul: Attrs failure')
    li_tag = hr.Li(id="myList", style="line-height:25%")
    assert li_tag.tag == 'li', ('Ul: tag failure')
    assert li_tag.attrs == {
        'id': 'myList',
        'style': 'line-height:25%'
    }, ('Li: Attrs failure')
def test_list_building():
    page = hr.Ul()
    page.append(hr.Li("first item"))
    page.append(hr.Li("second item w style", style="very trendy"))
    f = StringIO()
    page.render(f)
    expected = "<ul>\n" \
               "   <li>\n" \
               "      first item\n" \
               "   </li>\n" \
               '   <li style="very trendy">\n' \
               "      second item w style\n" \
               "   </li>\n" \
               "</ul>\n"
    assert f.getvalue() == expected
def test_Html_Body_Ul_Li_A_test_Content_id_style():
    page = hr.Html()
    body = hr.Body()
    unordered = hr.Ul(id="Test 71", style="Test 72")
    unordered.append(hr.Li("Test 73"))
    unordered.append(hr.Li("Test 74", style="Test 75"))
    item = hr.Li()
    item.append("Test 76")
    item.append(hr.A("Test 77", "Test 78"))
    item.append(" Test 79")
    unordered.append(item)
    body.append(unordered)
    page.append(body)
    testdata = page.content
    assert testdata == "<html>\n    <body>\n        <ul id=\"Test 71\" style=\"Test 72\">\n            <li>\n                Test 73\n            </li>\n            <li style=\"Test 75\">\n                Test 74\n            </li>\n            <li>\n                Test 76\n                <a href=\"Test 77\">Test 78</a>\n                 Test 79\n            </li>\n        </ul>\n    </body>\n</html>"
Ejemplo n.º 25
0
    def test_ul_tag_append(self):
        comp_string = '<ul>\n<li>\n    Test 1\n</li>\n<li>\n    Test 2\n</li>\n</ul>\n'

        with open(path.join(self.test_dir, 'test.txt'), 'w') as f:
            test = hr.Ul()
            test.indent = ''
            li_1 = hr.Li("Test 1")
            li_2 = hr.Li("Test 2")
            li_1.indent = ""
            li_2.indent = ""
            test.append(li_1)
            test.append(li_2)
            test.render(f)

        with open(path.join(self.test_dir, 'test.txt')) as f:
            self.assertEqual(comp_string, f.read())
def test_7():
    page_test = hr.Html()
    body = hr.Body()
    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()
    body.append(list)
    page_test.append(body)
    hr.render_page(page_test, "test_7_UILI_class.htm")
    test_file = f"{tmp_directory}test_7_UILI_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() == "0f69f655f2b48ba2739fbdcab16cb612"
Ejemplo n.º 27
0
def test_list():
    """
    Verify li tags are correctly appended into ul tags.
    """
    output = io.StringIO()
    ul = hr.Ul()
    li1 = hr.Li("Testing, 1 2 3..", style="color: blue")
    li2 = hr.Li("More tests! We need more tests!")
    ul.append(li1)
    ul.append(li2)
    ul.render(output, "")
    file_cont = output.getvalue()
    print(file_cont)
    assert '<li style="color: blue">' in file_cont
    assert "More tests! We need more tests!" in file_cont
    assert file_cont.strip().endswith('</ul>')
Ejemplo n.º 28
0
 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_step8_output(step8_sample_output):
    """copied and pasted from run_html_render.py, step7.
    Expect this gives same result as test html"""
    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, "test_html_output8.html")

    with open('test_html_output8.html') as f:
        generated_file = f.read()

    assert generated_file == step8_sample_output
Ejemplo n.º 30
0
def test_ul():
    html = hr.Html()
    body = hr.Body()
    body.append(hr.H(2, "xxx"))
    ul = hr.Ul(id="TheList", style="line-height:200%")
    body.append(ul)
    html.append(body)

    f = StringIO()
    html.render(f)
    f.seek(0)
    text = f.read().strip()

    print(text)
    assert text.find("<ul style=\"line-height:200%\" id=\"TheList\">") != -1 \
        or text.find("<ul id=\"TheList\" style=\"line-height:200%\">") != -1

    assert text.find("</ul>") != -1