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_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_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(): 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_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 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(): 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") e.append ("and some more text") #with open("test1.html", 'w') as outfile: # e.render(outfile) e.render(outfile, "") outfile.seek(0) file_contents = outfile.read() assert ("this is some text") in file_contents assert ("and some more text") in file_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
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_render(): some_stuff = 'blueberries and raspberries' el_object = Element(some_stuff) more_stuff = 'strawberries' el_object.append(more_stuff) with open('test1.txt', 'w') as out_file: el_object.render(out_file) with open('test1.txt', 'r') as in_file: contents = in_file.read() assert contents.startswith('<html>') assert contents.endswith('</html>') assert some_stuff in contents assert more_stuff in contents
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_render(self): """test render()""" p = Element() test_str = "this is a render test" # add content p.append(test_str) f = StringIO() # indent 4 spaces p.render(f, " ") expected = [ " <html>", p.indent * ' ' + " this is a render test", " </html>" ] expected_page = "\n".join(expected) + "\n" self.assertEqual(expected_page, f.getvalue())
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_tag(): outfile = io.StringIO() e = Element("this is some text", "body") e.append("and this is some more text, WooHoo!!") e.render(outfile) outfile.seek(0) file_contents = outfile.read() #f = open('test1.html', 'w') #f.write(file_contents) open('test1.html', 'w').write(file_contents) print(file_contents) assert ("this is some text") in file_contents assert ("and this is some more text, WooHoo!!") in file_contents assert file_contents.startswith("<body>") assert file_contents.strip().endswith("</body>")
def test_render_non_strings(): el_object = Element(Body('any string I like')) with open('test1', 'w') as out_file: el_object.render(out_file) with open('test1', 'r') as in_file: contents = in_file.read()
def test_render_non_strings(): el_object = Element(Body('blah and foooo')) with open('test1.txt', 'w') as out_file: el_object.render(out_file) with open('test1.txt', 'r') as in_file: contents = in_file.read()
def test_render(): e = Element("Some text") e.append("More text") with open("test1.html", 'w') as outfile: e.render(outfile)
def test_render(): html = Element() html.append('Some words.') f = StringIO() html.render(f) assert f.getvalue() == '<>\n Some words.\n</>\n'