-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtidyHTML_test.py
More file actions
374 lines (346 loc) · 24.5 KB
/
tidyHTML_test.py
File metadata and controls
374 lines (346 loc) · 24.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
#Tidy HTML Test
#Eitan Goldberger and Kelley Loder
import unittest
from tidyHTML import *
import tidyHTML
class TestTidyHTML(unittest.TestCase):
def test_give_tags_new_line(self):
content = ['<html><head>\n', \
'<title>Gensler & Zudans Family Dentistry</title>\n', \
'<style></style></head>\n', '<body>\n', '\n', '\n', \
'<area><base>\n', \
'sdfdf<h1>WELCOME TO GENSLER & ZUDANS FAMILY DENTISTRY!</h1>\n', \
'<img src="gensler_and_zudans_family_dentistry.jpg">\n', \
'\n', '<hello>\n', '\n', 'asfasf</hello>\n', '\n', '\n', \
'<p>Address:<br>\n', '1303 Mount Holly Rd.<br>\n', \
'Burlington, NJ 08016\n', \
'<h2> whats up with cats???!?!?!!?\n', '\n', \
'</h2></p>\n', '\n', \
'<h3> sdgsdgdsgdsg sdgsdgdsgdsg sdgsdgdsgdsg sdgsdgdsgdsg sdgsdgdsgdsg' \
'sdgsdgdsgdsg sdgsdgdsgdsg sdgsdgdsgdsg sdgsdgdsgdsg sdgsdgdsgdsg sdgsdgdsgdsg ' \
'sdgsdgdsgdsg sdgsdgdsgdsg sdgsdgdsgdsg sdgsdgdsgdsg sdgsdgdsgdsg sdgsdgdsgdsg ' \
'sdgsdgdsgdsg sdgsdgdsgdsg sdgsdgdsgdsg sdgsdgdsgdsg sdgsdgdsgdsg sdgsdgdsgdsg ' \
'sdgsdgdsgdsg sdgsdgdsgdsg sdgsdgdsgdsg sdgsdgdsgdsg </h3>\n', '\n', \
'</body> </endtagwithnostarttag> </html>']
content_after_give_tags_new_line = ['<html>\n', '<head>\n', \
'<title>Gensler & Zudans Family Dentistry</title>\n', \
'<style></style>\n', '</head>\n', '<body>\n', '\n', '\n', \
'<area><base>\n', \
'sdfdf<h1>WELCOME TO GENSLER & ZUDANS FAMILY DENTISTRY!</h1>\n', \
'<img src="gensler_and_zudans_family_dentistry.jpg">\n', \
'\n', '<hello>\n', '\n', 'asfasf\n', '</hello>\n', '\n', '\n', \
'<p>Address:<br>\n', '1303 Mount Holly Rd.<br>\n', \
'Burlington, NJ 08016\n', \
'<h2> whats up with cats???!?!?!!?\n', '\n', \
'</h2>\n', '</p>\n', '\n', \
'<h3> sdgsdgdsgdsg sdgsdgdsgdsg sdgsdgdsgdsg sdgsdgdsgdsg sdgsdgdsgdsg' \
'sdgsdgdsgdsg sdgsdgdsgdsg sdgsdgdsgdsg sdgsdgdsgdsg sdgsdgdsgdsg sdgsdgdsgdsg ' \
'sdgsdgdsgdsg sdgsdgdsgdsg sdgsdgdsgdsg sdgsdgdsgdsg sdgsdgdsgdsg sdgsdgdsgdsg ' \
'sdgsdgdsgdsg sdgsdgdsgdsg sdgsdgdsgdsg sdgsdgdsgdsg sdgsdgdsgdsg sdgsdgdsgdsg ' \
'sdgsdgdsgdsg sdgsdgdsgdsg sdgsdgdsgdsg sdgsdgdsgdsg </h3>\n', '\n', \
'</body> \n', '</endtagwithnostarttag> \n', '</html>']
self.assertEqual(give_tags_new_line(content), content_after_give_tags_new_line)
content = ['<html><head>\n', 'cats cats cats</head>\n', '<h1>caaaaaaaats</h1>\n']
content_after_give_tags_new_line = ['<html>\n', '<head>\n', 'cats cats cats\n', '</head>\n', '<h1>caaaaaaaats</h1>\n']
self.assertEqual(give_tags_new_line(content), content_after_give_tags_new_line)
def test_strip_all(self):
content = [' <head> i love cats! </head> cat cat! ', \
' still love cats.... why are cats so cool? ']
content_after_strip_all = ['<head> i love cats! </head> cat cat!', \
'still love cats.... why are cats so cool?']
self.assertEqual(strip_all(content), content_after_strip_all)
content = [' <html><head>\n', \
'<TITLE>Gensler & Zudans Family Dentistry</title>\n', \
'<style></style></head>\n', ' <body>\n', '\n', '\n', \
'<area><base>\n', \
'sdfdf<h1>WELCOME TO GENSLER & ZUDANS FAMILY DENTISTRY!</H1>\n', \
' <img src="gensler_and_zudans_family_dentistry.jpg">\n', \
'\n', '<hello>\n', '\n', ' asfasf</HELLO>\n', '\n', ' \n', \
' <p>Address:<br>\n', '1303 Mount Holly Rd.<br>\n', \
' Burlington, NJ 08016\n', \
' <h2> whats up with cats???!?!?!!?\n', '\n', \
' </h2></p>\n', '\n', \
'<h3> sdgsdgdsgdsg sdgsdgdsgdsg sdgsdgdsgdsg sdgsdgdsgdsg sdgsdgdsgdsg' \
'sdgsdgdsgdsg sdgsdgdsgdsg sdgsdgdsgdsg sdgsdgdsgdsg sdgsdgdsgdsg sdgsdgdsgdsg ' \
'sdgsdgdsgdsg sdgsdgdsgdsg sdgsdgdsgdsg sdgsdgdsgdsg sdgsdgdsgdsg sdgsdgdsgdsg ' \
'sdgsdgdsgdsg sdgsdgdsgdsg sdgsdgdsgdsg sdgsdgdsgdsg sdgsdgdsgdsg sdgsdgdsgdsg ' \
'sdgsdgdsgdsg sdgsdgdsgdsg sdgsdgdsgdsg sdgsdgdsgdsg </h3>\n', '\n', \
'</BODY> </endtagwithnostarttag> </html>']
content_after_strip_all = ['<html><head>\n', \
'<TITLE>Gensler & Zudans Family Dentistry</title>\n', \
'<style></style></head>\n', '<body>\n', '\n', '\n', \
'<area><base>\n', \
'sdfdf<h1>WELCOME TO GENSLER & ZUDANS FAMILY DENTISTRY!</H1>\n', \
'<img src="gensler_and_zudans_family_dentistry.jpg">\n', \
'\n', '<hello>\n', '\n', 'asfasf</HELLO>\n', '\n', '\n', \
'<p>Address:<br>\n', '1303 Mount Holly Rd.<br>\n', \
'Burlington, NJ 08016\n', \
'<h2> whats up with cats???!?!?!!?\n', '\n', \
'</h2></p>\n', '\n', \
'<h3> sdgsdgdsgdsg sdgsdgdsgdsg sdgsdgdsgdsg sdgsdgdsgdsg sdgsdgdsgdsg' \
'sdgsdgdsgdsg sdgsdgdsgdsg sdgsdgdsgdsg sdgsdgdsgdsg sdgsdgdsgdsg sdgsdgdsgdsg ' \
'sdgsdgdsgdsg sdgsdgdsgdsg sdgsdgdsgdsg sdgsdgdsgdsg sdgsdgdsgdsg sdgsdgdsgdsg ' \
'sdgsdgdsgdsg sdgsdgdsgdsg sdgsdgdsgdsg sdgsdgdsgdsg sdgsdgdsgdsg sdgsdgdsgdsg ' \
'sdgsdgdsgdsg sdgsdgdsgdsg sdgsdgdsgdsg sdgsdgdsgdsg </h3>\n', '\n', \
'</BODY> </endtagwithnostarttag> </html>']
self.assertEqual(strip_all(content), content_after_strip_all)
def test_find_tags(self):
content = ['<html>\n', '<head>\n', \
'<title>Gensler & Zudans Family Dentistry</title>\n', \
'<style></style></head>\n', '<body>\n', '\n', '\n', \
'<area><base>\n', \
'<h1>WELCOME TO GENSLER & ZUDANS FAMILY DENTISTRY!</h1>\n', \
'<img src="gensler_and_zudans_family_dentistry.jpg">\n', \
'</body>\n', '</endtagwithnostarttag>\n', '</html>']
tags = [{'start_ndx': 0, 'stop_ndx': 5, 'line': 0, 'type': 'start'}, \
{'start_ndx': 0, 'stop_ndx': 5, 'line': 1, 'type': 'start'}, \
{'start_ndx': 0, 'stop_ndx': 6, 'line': 2, 'type': 'start'}, \
{'start_ndx': 44, 'stop_ndx': 51, 'line': 2, 'type': 'end'}, \
{'start_ndx': 0, 'stop_ndx': 6, 'line': 3, 'type': 'start'}, \
{'start_ndx': 7, 'stop_ndx': 14, 'line': 3, 'type': 'end'}, \
{'start_ndx': 15, 'stop_ndx': 21, 'line': 3, 'type': 'end'}, \
{'start_ndx': 0, 'stop_ndx': 5, 'line': 4, 'type': 'start'}, \
{'start_ndx': 0, 'stop_ndx': 5, 'line': 7, 'type': 'empty'}, \
{'start_ndx': 6, 'stop_ndx': 11, 'line': 7, 'type': 'empty'}, \
{'start_ndx': 0, 'stop_ndx': 3, 'line': 8, 'type': 'start'}, \
{'start_ndx': 53, 'stop_ndx': 57, 'line': 8, 'type': 'end'}, \
{'start_ndx': 0, 'stop_ndx': 50, 'line': 9, 'type': 'empty'}, \
{'start_ndx': 0, 'stop_ndx': 6, 'line': 10, 'type': 'end'}, \
{'start_ndx': 0, 'stop_ndx': 22, 'line': 11, 'type': 'end'}, \
{'start_ndx': 0, 'stop_ndx': 6, 'line': 12, 'type': 'end'}]
self.assertEqual(find_tags(content), tags)
def test_classify(self):
self.assertEqual(classify('<head>'), 'start')
self.assertEqual(classify('<basefont>'), 'empty')
self.assertEqual(classify('</span>'), 'end')
self.assertEqual(classify('<img src="gensler_and_zudans_family_dentistry.jpg">'), 'empty')
self.assertEqual(classify('<isindex>'), 'empty')
def test_same_line_tags(self):
content = ['<html>\n', '<head>\n', \
'<title>Gensler & Zudans Family Dentistry</title>\n', \
'<style></style></head>\n', '<body>\n', '\n', '\n', \
'<area><base>\n', \
'<h1>WELCOME TO GENSLER & ZUDANS FAMILY DENTISTRY!</h1>\n', \
'<img src="gensler_and_zudans_family_dentistry.jpg">\n', \
'</body>\n', '</endtagwithnostarttag>\n', '</html>']
tags = [{'start_ndx': 0, 'stop_ndx': 5, 'line': 0, 'type': 'start'}, \
{'start_ndx': 0, 'stop_ndx': 5, 'line': 1, 'type': 'start'}, \
{'start_ndx': 0, 'stop_ndx': 6, 'line': 2, 'type': 'start'}, \
{'start_ndx': 44, 'stop_ndx': 51, 'line': 2, 'type': 'end'}, \
{'start_ndx': 0, 'stop_ndx': 6, 'line': 3, 'type': 'start'}, \
{'start_ndx': 7, 'stop_ndx': 14, 'line': 3, 'type': 'end'}, \
{'start_ndx': 15, 'stop_ndx': 21, 'line': 3, 'type': 'end'}, \
{'start_ndx': 0, 'stop_ndx': 5, 'line': 4, 'type': 'start'}, \
{'start_ndx': 0, 'stop_ndx': 5, 'line': 7, 'type': 'empty'}, \
{'start_ndx': 6, 'stop_ndx': 11, 'line': 7, 'type': 'empty'}, \
{'start_ndx': 0, 'stop_ndx': 3, 'line': 8, 'type': 'start'}, \
{'start_ndx': 53, 'stop_ndx': 57, 'line': 8, 'type': 'end'}, \
{'start_ndx': 0, 'stop_ndx': 50, 'line': 9, 'type': 'empty'}, \
{'start_ndx': 0, 'stop_ndx': 6, 'line': 10, 'type': 'end'}, \
{'start_ndx': 0, 'stop_ndx': 22, 'line': 11, 'type': 'end'}, \
{'start_ndx': 0, 'stop_ndx': 6, 'line': 12, 'type': 'end'}]
tags_after_same_line_tags = [{'start_ndx': 0, 'stop_ndx': 5, 'line': 0, 'type': 'start'}, \
{'start_ndx': 0, 'stop_ndx': 5, 'line': 1, 'type': 'start'}, \
{'start_ndx': 15, 'stop_ndx': 21, 'line': 3, 'type': 'end'}, \
{'start_ndx': 0, 'stop_ndx': 5, 'line': 4, 'type': 'start'}, \
{'start_ndx': 0, 'stop_ndx': 5, 'line': 7, 'type': 'empty'}, \
{'start_ndx': 6, 'stop_ndx': 11, 'line': 7, 'type': 'empty'}, \
{'start_ndx': 0, 'stop_ndx': 50, 'line': 9, 'type': 'empty'}, \
{'start_ndx': 0, 'stop_ndx': 6, 'line': 10, 'type': 'end'}, \
{'start_ndx': 0, 'stop_ndx': 22, 'line': 11, 'type': 'end'}, \
{'start_ndx': 0, 'stop_ndx': 6, 'line': 12, 'type': 'end'}]
self.assertEqual(same_line_tags(tags, content), tags_after_same_line_tags)
def test_tags_match(self):
self.assertTrue(tags_match('<head>', '</head>'))
self.assertFalse(tags_match('<h1>', '</h2>'))
self.assertTrue(tags_match('<p>', '</p>'))
self.assertFalse(tags_match('<head>', '<head>'))
self.assertTrue(tags_match('<ul>', '</ul>'))
self.assertFalse(tags_match('</head>', '<head>'))
def test_find_end_tag(self):
content = ['<html>\n', '<head>\n', \
'<title>Gensler & Zudans Family Dentistry</title>\n', \
'<style></style></head>\n', '<body>\n', '\n', '\n', \
'<area><base>\n', \
'<h1>WELCOME TO GENSLER & ZUDANS FAMILY DENTISTRY!</h1>\n', \
'<img src="gensler_and_zudans_family_dentistry.jpg">\n', \
'</body>\n', '</endtagwithnostarttag>\n', '</html>']
tags = [{'start_ndx': 0, 'stop_ndx': 5, 'line': 0, 'type': 'start'}, \
{'start_ndx': 0, 'stop_ndx': 5, 'line': 1, 'type': 'start'}, \
{'start_ndx': 0, 'stop_ndx': 6, 'line': 2, 'type': 'start'}, \
{'start_ndx': 44, 'stop_ndx': 51, 'line': 2, 'type': 'end'}, \
{'start_ndx': 0, 'stop_ndx': 6, 'line': 3, 'type': 'start'}, \
{'start_ndx': 7, 'stop_ndx': 14, 'line': 3, 'type': 'end'}, \
{'start_ndx': 15, 'stop_ndx': 21, 'line': 3, 'type': 'end'}, \
{'start_ndx': 0, 'stop_ndx': 5, 'line': 4, 'type': 'start'}, \
{'start_ndx': 0, 'stop_ndx': 5, 'line': 7, 'type': 'empty'}, \
{'start_ndx': 6, 'stop_ndx': 11, 'line': 7, 'type': 'empty'}, \
{'start_ndx': 0, 'stop_ndx': 3, 'line': 8, 'type': 'start'}, \
{'start_ndx': 53, 'stop_ndx': 57, 'line': 8, 'type': 'end'}, \
{'start_ndx': 0, 'stop_ndx': 50, 'line': 9, 'type': 'empty'}, \
{'start_ndx': 0, 'stop_ndx': 6, 'line': 10, 'type': 'end'}, \
{'start_ndx': 0, 'stop_ndx': 22, 'line': 11, 'type': 'end'}, \
{'start_ndx': 0, 'stop_ndx': 6, 'line': 12, 'type': 'end'}]
self.assertEqual(find_end_tag(tags, 0, content), 15)
self.assertEqual(find_end_tag(tags, 2, content), 3)
self.assertEqual(find_end_tag(tags, 1, content), 6)
def test_how_many_indents(self):
self.assertEqual(how_many_indents('\t\t\t\t<html><head>\t\t\n'), 4)
self.assertEqual(how_many_indents('\t\t\n'), 2)
self.assertEqual(how_many_indents('\t'), 1)
self.assertEqual(how_many_indents('<html>\t\t<head>\t\t'), 0)
self.assertEqual(how_many_indents('\t<html>\t\t<head>\t\t\n'), 1)
def test_make_lower(self):
content = [' <htmL><heAd>\n', \
'<TITLE>Gensler & Zudans Family Dentistry</title>\n', \
'<STYLE></style></head>\n', ' <body>\n', '\n', '\n', \
'<area><BASE>\n', \
'sdfdf<H1>WELCOME TO GENSLER & ZUDANS FAMILY DENTISTRY!</H1>\n', \
' <img src="gensler_and_zudans_family_dentistry.jpg">\n', \
'\n', '<helLO>\n', '\n', ' asfasf</HELLO>\n', '\n', ' \n', \
' <p>Address:<br>\n', '1303 Mount Holly Rd.<BR>\n', \
' Burlington, NJ 08016\n', \
' <h2> whats up with cats???!?!?!!?\n', '\n', \
' </h2></P>\n', '\n', \
'<h3> sdgsdgdsgdsg sdgsdgdsgdsg sdgsdgdsgdsg sdgsdgdsgdsg sdgsdgdsgdsg' \
'sdgsdgdsgdsg sdgsdgdsgdsg sdgsdgdsgdsg sdgsdgdsgdsg sdgsdgdsgdsg sdgsdgdsgdsg ' \
'sdgsdgdsgdsg sdgsdgdsgdsg sdgsdgdsgdsg sdgsdgdsgdsg sdgsdgdsgdsg sdgsdgdsgdsg ' \
'sdgsdgdsgdsg sdgsdgdsgdsg sdgsdgdsgdsg sdgsdgdsgdsg sdgsdgdsgdsg sdgsdgdsgdsg ' \
'sdgsdgdsgdsg sdgsdgdsgdsg sdgsdgdsgdsg sdgsdgdsgdsg </h3>\n', '\n', \
'</BODY> </endtagwithnostarttag> </HTML>']
content_after_make_lower = [' <html><head>\n', \
'<title>Gensler & Zudans Family Dentistry</title>\n', \
'<style></style></head>\n', ' <body>\n', '\n', '\n', \
'<area><base>\n', \
'sdfdf<h1>WELCOME TO GENSLER & ZUDANS FAMILY DENTISTRY!</h1>\n', \
' <img src="gensler_and_zudans_family_dentistry.jpg">\n', \
'\n', '<hello>\n', '\n', ' asfasf</hello>\n', '\n', ' \n', \
' <p>Address:<br>\n', '1303 Mount Holly Rd.<br>\n', \
' Burlington, NJ 08016\n', \
' <h2> whats up with cats???!?!?!!?\n', '\n', \
' </h2></p>\n', '\n', \
'<h3> sdgsdgdsgdsg sdgsdgdsgdsg sdgsdgdsgdsg sdgsdgdsgdsg sdgsdgdsgdsg' \
'sdgsdgdsgdsg sdgsdgdsgdsg sdgsdgdsgdsg sdgsdgdsgdsg sdgsdgdsgdsg sdgsdgdsgdsg ' \
'sdgsdgdsgdsg sdgsdgdsgdsg sdgsdgdsgdsg sdgsdgdsgdsg sdgsdgdsgdsg sdgsdgdsgdsg ' \
'sdgsdgdsgdsg sdgsdgdsgdsg sdgsdgdsgdsg sdgsdgdsgdsg sdgsdgdsgdsg sdgsdgdsgdsg ' \
'sdgsdgdsgdsg sdgsdgdsgdsg sdgsdgdsgdsg sdgsdgdsgdsg </h3>\n', '\n', \
'</body> </endtagwithnostarttag> </html>']
self.assertEqual(make_lower(content), content_after_make_lower)
content = ['cats <HEAD> cats cats cats </hEAd>' \
' <BR/> cat cat kitty cat </END>']
content_after_make_lower = ['cats <head> cats cats cats </head>' \
' <br/> cat cat kitty cat </end>']
self.assertEqual(make_lower(content), content_after_make_lower)
def test_delete_blank_lines(self):
content = [' <htmL><heAd>\n', \
'<TITLE>Gensler & Zudans Family Dentistry</title>\n', \
'<STYLE></style></head>\n', ' <body>\n', '\n', '\n', \
'<area><BASE>\n', \
'sdfdf<H1>WELCOME TO GENSLER & ZUDANS FAMILY DENTISTRY!</H1>\n', \
' <img src="gensler_and_zudans_family_dentistry.jpg">\n', \
'\n', '<helLO>\n', '\n', ' asfasf</HELLO>\n', '\n', ' \n', \
' <p>Address:<br>\n', '1303 Mount Holly Rd.<BR>\n', \
' Burlington, NJ 08016\n', \
' <h2> whats up with cats???!?!?!!?\n', '\n', \
' </h2></P>\n', '\n', \
'<h3> sdgsdgdsgdsg sdgsdgdsgdsg sdgsdgdsgdsg sdgsdgdsgdsg sdgsdgdsgdsg' \
'sdgsdgdsgdsg sdgsdgdsgdsg sdgsdgdsgdsg sdgsdgdsgdsg sdgsdgdsgdsg sdgsdgdsgdsg ' \
'sdgsdgdsgdsg sdgsdgdsgdsg sdgsdgdsgdsg sdgsdgdsgdsg sdgsdgdsgdsg sdgsdgdsgdsg ' \
'sdgsdgdsgdsg sdgsdgdsgdsg sdgsdgdsgdsg sdgsdgdsgdsg sdgsdgdsgdsg sdgsdgdsgdsg ' \
'sdgsdgdsgdsg sdgsdgdsgdsg sdgsdgdsgdsg sdgsdgdsgdsg </h3>\n', '\n', \
'</BODY> </endtagwithnostarttag> </HTML>']
content_after_delete_blank_lines = [' <htmL><heAd>\n', \
'<TITLE>Gensler & Zudans Family Dentistry</title>\n', \
'<STYLE></style></head>\n', ' <body>\n', \
'<area><BASE>\n', \
'sdfdf<H1>WELCOME TO GENSLER & ZUDANS FAMILY DENTISTRY!</H1>\n', \
' <img src="gensler_and_zudans_family_dentistry.jpg">\n', \
'<helLO>\n', ' asfasf</HELLO>\n', \
' <p>Address:<br>\n', '1303 Mount Holly Rd.<BR>\n', \
' Burlington, NJ 08016\n', \
' <h2> whats up with cats???!?!?!!?\n', \
' </h2></P>\n', \
'<h3> sdgsdgdsgdsg sdgsdgdsgdsg sdgsdgdsgdsg sdgsdgdsgdsg sdgsdgdsgdsg' \
'sdgsdgdsgdsg sdgsdgdsgdsg sdgsdgdsgdsg sdgsdgdsgdsg sdgsdgdsgdsg sdgsdgdsgdsg ' \
'sdgsdgdsgdsg sdgsdgdsgdsg sdgsdgdsgdsg sdgsdgdsgdsg sdgsdgdsgdsg sdgsdgdsgdsg ' \
'sdgsdgdsgdsg sdgsdgdsgdsg sdgsdgdsgdsg sdgsdgdsgdsg sdgsdgdsgdsg sdgsdgdsgdsg ' \
'sdgsdgdsgdsg sdgsdgdsgdsg sdgsdgdsgdsg sdgsdgdsgdsg </h3>\n', \
'</BODY> </endtagwithnostarttag> </HTML>']
self.assertEqual(delete_blank_lines(content), content_after_delete_blank_lines)
content = [' cats cats cats ', '\n', ' \n ', '<h1> \n', \
' ', ' </h1> \n', ' \n']
content_after_delete_blank_lines = [' cats cats cats ', '<h1> \n', \
' ', ' </h1> \n']
self.assertEqual(delete_blank_lines(content), content_after_delete_blank_lines)
def test_add_blank_lines(self):
content = [' <htmL><heAd>\n', \
'<TITLE>Gensler & Zudans Family Dentistry</title>\n', \
'<STYLE></style></head>\n', ' <body>\n', '\n', '\n', \
'<area><BASE>\n', \
'sdfdf<H1>WELCOME TO GENSLER & ZUDANS FAMILY DENTISTRY!</H1>\n', \
' <img src="gensler_and_zudans_family_dentistry.jpg">\n', \
'\n', '<helLO>\n', '\n', ' asfasf</HELLO>\n', '\n', ' \n', \
' <p>Address:<br>\n', '1303 Mount Holly Rd.<BR>\n', \
' Burlington, NJ 08016\n', \
' <h2> whats up with cats???!?!?!!?\n', '\n', \
' </h2></P>\n', '\n', \
'<h3> sdgsdgdsgdsg sdgsdgdsgdsg sdgsdgdsgdsg sdgsdgdsgdsg sdgsdgdsgdsg' \
'sdgsdgdsgdsg sdgsdgdsgdsg sdgsdgdsgdsg sdgsdgdsgdsg sdgsdgdsgdsg sdgsdgdsgdsg ' \
'sdgsdgdsgdsg sdgsdgdsgdsg sdgsdgdsgdsg sdgsdgdsgdsg sdgsdgdsgdsg sdgsdgdsgdsg ' \
'sdgsdgdsgdsg sdgsdgdsgdsg sdgsdgdsgdsg sdgsdgdsgdsg sdgsdgdsgdsg sdgsdgdsgdsg ' \
'sdgsdgdsgdsg sdgsdgdsgdsg sdgsdgdsgdsg sdgsdgdsgdsg </h3>\n', '\n', \
'</BODY> </endtagwithnostarttag> </HTML>']
content_after_add_blank_lines = [' <htmL><heAd>\n', \
'<TITLE>Gensler & Zudans Family Dentistry</title>\n', \
'<STYLE></style></head>\n', '\n', ' <body>\n', '\n', '\n', \
'<area><BASE>\n', \
'sdfdf<H1>WELCOME TO GENSLER & ZUDANS FAMILY DENTISTRY!</H1>\n', \
' <img src="gensler_and_zudans_family_dentistry.jpg">\n', \
'\n', '<helLO>\n', '\n', ' asfasf</HELLO>\n', '\n', ' \n', \
' <p>Address:<br>\n', '1303 Mount Holly Rd.<BR>\n', \
' Burlington, NJ 08016\n', '\n', \
' <h2> whats up with cats???!?!?!!?\n', '\n', \
' </h2></P>\n', '\n', '\n', \
'<h3> sdgsdgdsgdsg sdgsdgdsgdsg sdgsdgdsgdsg sdgsdgdsgdsg sdgsdgdsgdsg' \
'sdgsdgdsgdsg sdgsdgdsgdsg sdgsdgdsgdsg sdgsdgdsgdsg sdgsdgdsgdsg sdgsdgdsgdsg ' \
'sdgsdgdsgdsg sdgsdgdsgdsg sdgsdgdsgdsg sdgsdgdsgdsg sdgsdgdsgdsg sdgsdgdsgdsg ' \
'sdgsdgdsgdsg sdgsdgdsgdsg sdgsdgdsgdsg sdgsdgdsgdsg sdgsdgdsgdsg sdgsdgdsgdsg ' \
'sdgsdgdsgdsg sdgsdgdsgdsg sdgsdgdsgdsg sdgsdgdsgdsg </h3>\n', '\n', \
'</BODY> </endtagwithnostarttag> </HTML>']
self.assertEqual(add_blank_lines(content), content_after_add_blank_lines)
content = ['<head> cats are so cute</head>', '<body>', '<h1>cats cats cats</h1></body>']
content_after_add_blank_lines = ['\n', '<head> cats are so cute</head>', \
'\n', '<body>', '\n', '<h1>cats cats cats</h1></body>']
self.assertEqual(add_blank_lines(content), content_after_add_blank_lines)
def test_line_length(self):
content = ['<head>\n', \
'sdgsgdsgsdgdsgdsggs sdgsdgdgsdgdsgsdgdssdgsdgsdg sdfsd sdfsdf ' \
'sddgsdgdsgsdgsdgsdgsdgsdg sdgsdgsdgsdgsdgsdg\n', \
'sdgsdgdsgdsgdsg sdgsdgsdgdsgdsgdsgsdgsdgdsgsdgdsgsdgdsgsdg ' \
'sasgsdgdgsdgsdgsdgsdgsdgsdgsdgsdgsdsdg\n', \
'sddgsdgsdgsdgsdgdsgdsgsdgsdgsdgdsgsdgsdgdsgsdgsdgsdgsdgsdg ' \
'sdfsdgdsgdsgsdgsgdsgdsgdsgdsdsgdsgsdgsdgsdgsdgdsgsdgsd\n']
content_after_line_length = ['<head>\n', \
'sdgsgdsgsdgdsgdsggs sdgsdgdgsdgdsgsdgdssdgsdgsdg sdfsd sdfsdf\n', \
'sddgsdgdsgsdgsdgsdgsdgsdg sdgsdgsdgsdgsdgsdg\n', \
'sdgsdgdsgdsgdsg sdgsdgsdgdsgdsgdsgsdgsdgdsgsdgdsgsdgdsgsdg\n', \
'sasgsdgdgsdgsdgsdgsdgsdgsdgsdgsdgsdsdg\n', \
'sddgsdgsdgsdgsdgdsgdsgsdgsdgsdgdsgsdgsdgdsgsdgsdgsdgsdgsdg\n', \
'sdfsdgdsgdsgsdgsgdsgdsgdsgdsdsgdsgsdgsdgsdgsdgdsgsdgsd\n']
self.assertEqual(line_length(content), content_after_line_length)
def test_find_first_space_before_80(self):
line = '<head> catscatscatscatscatscatscatscats</head>'
line = line * 2
self.assertEqual(find_first_space_before_80(line), 52)
line = line * 2
self.assertEqual(find_first_space_before_80(line), 52)
line = '<head>catscatscatscatscatscatscatscats</head>'
line = line * 2
self.assertEqual(find_first_space_before_80(line), -1)
'''was unable to finish the following unit tests in time:
def test_indent_lines(self):
def test_indent_all_tags(self):
def test_start_tag_exists(self):
def test_fix_nesting(self):
def test_delete_xtra_end_tags(self):'''
unittest.main()