コード例 #1
0
def test_selfclosingtag():
    a = hr.SelfClosingTag()
    a.tag = 'br'
    output = StringIO()
    a.render(output)
    assert "<br />\n" in output.getvalue()
    with pytest.raises(TypeError):
        a = hr.SelfClosingTag('some stuff')
コード例 #2
0
def test_self_closing_content_errors():
    """Test that self-closing-tags cannot accept content"""
    with pytest.raises(TypeError):
        elem = hr.SelfClosingTag(  # pylint: disable=too-many-function-args
            "spam", style="eggs")
    with pytest.raises(TypeError):
        elem = hr.SelfClosingTag(content="spam", style="eggs")
    with pytest.raises(TypeError):
        elem = hr.SelfClosingTag(style="eggs")
        elem.append("spam")
コード例 #3
0
 def test_selfclosingtag(self):
     test_selfclosing = hr.SelfClosingTag()
     test_selfclosing.tag = 'br'
     f = StringIO()
     test_selfclosing.render(f)
     self.assertEqual(f.getvalue(), "<br />\n")
     test_selfclosing_attr = hr.SelfClosingTag(charset="UTF-8")
     test_selfclosing_attr.tag = 'meta'
     f = StringIO()
     test_selfclosing_attr.render(f)
     self.assertEqual(f.getvalue(), "<meta charset=\"UTF-8\" />\n")
コード例 #4
0
    def test_self_closing_tag(self):
        '''Verify SelfClosingTag.render overrides Element.render'''
        sc_tag = hr.SelfClosingTag()
        sc_tag.tag = 'br'
        output = StringIO()
        sc_tag.render(output)
        self.assertEqual(output.getvalue(), '<br />\n')

        sc_tag_attr = hr.SelfClosingTag(charset='UTF-8')
        sc_tag_attr.tag = 'meta'
        output = StringIO()
        sc_tag_attr.render(output)
        self.assertEqual(output.getvalue(), '<meta charset="UTF-8" />\n')
コード例 #5
0
 def test_sct_render(self):
     trial_elem = hr.SelfClosingTag()
     f = StringIO()
     trial_elem.render(f, cur_ind=1)
     standard = '    < />\n'
     self.assertEqual(trial_elem.tag, '')
     self.assertEqual(standard, f.getvalue())
コード例 #6
0
def test_self_closing():
    e = hr.SelfClosingTag()
    f = StringIO()
    e.render(f)
    f.seek(0)
    text = f.read().strip()
    assert ' />' in text
コード例 #7
0
 def test_SelfClosingTag(self):
     test = hr.SelfClosingTag()
     test.tag_name = 'hr'
     test_temp = '<hr/>\n'
     f = StringIO()
     test.render(f)
     self.assertEqual(f.getvalue(), test_temp)
コード例 #8
0
def test_selfclosing_element():
    f = StringIO()
    test_close = h.SelfClosingTag()
    test_close.render(f)
    page = f.getvalue()
    expected_page = '<html />\n'
    assert page == expected_page
コード例 #9
0
def test_self_closing_render():
    element = hr.SelfClosingTag()
    element2 = hr.Element()
    element2.append(element)
    goal_string = "<html>\n    <html />\n</html>"
    f = StringIO()
    element2.render(f)
    assert goal_string == f.getvalue()
コード例 #10
0
 def test_SelfClosingTag_10(self):  # Rendering without attributes
     self.e1 = hr.SelfClosingTag()
     self.e1.tag = consts.random_tag.strip()
     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:
         str_out = self.file.read()
         self.assertEqual(str_out, f"<SomeTagName />\n")
コード例 #11
0
 def test_SelfClosingTag_20(self):  # Rendering with attributes
     self.e1 = hr.SelfClosingTag(**consts.attrs_pass)
     self.e1.tag = consts.random_tag.strip()
     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:
         str_out = self.file.read()
         self.assertEqual(
             str_out, '<SomeTagName id="Marker" alt="Fancy Pants" />\n')
コード例 #12
0
 def test_self_closing_tag(self):
     """Run a test for self closing tags"""
     test_content = hr.SelfClosingTag("test string")
     test_content.tag = "br"
     f = StringIO()
     test_content.render(f)
     expected = "<br />\n"
     actual = f.getvalue()
     self.assertEqual(expected, actual)
コード例 #13
0
    def testRender(self):
        """testRender validates a basic SelfClosingTag render operation."""
        want = ["<html />"]

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

        self.assertTrue(validate_output(self.file_out, want))
コード例 #14
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')
コード例 #15
0
def test_self_closing_element():
    e = hr.SelfClosingTag(**{"t1": "t2"})
    f = StringIO()
    e.render(f)
    assert (f.getvalue() == "<html t1=\"t2\" />")
    try:
        e.append("t")
    except TypeError:
        pass
    else:
        aseet(False)
コード例 #16
0
def test_sct_init():
    with pytest.raises(hr.SelfClosingTag.ContentError):
        a = hr.SelfClosingTag('some content')
コード例 #17
0
#!/usr/bin/env python3

import pytest
import html_render as hr
from io import StringIO

element = hr.Element('some text',
                     style="text-align: center; font-style: oblique;")
olt = hr.OneLineTag('title', style="text-align: center; font-style: oblique;")
sct = hr.SelfClosingTag()
link = hr.A('http://google.com', 'link')
h = hr.H(2, 'header')

print(element.attrs)
# body = hr.Body()
# body.append('body text')
# p1 = hr.P('para1')
# body.append(p1)
# body.append(hr.P('para2'))
# element.append(body)


def test_init():
    assert element.content == ['some text']
    assert element.tag_type == 0


def test_indent():
    element.indent(False)
    assert element.indent_size == 0
    element.indent(True)
コード例 #18
0
 def test_SelfClosingTag(self):
     self.assertTrue(issubclass(hr.SelfClosingTag, hr.Element))
     obj = hr.SelfClosingTag()
     self.assertIsInstance(obj, hr.SelfClosingTag)
     self.assertIsInstance(obj, hr.Element)
     self.assertTrue(hasattr(obj, 'render'))
コード例 #19
0
def test_SelfClosingTag():
    out_SelfClosingTag = hr.SelfClosingTag()
    out_SelfClosingTag.tag = 'meta'
    f = StringIO()
    out_SelfClosingTag.render(f)
    assert f.getvalue() == '<meta />\n'
コード例 #20
0
def test_meta():
    metatag = hr.SelfClosingTag()
    metatag.tag = "ul"
    x = StringIO()
    metatag.render(x)
    assert x.getvalue() == "<ul>\n"
コード例 #21
0
 def test_selfclosingtag(self):
     test_selfclosing = hr.SelfClosingTag()
     test_selfclosing.tag = 'br'
     f = StringIO()
     test_selfclosing.render(f)
     self.assertEqual(f.getvalue(), "<br />\n")
コード例 #22
0
def test_self_closing_content_error():
    with pytest.raises(TypeError):
        element = hr.SelfClosingTag('cat')
コード例 #23
0
def test_self_closing():
    """Test the extended kwargs functionality of Element"""
    elem = hr.SelfClosingTag(style="eggs")

    assert get_opening_line(elem) == '<html style="eggs" />'
コード例 #24
0
def test_self_closer():
    selfclosertest = hr.SelfClosingTag()
    selfclosertest.tag = 'br'
    f = StringIO()
    selfclosertest.render(f)
    assert f.getvalue() == "<br>\n"
コード例 #25
0
 def test_selfclosingtag_obj(self):
     # Tests content is an empty list
     selfclosingtag_obj = hr.SelfClosingTag()
     self.assertListEqual(selfclosingtag_obj.content, [])
コード例 #26
0
def test_selfclosingtag():
    test3 = hr.SelfClosingTag('intro3')
    # test3.append('test text3')
    assert ['intro3'] == test3.content
コード例 #27
0
 def test_metatag(self):
     test_meta = hr.SelfClosingTag(charset="UTF-8")
     test_meta.tag = 'meta'
     f = StringIO()
     test_meta.render(f)
     self.assertEqual(f.getvalue(), "<meta charset=\"UTF-8\" />\n")
コード例 #28
0
def test_selfclosingtag():
    test3 = hr.SelfClosingTag('intro3')
    test3.append('test text3')
    assert 'test text3' and 'intro3' in test3.content
コード例 #29
0
 def test_SelfClosingTag(self):
     test5 = hr.SelfClosingTag('Test for SelfClosingTag')
     f = StringIO()
     test5.tag = 'p'
     test5.render(f, '')
     self.assertEqual(f.getvalue(), f'<p>\n')
コード例 #30
0
 def test_selfclosingtag_obj_TypeError(self):
     # Tests SelfClosingTag object cannot be initialized with content
     with self.assertRaises(TypeError):
         hr.SelfClosingTag("some_text")