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')
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")
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")
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')
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())
def test_self_closing(): e = hr.SelfClosingTag() f = StringIO() e.render(f) f.seek(0) text = f.read().strip() assert ' />' in text
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)
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
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()
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")
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')
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)
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))
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 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)
def test_sct_init(): with pytest.raises(hr.SelfClosingTag.ContentError): a = hr.SelfClosingTag('some content')
#!/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)
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'))
def test_SelfClosingTag(): out_SelfClosingTag = hr.SelfClosingTag() out_SelfClosingTag.tag = 'meta' f = StringIO() out_SelfClosingTag.render(f) assert f.getvalue() == '<meta />\n'
def test_meta(): metatag = hr.SelfClosingTag() metatag.tag = "ul" x = StringIO() metatag.render(x) assert x.getvalue() == "<ul>\n"
def test_selfclosingtag(self): test_selfclosing = hr.SelfClosingTag() test_selfclosing.tag = 'br' f = StringIO() test_selfclosing.render(f) self.assertEqual(f.getvalue(), "<br />\n")
def test_self_closing_content_error(): with pytest.raises(TypeError): element = hr.SelfClosingTag('cat')
def test_self_closing(): """Test the extended kwargs functionality of Element""" elem = hr.SelfClosingTag(style="eggs") assert get_opening_line(elem) == '<html style="eggs" />'
def test_self_closer(): selfclosertest = hr.SelfClosingTag() selfclosertest.tag = 'br' f = StringIO() selfclosertest.render(f) assert f.getvalue() == "<br>\n"
def test_selfclosingtag_obj(self): # Tests content is an empty list selfclosingtag_obj = hr.SelfClosingTag() self.assertListEqual(selfclosingtag_obj.content, [])
def test_selfclosingtag(): test3 = hr.SelfClosingTag('intro3') # test3.append('test text3') assert ['intro3'] == test3.content
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")
def test_selfclosingtag(): test3 = hr.SelfClosingTag('intro3') test3.append('test text3') assert 'test text3' and 'intro3' in test3.content
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')
def test_selfclosingtag_obj_TypeError(self): # Tests SelfClosingTag object cannot be initialized with content with self.assertRaises(TypeError): hr.SelfClosingTag("some_text")