1#!/usr/bin/env python 2# vim:fileencoding=utf-8 3# License: Apache 2.0 Copyright: 2017, Kovid Goyal <kovid at kovidgoyal.net> 4 5from __future__ import absolute_import, division, print_function, unicode_literals 6 7from . import TestCase 8from html5_parser import parse 9 10 11class BasicTests(TestCase): 12 13 def test_name_sanitization(self): 14 root = parse('<p bad(attr=x><bad:name/>') 15 p = root[1][0] 16 self.ae(p.attrib, {'bad_attr': 'x'}) 17 self.ae(p[0].tag, 'bad_name') 18 19 def test_multiple_roots(self): 20 root = parse("<html><html />", maybe_xhtml=True) 21 from lxml import etree 22 self.ae(etree.tostring(root, encoding='unicode'), 23 '<html xmlns="http://www.w3.org/1999/xhtml"><head/><body/></html>') 24