Skip to content

Commit 7fe0b21

Browse files
committed
Add unit test functions for doctype
1 parent 135b1d7 commit 7fe0b21

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

tests/AdvancedHTMLParserTests/test_General.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,27 @@ def test_getForms(self):
257257
except ImportError:
258258
sys.stderr.write('WARNING: .filter is disabled via ImportError. QueryableList not installed?\n\n')
259259

260+
def test_doctype(self):
261+
'''
262+
test_doctype - Test doctype stuff
263+
'''
264+
265+
parser = AdvancedHTMLParser.AdvancedHTMLParser()
266+
parser.parseStr('''<!DOCTYPE html>\n<html><head></head><body></body></html>''')
267+
268+
assert '<!DOCTYPE html>' in parser.getHTML(), 'Parsed html string with doctype, but lost doctype in getHTML output'
269+
270+
parser = AdvancedHTMLParser.AdvancedHTMLParser()
271+
parser.parseStr('''<html><head></head><body></body></html>''')
272+
273+
assert '<!DOCTYPE html>' not in parser.getHTML(), 'Parsed html stripg without doctype, but one got added and was present in getHTML output'
274+
275+
parser.setDoctype('DOCTYPE html')
276+
assert '<!DOCTYPE html>' in parser.getHTML(), 'called setDoctype to set a doctype, but it was not in the getHTML output, as expected.'
277+
278+
parser.setDoctype(None)
279+
assert '<!DOCTYPE html>' not in parser.getHTML(), 'called setDoctype to clear a doctype, but it was still in the getHTML output'
280+
260281

261282

262283
if __name__ == '__main__':

0 commit comments

Comments
 (0)