Home | History | Annotate | Download | only in tests
      1 from __future__ import absolute_import, division, unicode_literals
      2 
      3 import io
      4 
      5 from . import support  # flake8: noqa
      6 from html5lib import html5parser
      7 from html5lib.constants import namespaces
      8 from html5lib import treebuilders
      9 
     10 import unittest
     11 
     12 # tests that aren't autogenerated from text files
     13 
     14 
     15 class MoreParserTests(unittest.TestCase):
     16 
     17     def setUp(self):
     18         self.dom_tree = treebuilders.getTreeBuilder("dom")
     19 
     20     def test_assertDoctypeCloneable(self):
     21         parser = html5parser.HTMLParser(tree=self.dom_tree)
     22         doc = parser.parse('<!DOCTYPE HTML>')
     23         self.assertTrue(doc.cloneNode(True))
     24 
     25     def test_line_counter(self):
     26         # http://groups.google.com/group/html5lib-discuss/browse_frm/thread/f4f00e4a2f26d5c0
     27         parser = html5parser.HTMLParser(tree=self.dom_tree)
     28         parser.parse("<pre>\nx\n&gt;\n</pre>")
     29 
     30     def test_namespace_html_elements_0_dom(self):
     31         parser = html5parser.HTMLParser(tree=self.dom_tree, namespaceHTMLElements=True)
     32         doc = parser.parse("<html></html>")
     33         self.assertTrue(doc.childNodes[0].namespaceURI == namespaces["html"])
     34 
     35     def test_namespace_html_elements_1_dom(self):
     36         parser = html5parser.HTMLParser(tree=self.dom_tree, namespaceHTMLElements=False)
     37         doc = parser.parse("<html></html>")
     38         self.assertTrue(doc.childNodes[0].namespaceURI is None)
     39 
     40     def test_namespace_html_elements_0_etree(self):
     41         parser = html5parser.HTMLParser(namespaceHTMLElements=True)
     42         doc = parser.parse("<html></html>")
     43         self.assertTrue(list(doc)[0].tag == "{%s}html" % (namespaces["html"],))
     44 
     45     def test_namespace_html_elements_1_etree(self):
     46         parser = html5parser.HTMLParser(namespaceHTMLElements=False)
     47         doc = parser.parse("<html></html>")
     48         self.assertTrue(list(doc)[0].tag == "html")
     49 
     50     def test_unicode_file(self):
     51         parser = html5parser.HTMLParser()
     52         parser.parse(io.StringIO("a"))
     53 
     54 
     55 def buildTestSuite():
     56     return unittest.defaultTestLoader.loadTestsFromName(__name__)
     57 
     58 
     59 def main():
     60     buildTestSuite()
     61     unittest.main()
     62 
     63 if __name__ == '__main__':
     64     main()
     65