Skip to content
This repository was archived by the owner on Jun 9, 2021. It is now read-only.

Commit d5ed9c0

Browse files
committed
create html render and test
1 parent 5e682f8 commit d5ed9c0

File tree

2 files changed

+79
-0
lines changed

2 files changed

+79
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#! usr/bin/env python3
2+
"""
3+
html render activity
4+
"""
5+
6+
class Element():
7+
tag = 'html'
8+
indent = ' '
9+
10+
def __init__(self, content=None):
11+
if content is None:
12+
self.content = []
13+
else:
14+
self.content = [content]
15+
# python 3 "object" is assumed
16+
# none is handy default value bc it is immutable
17+
18+
def append(self, content):
19+
self.content.append(content)
20+
21+
def render(self, file_obj):
22+
file_obj.write('<')
23+
24+
class Body(Element):
25+
tag = 'body'
26+
27+
class Para(Element):
28+
tag = 'p'
29+
30+
class HTML(Element):
31+
tag = 'HTML'
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#! usr/bin/env python3
2+
"""
3+
test html render activity
4+
"""
5+
6+
import html_render
7+
import pytest
8+
from html_render import Element, Body, Para, HTML
9+
10+
def test_new_element():
11+
el_object = html_render.Element()
12+
el_object = html_render.Element('hedgweena')
13+
14+
def test_add_content():
15+
el_object = html_render.Element('hedgie')
16+
el_object = html_render.Element()
17+
print(el_object)
18+
assert el_object.content == []
19+
# if an assertion fails pytest will fail and spit out info
20+
21+
def test_adding_empty_string():
22+
el_object = html_render.Element('')
23+
assert el_object.content == ['']
24+
25+
def test_append_string():
26+
el_object = html_render.Element('Hedgie')
27+
el_object.append(' Hugs!')
28+
assert el_object.content == ['Hedgie Hugs!']
29+
30+
def test_tag_exists():
31+
assert html_render.Element.tag == 'html'
32+
el_object = html_render.Element.tag('spam, spam, spam')
33+
assert el_object.tag == 'html'
34+
35+
def test_indent_exists():
36+
assert html_render.Element.indent == ' '
37+
38+
def test_body_tag():
39+
assert Body.tag == 'body'
40+
41+
def test_para_tag():
42+
assert Para.tag == 'p'
43+
44+
def test_html_tag():
45+
assert HTML.tag == 'HTML'
46+
47+
def test_render_non_strings():
48+
el_object - Element(Body('a neat string'))

0 commit comments

Comments
 (0)