def test_two_instances(): e = Element("this is also text") e2 = Element("this is also text") e.append("some more text") assert "some more text" in e.content
def test_two_instances(): e = Element('this is some text') e2 = Element('this is some other text') e.append('some more text') assert 'some more text' not in e2.content
def test_init(): """ this only tests that it can be initialized -- but it's a start """ e = Element() e = Element("this is some text")
def test_two_instances(): e = Element("this is some text") e2 = Element("this is some text") e.append("some more text") assert "some more text" not in e2.content
def test_new_element(): ''' This tests if the program can create a new element either with nothing (el_object) or with content (el_object2). ''' el_object = Element() el_object2 = Element('content')
def test_add_content(): ''' This tests if the program can add content to an element. ''' el_object = Element('content') el_object = Element() assert el_object.content == []
def test_init(): """ This only tests that it can be initialized with and without some content -- but it's a start """ e = Element() e = Element("this is some text")
def test_append(self): """test append""" # create Element instance p = Element() expected = "This is a test" p.append(expected) actual = p.a_list[0] self.assertEqual(expected, actual)
def test_content(): ''' test the content list ''' ANS = 1 e = Element("foo") e1 = Element("bar") result = e.get_content() assert result is ANS
def test_append(): '''test append method''' ANS = 2 e = Element("foo") e.append("bar") result = e.get_content() assert result is ANS
def test_append(): """ This tests that you can append text It doesn't test if it works -- that will be covered by the render test later """ e = Element("this is some text") e.append("some more text")
def test_render(): my_stuff = 'spam, spam, spam' el_object = Element(my_stuff) more_stuff = 'eggs, eggs, eggs' el_object.append(more_stuff) contents = render_element(el_object).strip() assert contents.startswith('<html>') assert contents.endswith('</html>') assert my_stuff in contents assert more_stuff in contents
def test_render(): outfile = io.StringIO() e = Element("this is some text") e.render(outfile, ind=4) file_contents = outfile.getvalue() print(file_contents)
def test_render(): e = Element("this is some text") e.append("and this is some more text") file_contents = render_result(e) assert ("this is some text") in file_contents assert ("and this is some more text") in file_contents assert file_contents.startswith("<html>") assert file_contents.strip().endswith("</html>")
def test_render_body(): my_stuff = 'spam, spam, spam' el_object = Element(my_stuff) more_stuff = 'eggs, eggs, eggs' el_object with open('test1', 'w') as out_file: el_object.render(out_file) with open('test1', 'r') as in_file: contents = in_file.read() assert contents.startswith('<body>') assert contents.endswith('</body')
def render_element(element, filename='temp_render_file.html', remove=True): """ renders an element, and returns what got rendered This can be used by multiple tests. :param element: the element to be rendered (its render() method will be called) :param filename='temp_render_file.html': the name of the temporary file to be used. :param remove=True: Whether to remove the file after using it to render. Set this to True if you want to be able to look at after the tests run. NOTE: - this could be refactored, and still used everywhere. """ with open(filename, 'w') as out_file: Element.render(out_file) with open(filename, 'r') as in_file: contents = in_file.read()
def test_attributes(): """ tests that you can pass attributes in to the tag """ e = Element("some text", id="this", color="red") # could be any attributes file_contents = render_result(e) print(file_contents) assert 'id="this"' in file_contents assert 'color="red"' in file_contents
def test_indentation(): my_stuff = 'Blondes just have more fun' el_object = Element(my_stuff) contents = render_element(el_object) contents = contents.strip() print(contents) lines = contents.split('\n') assert len(lines) == 3 assert lines[1].startswith(Element.extra_indent + 'Blondes')
def test_step1(): el = Element() assert el.tag == 'html' assert el.indent == 4 assert el.content == [] el.append('hi') assert el.content == ['hi'] el.append('bye') assert el.content == ['hi', 'bye'] f = StringIO() el.render(f) assert f.getvalue() == ('<html>\n hi\n bye\n</html>\n') f = StringIO() el.render(f, 1) assert f.getvalue() == (' <html>\n hi\n bye\n ' '</html>\n')
def test_Element_kwargs(): element = Element('data1', style="text-align: center; font-style: oblique;") # noqa: E501 element.tag = 'p' element.append('data2') with open('file8.html', 'w') as file1fh: element.render(file1fh) with open('file8.html', 'r') as filefh: rendered = filefh.read() assert '<p style="text-align: center; font-style: oblique;">\n'+element.indent+'data1\n'+element.indent+'data2\n'+'</p>\n' == rendered # noqa: E501
def test_indent_contents(): """ The contents in a element should be indented more than the tag by the amount in the indent class attribute """ html = Element("some content") file_contents = render_result(html, ind="") print(file_contents) lines = file_contents.split("\n") assert lines[1].startswith(Element.indent)
def test_render_non_strings(): my_stuff = 'any string I like' el_object = Element(Body(my_stuff)) contents = render_element(el_object) contents = contents.strip() print(contents) assert my_stuff in contents assert contents.startswith('<html>') assert contents.endswith('</html>') assert '<body>' in contents assert '</body>' in contents assert contents.index('<body>') < contents.index(my_stuff) assert contents.index('<body>') < contents.index('</body>')
def test_render(): element = Element('data1') element.append('data2') with open('file1.html', 'w') as file1fh: element.render(file1fh) with open('file1.html', 'r') as filefh: rendered = filefh.read() assert '<>\n'+element.indent+'data1\n'+element.indent+'data2\n'+'</>\n' == rendered # noqa: E501
def test_render_element(): """ Tests whether the Element can render two pieces of text So it is also testing that the append method works correctly. It is not testing whether indentation or line feeds are correct. """ e = Element("this is some text") e.append("and this is some more text") # This uses the render_results utility above file_contents = render_result(e).strip() # making sure the content got in there. assert ("this is some text") in file_contents assert ("and this is some more text") in file_contents # make sure it's in the right order assert file_contents.index("this is") < file_contents.index("and this") # making sure the opening and closing tags are right. assert file_contents.startswith("<html>") assert file_contents.endswith("</html>")
def test_append(): e = Element("this is some text") e.append ("and more text") assert "and more text" in e.content assert e.content == ["this is some text", "and more text"] e.append ("and even more text") assert e.content == ["this is some text", "and more text", "and even more text"]
def test_render(): outfile = io.StringIO() e = Element("this is some text") e.append("some more text") e.render(outfile) outfile.seek(0) file_contents = outfile.read() assert ("this is some text") in file_contents assert ("some more text") in file_contents assert file_contents.startswith("<html>") assert file_contents.strip().endswith("</html>")
def test_render(): outfile = io.StringIO() e = Element("this is some text") e.append("and this is some more text") e.render(outfile) outfile.seek(0) file_contents = outfile.read() assert ("this is some text") in file_contents assert ("and this is some more text") in file_contents
def test_render(): outfile = io.StringIO() e = Element('this is some text\n') e.append('this is again some more text') e.render(outfile) outfile.seek(0) file_contents = outfile.read() assert ('this is some text') in file_contents assert ('this is again some more text') in file_contents assert file_contents.startswith('<html>') assert file_contents.strip.endswith('</html>') print(file_contents)
def test_render_element(): my_stuff = 'hamma, hamma, hamma' el_object = Element(my_stuff) more_stuff = "umma, umma, umma" el_object.append(more_stuff) with open('test1', 'w') as out_file: el_object.render(out_file) with open('test1', 'r') as in_file: contents = in_file.read() assert contents.startswith('<html>') assert contents.endswith('</html>') assert my_stuff in contents assert more_stuff in contents
def test_reder(): mystuff = 'spam, spam, spam' el_object = Element(mystuff) morestuff = 'eggs, eggs, eggs' el_object.append(morestuff) with open('text1.htm', 'w') as out_file: el_object.render(out_file) with open('text1.htm', 'r') as in_file: contents = in_file.read() assert contents.startswith('<html>') assert contents.endswith('</html>') assert mystuff in contents assert morestuff in contents