'Test parsing with the HTML5 parser used for polishing'

def test_polish_parser(self):

    for test in basic_checks:
        test(self, parse)
    root = parse(u'<html><p><svg><image    /><b></svg>&nbsp;\n<b>xxx', discard_namespaces=True)
    self.assertTrue(root.xpath(u'//b'), u'Namespaces    not    discarded')
    self.assertFalse(root.xpath(u'//svg/b'), u'The    <b>    was    not    moved    out    of    <svg>')
    for ds in (False, True):
        src = u'\n<html>\n<p>\n<svg><image    />\n<b></svg>&nbsp'
        root = parse(src, discard_namespaces=ds)
        for (tag, lnum) in {u'html': 2, u'head': 3, u'body': 3, u'p': 3, u'svg': 4, u'image': 4, u'b': 5}.iteritems():
            elem = root.xpath((u'//*[local-name()="%s"]' % tag))[0]
            self.assertEqual(lnum, elem.sourceline, (u'Line    number    incorrect    for    %s,    source:    %s:' % (tag, src)))
    for ds in (False, True):
        src = u'\n<html>\n<p    b=1    a=2    c=3    d=4    e=5    f=6    g=7    h=8><svg    b=1    a=2    c=3    d=4    e=5    f=6    g=7    h=8>\n'
        root = parse(src, discard_namespaces=ds)
        for tag in (u'p', u'svg'):
            for (i, (k, v)) in enumerate(root.xpath((u'//*[local-name()="%s"]' % tag))[0].items()):
                self.assertEqual((i + 1), int(v))
    root = parse(u'<html    xmlns="http://www.w3.org/1999/xhtml"    xml:lang="en-US"    xmlns:xml="http://www.w3.org/XML/1998/namespace"><body/></html>')
    self.assertNotIn(u'xmlnsU0003Axml', root.attrib, u'xml    namespace    declaration    not    removed')
    root = parse(u'<html    xmlns="http://www.w3.org/1999/xhtml"    xml:lang="en-US"    xmlns:extra="extra"><body/></html>')
    self.assertIn(u'extra', root.nsmap, u'Extra    namespace    declaration    on    <html>    tag    not    preserved')
