def test_append(self): element1 = hr.Element() element1.append('Testing.') self.assertEqual(element1.content, ['Testing.']) element2 = hr.Element('Testing.') element2.append('1, 2, 3.') self.assertEqual(element2.content, ['Testing.', '1, 2, 3.'])
def test_append(): a = hr.Element() a.append('This is more content') assert 'This is more content' in a.content b = hr.Element('Some Content') b.append('This is more content') assert 'This is more content' in b.content
def test_element(): # Test all args e = hr.Element("Test", **{"t1": "t2"}) f = StringIO() e.render(f) assert (f.getvalue() == "<html t1=\"t2\">\n Test\n</html>") # Test no args e = hr.Element() f = StringIO() e.render(f) assert (f.getvalue() == "<html>\n</html>") # Test only attributes e = hr.Element(**{"t1": "t2"}) f = StringIO() e.render(f) assert (f.getvalue() == "<html t1=\"t2\">\n</html>") # Test only content e = hr.Element("Test") f = StringIO() e.render(f) assert (f.getvalue() == "<html>\n Test\n</html>") # Test the append menthod e.append(hr.Body("Test")) f = StringIO() e.render(f) assert (f.getvalue() == "<html>\n Test\n <body>\n Test\n </body>\n</html>")
def test_init(): """ This only tests that it can be initialized with and without some content -- but it's a start """ e = hr.Element() e = hr.Element("this is some text")
def test_init(): """ This only tests that it can be initialized with and without some content -- but it's a start """ elem = hr.Element() # pylint: disable=unused-variable elem = hr.Element("this is some text")
def test_element_renders_elements(): test_string = "test string" element = hr.Element(test_string) element2 = hr.Element() element2.append(element) goal_string = "<html>\n <html>\n {0}\n </html>\n</html>".format( test_string) f = StringIO() element2.render(f) assert goal_string == f.getvalue()
def testAppend(self): """testAppend validates appending an element to an Element object.""" element = html_render.Element() element.append("a text element") element.append(html_render.Element("an object element")) self.assertIs(type(element.sub_elements), list) self.assertEqual(len(element.sub_elements), 2) self.assertEqual(element.sub_elements[0].text, "a text element") self.assertEqual(element.sub_elements[1].sub_elements[0].text, "an object element")
def test_init(self): """ This only tests that it can be initialized with and without some content -- but it's a start """ e = hr.Element() # instantiate without passing in args self.assertEqual(e.contents, []) self.assertFalse(bool(e.attrs)) # instantiate with content and attrs e = hr.Element('teststring', keyword='some style') self.assertEqual(e.contents, ['teststring']) self.assertEqual(e.attrs, {'keyword': 'some style'})
def test_element_renders_nested_content(): e1 = hr.Element("Parent") e2 = hr.Element("Child") e1.append(e2) expected = ("<default-tag>\n" " Parent\n" " <default-tag>\n" " Child\n" " </default-tag>\n" "</default-tag>\n") with io.StringIO() as output: e1.render(output) assert output.getvalue() == expected
def testRender(self): """testRender validates a basic Element render operation.""" given = 'hello Element' want = [ "<html>", "{}{}".format(html_render.Element().ind, given), "</html>", ] got = open(self.file_out, 'w') html_render.Element(given).render(got) got.close() self.assertTrue(validate_output(self.file_out, want))
def test_Append(self): """ Test append method :return: Test should return equals """ assert_test_val1 = h.Element() assert_test_val1.append('Append Test...') # test append 1 value self.assertEqual(assert_test_val1.content, ['Append Test...']) assert_test_val2 = h.Element( 'Append Test...') # test appending another value to existing assert_test_val2.append('12345') self.assertEqual(assert_test_val2.content, ['Append Test...', '12345'])
def test_element_append(): init_string = "init string" element = hr.Element() test_strings = ["test1", 'test2', 'test3'] for idx, test_string in enumerate(test_strings): element.append(test_string) assert (element.contents == test_strings[:idx + 1])
def test_add_attribute(self): """Add style to element""" test_element = hr.Element("content to add", style='Bold') self.assertTrue(test_element.attributes == {'style': "Bold"}, msg=test_element.attributes) self.assertTrue(self.paragraph.attributes == {'style': 'color:blue;'}, msg=self.paragraph.attributes)
def render_helper(self, ind, element_tag=''): """ Internal helper function to wrap around the `render` method for a basic nonspecialized element. :ind: The indentation between levels, as a string of spaces. :element_tag: The element's tag name. :return: `True` if successful; otherwise, `False`. """ result, self.e1 = False, hr.Element() if element_tag: self.e1.tag = element_tag for str in consts.strs_before: self.e1.append(str) with open(consts.test_filename, 'w') as self.fobj: self.assertTrue(self.e1.render(self.fobj, ind)) with open(consts.test_filename, 'r') as self.file: self.strs_out = self.file.readlines() self.assertEqual(len(self.strs_out), 3) # Verify total lines self.assertEqual(self.strs_out[0], f"<{element_tag}>\n") self.assertEqual(self.strs_out[1], ind + ' '.join(consts.strs_after) + '\n') self.assertEqual(self.strs_out[-1], f"</{element_tag}>\n") result = True return result
def test_element_indent1(self): """ Tests whether the Element indents at least simple content we are expecting to to look like this: <html> this is some text <\html> More complex indentation should be tested later. """ e = hr.Element("this is some text") # This uses the render_results utility above file_contents = render_result(e).strip() # making sure the content got in there. self.assertIn("this is some text", file_contents) # break into lines to check indentation lines = file_contents.split('\n') # making sure the opening and closing tags are right. self.assertEqual(lines[0], "<html>") # this line should be indented by the amount specified # by the class attribute: "indent" self.assertTrue(lines[1].startswith(e.ind + "thi")) self.assertEqual(lines[2], "</html>") self.assertTrue(file_contents.endswith("</html>"))
def test_render(self): element = hr.Element("Test") element.tag = 'html' f = StringIO() element.render(f) self.assertEqual(f.getvalue(), "<html>\n" + element.indent + "Test\n</html>\n") element.tag = 'body' f = StringIO() element.render(f) self.assertEqual(f.getvalue(), "<body>\n" + element.indent + "Test\n</body>\n") element.tag = 'p' f = StringIO() element.render(f) self.assertEqual(f.getvalue(), "<p>\n" + element.indent + "Test\n</p>\n") element.tag = 'head' f = StringIO() element.render(f) self.assertEqual(f.getvalue(), "<head>\n" + element.indent + "Test\n</head>\n") assert os.path.isfile(cwd + '\\' + 'test_html_output1.html') assert os.path.isfile(cwd + '\\' + 'test_html_output2.html') assert os.path.isfile(cwd + '\\' + 'test_html_output3.html') assert os.path.isfile(cwd + '\\' + 'test_html_output4.html') assert os.path.isfile(cwd + '\\' + 'test_html_output5.html') assert os.path.isfile(cwd + '\\' + 'test_html_output6.html') assert os.path.isfile(cwd + '\\' + 'test_html_output7.html') assert os.path.isfile(cwd + '\\' + 'test_html_output8.html')
def setUp(self): # Invoked before each test method self.test_class = hr.Element() self.tag = "" self.cur_ind = " " self.another_attrib_key = "" self.another_attrib_value = ""
def test_element_indent1(): """ Tests whether the Element indents at least simple content we are expecting to to look like this: <html> this is some text <\html> More complex indentation should be tested later. """ elem = hr.Element("this is some text") # This uses the render_results utility above file_contents = render_result(elem).strip() # making sure the content got in there. assert "this is some text" in file_contents # break into lines to check indentation lines = file_contents.split("\n") # making sure the opening and closing tags are right. assert lines[0] == "<html>" # this line should be indented by the amount specified # by the class attribute: "indent" assert lines[1].startswith((" " * hr.Element.indent) + "thi") assert lines[2] == "</html>" assert file_contents.endswith("</html>")
def test_html(): htmltag = hr.Element("And here is another piece of text") htmltag.tag = 'html' x = StringIO() htmltag.render(x) assert x.getvalue( ) == "<html>\nAnd here is another piece of text\n</html>\n"
def test_set_attribute(): """Test that attributes can be assigned before and after init""" elem = hr.Element("this is some text", id="spam", style="eggs") elem.set_attributes(holy="grail", answer=42) assert (get_opening_line(elem) == '<html id="spam" style="eggs" holy="grail" answer="42">')
def test_render(self): test3 = hr.Element('Test for Render') test3.tag = 'p' f = StringIO() test3.render(f) self.assertEqual(f.getvalue(), f'<p>\n Test for Render\n</p>\n')
def test_element_render_w_two_lines(): page = hr.Element("one") page.append("two") f = StringIO() page.render(f) expected = "<html>\n one\n two\n</html>\n" assert f.getvalue() == expected
def test_element_content(self): """testing append method through element reference""" test_element = hr.Element("this is some content") self.assertEqual(test_element.content, ["this is some content"]) test_element.append("Adding additional content") self.assertEqual(test_element.content, ["this is some content", "Adding additional content"])
def test_p(): ptag = hr.Element("I did not like this assignment at all.") ptag.tag = 'html' x = StringIO() ptag.render(x) assert x.getvalue( ) == "<html>\nI did not like this assignment at all.\n</html>\n"
def test_element(self): test_element = hr.Element("test content") self.assertEqual(test_element.content, ["test content"]) test_element.tag = "p" self.assertEqual(test_element.tag, 'p') test_element.tag = 'body' self.assertEqual(test_element.tag, 'body')
def test_render(): render_element = hr.Element("render text") render_element.tag = 'html' f = StringIO() render_element.render(f) assert f.getvalue( ) == "<html>\n" + render_element.indent + "render text\n</html>\n"
def test_attributes(): e = hr.Element(id="this", style="text-color:blue") result = render_me(e) print(result) assert result.startswith("<html") assert 'id="this"' in result assert 'style="text-color:blue"' in result
def test_element(self): subject = hr.Element() subject.append(hr.P('hello world')) subject = self.render_page(subject).strip() self.assertTrue(subject.startswith('<html>')) self.assertTrue(subject.endswith('</html>')) self.assertIn('hello world', subject)
def test_Element_append(self): f = StringIO() testelement = hr.Element() testelement.append('test1') testelement.append('test2') testelement.render(f) print(f.getvalue()) self.assertEqual(f.getvalue(), "<tag>\ntest1\ntest2\n</tag>\n")
def test_render(self): ''' test render method ''' test = hr.Element('Here is a sentence.') test.tag_name = 'p' test_temp = f'<p>\n{test.indent}Here is a sentence.\n</p>\n' f = StringIO() test.render(f) self.assertEqual(f.getvalue(), test_temp)