Skip to content

Commit 93f41d3

Browse files
updating rendered materials
1 parent f58de2f commit 93f41d3

20 files changed

Lines changed: 5456 additions & 7 deletions

File tree

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<html>
2+
<head>
3+
<title>PythonClass = Revision 1087:</title>
4+
</head>
5+
<body>
6+
<p style="text-align: center; font-style: oblique;">
7+
Here is a paragraph of text -- there could be more of them, but this is enough to show that we can do some text
8+
</p>
9+
</body>
10+
</html>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="UTF-8" />
5+
<title>PythonClass = Revision 1087:</title>
6+
</head>
7+
<body>
8+
<h2>PythonClass - Class 6 example</h2>
9+
<p style="text-align: center; font-style: oblique;">
10+
Here is a paragraph of text -- there could be more of them, but this is enough to show that we can do some text
11+
</p>
12+
<hr />
13+
<ul id="TheList" style="line-height:200%">
14+
<li>
15+
The first item in a list
16+
</li>
17+
<li style="color: red">
18+
This is the second item
19+
</li>
20+
<li>
21+
And this is a
22+
<a href="http://google.com">link</a>
23+
to google
24+
</li>
25+
</ul>
26+
</body>
27+
</html>
Lines changed: 264 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,264 @@
1+
"""
2+
test code for html_render.py
3+
4+
This is just a start -- you will need more tests!
5+
"""
6+
7+
import io
8+
import pytest
9+
10+
# import * is often bad form, but makes it easier to test everything in a module.
11+
from html_render import *
12+
13+
14+
# utility function for testing render methods
15+
# needs to be used in multiple tests, so we write it once here.
16+
def render_result(element, ind=""):
17+
"""
18+
calls the element's render method, and returns what got rendered as a
19+
string
20+
"""
21+
# the StringIO object is a "file-like" object -- something that
22+
# provides the methods of a file, but keeps everything in memory
23+
# so it can be used to test code that writes to a file, without
24+
# having to actually write to disk.
25+
outfile = io.StringIO()
26+
# this so the tests will work before we tackle indentation
27+
if ind:
28+
element.render(outfile, ind)
29+
else:
30+
element.render(outfile)
31+
return outfile.getvalue()
32+
33+
########
34+
# Step 1
35+
########
36+
37+
def test_init():
38+
"""
39+
This only tests that it can be initialized with and without
40+
some content -- but it's a start
41+
"""
42+
e = Element()
43+
44+
e = Element("this is some text")
45+
46+
47+
def test_append():
48+
"""
49+
This tests that you can append text
50+
51+
It doesn't test if it works --
52+
that will be covered by the render test later
53+
"""
54+
e = Element("this is some text")
55+
e.append("some more text")
56+
57+
58+
def test_render_element():
59+
"""
60+
Tests whether the Element can render two pieces of text
61+
So it is also testing that the append method works correctly.
62+
63+
It is not testing whether indentation or line feeds are correct.
64+
"""
65+
e = Element("this is some text")
66+
e.append("and this is some more text")
67+
68+
# This uses the render_results utility above
69+
file_contents = render_result(e).strip()
70+
71+
# making sure the content got in there.
72+
assert("this is some text") in file_contents
73+
assert("and this is some more text") in file_contents
74+
75+
# make sure it's in the right order
76+
assert file_contents.index("this is") < file_contents.index("and this")
77+
78+
# making sure the opening and closing tags are right.
79+
assert file_contents.startswith("<html>")
80+
assert file_contents.endswith("</html>")
81+
82+
# # Uncomment this one after you get the one above to pass
83+
# # Does it pass right away?
84+
# def test_render_element2():
85+
# """
86+
# Tests whether the Element can render two pieces of text
87+
# So it is also testing that the append method works correctly.
88+
89+
# It is not testing whether indentation or line feeds are correct.
90+
# """
91+
# e = Element()
92+
# e.append("this is some text")
93+
# e.append("and this is some more text")
94+
95+
# # This uses the render_results utility above
96+
# file_contents = render_result(e).strip()
97+
98+
# # making sure the content got in there.
99+
# assert("this is some text") in file_contents
100+
# assert("and this is some more text") in file_contents
101+
102+
# # make sure it's in the right order
103+
# assert file_contents.index("this is") < file_contents.index("and this")
104+
105+
# # making sure the opening and closing tags are right.
106+
# assert file_contents.startswith("<html>")
107+
# assert file_contents.endswith("</html>")
108+
109+
110+
111+
# # ########
112+
# # # Step 2
113+
# # ########
114+
115+
# # tests for the new tags
116+
# def test_html():
117+
# e = Html("this is some text")
118+
# e.append("and this is some more text")
119+
120+
# file_contents = render_result(e).strip()
121+
122+
# assert("this is some text") in file_contents
123+
# assert("and this is some more text") in file_contents
124+
# print(file_contents)
125+
# assert file_contents.endswith("</html>")
126+
127+
128+
# def test_body():
129+
# e = Body("this is some text")
130+
# e.append("and this is some more text")
131+
132+
# file_contents = render_result(e).strip()
133+
134+
# assert("this is some text") in file_contents
135+
# assert("and this is some more text") in file_contents
136+
137+
# assert file_contents.startswith("<body>")
138+
# assert file_contents.endswith("</body>")
139+
140+
141+
# def test_p():
142+
# e = P("this is some text")
143+
# e.append("and this is some more text")
144+
145+
# file_contents = render_result(e).strip()
146+
147+
# assert("this is some text") in file_contents
148+
# assert("and this is some more text") in file_contents
149+
150+
# assert file_contents.startswith("<p>")
151+
# assert file_contents.endswith("</p>")
152+
153+
154+
# def test_sub_element():
155+
# """
156+
# tests that you can add another element and still render properly
157+
# """
158+
# page = Html()
159+
# page.append("some plain text.")
160+
# page.append(P("A simple paragraph of text"))
161+
# page.append("Some more plain text.")
162+
163+
# file_contents = render_result(page)
164+
# print(file_contents) # so we can see it if the test fails
165+
166+
# # note: The previous tests should make sure that the tags are getting
167+
# # properly rendered, so we don't need to test that here.
168+
# assert "some plain text" in file_contents
169+
# assert "A simple paragraph of text" in file_contents
170+
# assert "Some more plain text." in file_contents
171+
# assert "some plain text" in file_contents
172+
# # but make sure the embedded element's tags get rendered!
173+
# assert "<p>" in file_contents
174+
# assert "</p>" in file_contents
175+
176+
177+
178+
179+
########
180+
# Step 3
181+
########
182+
183+
# Add your tests here!
184+
185+
# #####################
186+
# # indentation testing
187+
# # Uncomment for Step 9 -- adding indentation
188+
# #####################
189+
190+
191+
# def test_indent():
192+
# """
193+
# Tests that the indentation gets passed through to the renderer
194+
# """
195+
# html = Html("some content")
196+
# file_contents = render_result(html, ind=" ").rstrip() #remove the end newline
197+
198+
# print(file_contents)
199+
# lines = file_contents.split("\n")
200+
# assert lines[0].startswith(" <")
201+
# print(repr(lines[-1]))
202+
# assert lines[-1].startswith(" <")
203+
204+
205+
# def test_indent_contents():
206+
# """
207+
# The contents in a element should be indented more than the tag
208+
# by the amount in the indent class attribute
209+
# """
210+
# html = Element("some content")
211+
# file_contents = render_result(html, ind="")
212+
213+
# print(file_contents)
214+
# lines = file_contents.split("\n")
215+
# assert lines[1].startswith(Element.indent)
216+
217+
218+
# def test_multiple_indent():
219+
# """
220+
# make sure multiple levels get indented fully
221+
# """
222+
# body = Body()
223+
# body.append(P("some text"))
224+
# html = Html(body)
225+
226+
# file_contents = render_result(html)
227+
228+
# print(file_contents)
229+
# lines = file_contents.split("\n")
230+
# for i in range(3): # this needed to be adapted to the <DOCTYPE> tag
231+
# assert lines[i + 1].startswith(i * Element.indent + "<")
232+
233+
# assert lines[4].startswith(3 * Element.indent + "some")
234+
235+
236+
# def test_element_indent1():
237+
# """
238+
# Tests whether the Element indents at least simple content
239+
240+
# we are expecting to to look like this:
241+
242+
# <html>
243+
# this is some text
244+
# <\html>
245+
246+
# More complex indentation should be tested later.
247+
# """
248+
# e = Element("this is some text")
249+
250+
# # This uses the render_results utility above
251+
# file_contents = render_result(e).strip()
252+
253+
# # making sure the content got in there.
254+
# assert("this is some text") in file_contents
255+
256+
# # break into lines to check indentation
257+
# lines = file_contents.split('\n')
258+
# # making sure the opening and closing tags are right.
259+
# assert lines[0] == "<html>"
260+
# # this line should be indented by the amount specified
261+
# # by the class attribute: "indent"
262+
# assert lines[1].startswith(Element.indent + "thi")
263+
# assert lines[2] == "</html>"
264+
# assert file_contents.endswith("</html>")
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<html>
2+
<body>
3+
<p>
4+
Here is a paragraph of text -- there could be more of them, but this is enough to show that we can do some text
5+
</p>
6+
<p>
7+
And here is another piece of text -- you should be able to add any number
8+
</p>
9+
</body>
10+
</html>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<html>
2+
<head>
3+
<title>PythonClass = Revision 1087:</title>
4+
</head>
5+
<body>
6+
<h2>PythonClass - Class 6 example</h2>
7+
<p style="text-align: center; font-style: oblique;">
8+
Here is a paragraph of text -- there could be more of them, but this is enough to show that we can do some text
9+
</p>
10+
<hr />
11+
<ul id="TheList" style="line-height:200%">
12+
<li>
13+
The first item in a list
14+
</li>
15+
<li style="color: red">
16+
This is the second item
17+
</li>
18+
<li>
19+
And this is a
20+
<a href="http://google.com">link</a>
21+
to google
22+
</li>
23+
</ul>
24+
</body>
25+
</html>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<html>
2+
<head>
3+
<title>PythonClass = Revision 1087:</title>
4+
</head>
5+
<body>
6+
<p style="text-align: center; font-style: oblique;">
7+
Here is a paragraph of text -- there could be more of them, but this is enough to show that we can do some text
8+
</p>
9+
<hr />
10+
</body>
11+
</html>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/usr/bin/env python3
2+
3+
"""
4+
A class-based system for rendering html.
5+
"""
6+
7+
8+
# This is the framework for the base class
9+
class Element(object):
10+
11+
def __init__(self, content=None):
12+
pass
13+
14+
def append(self, new_content):
15+
pass
16+
17+
def render(self, out_file):
18+
out_file.write("just something as a place holder...")
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<html>
2+
<head>
3+
<title>PythonClass = Revision 1087:</title>
4+
</head>
5+
<body>
6+
<p>
7+
Here is a paragraph of text -- there could be more of them, but this is enough to show that we can do some text
8+
</p>
9+
<p>
10+
And here is another piece of text -- you should be able to add any number
11+
</p>
12+
</body>
13+
</html>

0 commit comments

Comments
 (0)