~facelessuser/beautifulsoup/lxml-fix

« back to all changes in this revision

Viewing changes to bs4/tests/test_htmlparser.py

  • Committer: Leonard Richardson
  • Date: 2019-07-21 19:50:49 UTC
  • Revision ID: leonardr@segfault.org-20190721195049-vzupkzxai3bx3r8t
Implemented line number tracking for html5lib.

Show diffs side-by-side

added added

removed removed

Lines of Context:
38
38
        self.assertSoupEquals("foo &# bar", "foo &# bar")
39
39
 
40
40
    def test_tracking_line_numbers(self):
41
 
        # Unlike other TreeBuilders, the html.parser TreeBuilder
42
 
        # keeps track of line number and position of each element.
43
 
        soup = self.soup(
44
 
            "\n   <p>\n\n<lineno>\n<b>text</b></lineno><offset></p>",
45
 
            store_line_numbers=True
46
 
        )
47
 
        self.assertEqual(2, soup.p.lineno)
48
 
        self.assertEqual(3, soup.p.offset)
49
 
        self.assertEqual("lineno", soup.p.find('lineno').name)
50
 
 
51
 
 
 
41
        # The html.parser TreeBuilder keeps track of line number and
 
42
        # position of each element.
 
43
        markup = "\n   <p>\n\n<sourceline>\n<b>text</b></sourceline><sourcepos></p>"
 
44
        soup = self.soup(markup)
 
45
        self.assertEqual(2, soup.p.sourceline)
 
46
        self.assertEqual(3, soup.p.sourcepos)
 
47
        self.assertEqual("sourceline", soup.p.find('sourceline').name)
 
48
 
 
49
        # You can deactivate this behavior.
 
50
        soup = self.soup(markup, store_line_numbers=False)
 
51
        self.assertEqual("sourceline", soup.p.sourceline.name)
 
52
        self.assertEqual("sourcepos", soup.p.sourcepos.name)
 
53
 
 
54
        
52
55
class TestHTMLParserSubclass(SoupTest):
53
56
    def test_error(self):
54
57
        """Verify that our HTMLParser subclass implements error() in a way