Skip to content

Commit 9a3304a

Browse files
committed
test_html_render.py::test_content_in_br still fail
1 parent c59234c commit 9a3304a

File tree

2 files changed

+35
-10
lines changed

2 files changed

+35
-10
lines changed

students/eoner/lesson07/html_render.py

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,7 @@ class Element(object):
1212

1313
def __init__(self, content=None, **kwargs):
1414
self.contents = [content]
15-
self.attributes = ""
16-
# create a string with kwargs
17-
for key, value in kwargs.items():
18-
self.attributes+=(' {}="{}",'.format(key, value))
15+
self.attributes = kwargs
1916

2017
def append(self, new_content):
2118
self.contents.append(new_content)
@@ -24,8 +21,10 @@ def render(self, out_file):
2421
# loop the content list
2522
# add tags to beginning / end
2623
open_tag = ["<{}".format(self.tag)]
27-
if len(self.attributes) >0:
28-
open_tag.append(self.attributes[:-1])
24+
#if any kwargs, add them in to starting tag
25+
if self.attributes!={}:
26+
for k, v in self.attributes.items():
27+
open_tag.append(' {}="{}"'.format(k, v))
2928
open_tag.append(">\n")
3029
out_file.write("".join(open_tag))
3130

@@ -71,15 +70,24 @@ def render(self, out_file):
7170
# loop the content list
7271
# add tags to beginning / end
7372
open_tag = ["<{}".format(self.tag)]
74-
out_file.write("".join(open_tag))
73+
if self.attributes!={}:
74+
for k, v in self.attributes.items():
75+
open_tag.append(' {}="{}"'.format(k, v))
7576
for content in self.contents:
7677
try:
7778
if content is not None:
78-
content.render(out_file)
79+
raise TypeError
7980
except AttributeError:
8081
out_file.write(content)
82+
out_file.write("".join(open_tag))
8183
out_file.write(" />\n")
84+
85+
def append(self, content):
86+
raise TypeError
8287

8388
class Hr(SelfClosingTag):
8489
tag = "hr"
85-
#Hr(width=400)
90+
#Hr(width=400)
91+
92+
class Br(SelfClosingTag):
93+
tag = "br"

students/eoner/lesson07/test_html_render.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,24 @@ def test_hr_attr():
252252
file_contents = render_result(hr)
253253
print(file_contents)
254254
assert file_contents == '<hr width="400" />\n'
255-
assert False
255+
256+
br = Br()
257+
file_contents = render_result(br)
258+
print(file_contents)
259+
assert file_contents == "<br />\n"
260+
261+
262+
def test_content_in_br():
263+
with pytest.raises(TypeError):
264+
br = Br("some content")
265+
266+
267+
def test_append_content_in_br():
268+
with pytest.raises(TypeError):
269+
br = Br()
270+
br.append("some content")
271+
272+
# assert False
256273
# #####################
257274
# # indentation testing
258275
# # Uncomment for Step 9 -- adding indentation

0 commit comments

Comments
 (0)