コード例 #1
0
def test_link_with_attributes():
    attr = {"class": "external-link", "target": "_blank"}
    a = A("http://google.com", "link to google", **attr)
    output = get_output(a)
    print(output)
    assert "class=\"external-link\"" in output
    assert "target=\"_blank\"" in output
コード例 #2
0
 def test_render(self):
     p = A("OneLineTag", "test render")
     f = StringIO()
     p.render(f)
     #print(f.getvalue())
     expected = "<a href=" + '"' + "OneLineTag" + '"' + ">test render</a>\n"
     self.assertEqual(expected, f.getvalue())
コード例 #3
0
def test_A():
    element = A('http://google.com', 'link to google')
    with open('file10.html', 'w') as file1fh:
        element.render(file1fh)
    with open('file10.html', 'r') as filefh:
        rendered = filefh.read()
    assert '<a href="http://google.com">\n'+element.indent+'link to google\n</a>\n' == rendered  # noqa: E501
コード例 #4
0
def test_anchor():
    a = A("http://google.com", "link to google")
    file_contents = render_result(a)
    print(file_contents)
    assert file_contents.startswith('<a ')
    assert file_contents.endswith('</a>')
    assert 'href="http://google.com"' in file_contents
    assert 'link to google' in file_contents
コード例 #5
0
def test_step6():
    a = A("http://google.com", "link to google")
    assert a.attr == {'href': "http://google.com"}
    assert a.content == ["link to google"]

    f = StringIO()
    a.render(f)
    assert f.getvalue() == ('<a href="http://google.com">link to google</a>\n')
コード例 #6
0
def test_anchor_element():
    p = A("http://google.com", "link to google")
    contents = render_element(p).strip()
    print(contents)
    assert contents.startswith('<a href="http:')
    assert contents.endswith('</a>')
    assert 'google.com' in contents
    assert 'link to' in contents
    assert contents.index('google.com') < contents.index('link to')
    assert contents.index('link to') < contents.index('</a>')
    lines = contents.split('\n')
    assert len(lines) == 1
コード例 #7
0
def test_a():
    page = Html()
    body = Body()
    body.append(A("http://google.com", "link"))
    page.append(body)

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

    assert f.getvalue() == '<!DOCTYPE html>\n<html>\n'\
        '    <body>\n'\
        '<a href="http://google.com">link</a>    </body>\n'\
        '</html>'
コード例 #8
0
def test_link():
    outfile = io.StringIO()
    a = A("http://google.com", "link")

    a.render(outfile)

    outfile.seek(0)
    file_contents = outfile.read()

    print(file_contents)

    assert file_contents.startswith('<a href="')
    assert file_contents.strip().endswith('</a>')
コード例 #9
0
def test_anchor_element_additional_atts():
    atts = {"size": "12px"}
    p = A("http://google.com", "link to google", **atts)
    contents = render_element(p).strip()
    print(contents)
    assert contents.startswith('<a href="http:')
    assert contents.endswith('</a>')
    assert 'google.com' in contents
    assert 'link to' in contents
    assert contents.index('google.com') < contents.index('link to')
    assert contents.index('link to') < contents.index('</a>')
    lines = contents.split('\n')
    assert len(lines) == 1
    assert 'size="12px"' in lines[0]
コード例 #10
0
def test_whole_thing():
    """
    Render a complete page

    This is not really a unit test, and does not test that the results
    are correct, but does ensure that it all runs, and provides output
    to look at
    """
    page = Html()

    head = Head()
    head.append(Meta(charset="UTF-8"))
    head.append(Title("Python Class Sample page"))
    page.append(head)

    body = Body()

    body.append(H(2, "Python Class - Html rendering example"))

    body.append(
        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())

    list = Ul(id="TheList", style="line-height:200%")

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

    item = Li()
    item.append("And this is a ")
    item.append(A("http://google.com", "link"))
    item.append("to google")

    list.append(item)

    body.append(list)

    page.append(body)

    # Element.indent = "        "
    # now render it:
    with open("sample_output.html", 'w') as f:
        page.render(f)
コード例 #11
0
def test_link():
    a = A("http://google.com", "link to google")
    output = get_output(a)
    print(output)
    assert output == "<a href=\"http://google.com\">link to google</a>"
コード例 #12
0
def test_a():
    test = A('espn.com', content='an a tag serving as a link')
    f = StringIO()
    test.render(f)
    assert f.getvalue(
    ) == '<a href="espn.com">an a tag serving as a link</a>\n'
コード例 #13
0
def test_anchor_single_attribute():
    a = A("http://google.com", "link to google")
    results = render_element(a)
    print(results)
    assert results.startswith('<a href="http://google.com">link to google</a')