~facelessuser/beautifulsoup/lxml-fix

« back to all changes in this revision

Viewing changes to bs4/tests/test_html5lib.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:
168
168
        for form in soup.find_all('form'):
169
169
            inputs.extend(form.find_all('input'))
170
170
        self.assertEqual(len(inputs), 1)
 
171
 
 
172
    def test_tracking_line_numbers(self):
 
173
        # The html.parser TreeBuilder keeps track of line number and
 
174
        # position of each element.
 
175
        markup = "\n   <p>\n\n<sourceline>\n<b>text</b></sourceline><sourcepos></p>"
 
176
        soup = self.soup(markup)
 
177
        self.assertEqual(2, soup.p.sourceline)
 
178
        self.assertEqual(5, soup.p.sourcepos)
 
179
        self.assertEqual("sourceline", soup.p.find('sourceline').name)
 
180
 
 
181
        # You can deactivate this behavior.
 
182
        soup = self.soup(markup, store_line_numbers=False)
 
183
        self.assertEqual("sourceline", soup.p.sourceline.name)
 
184
        self.assertEqual("sourcepos", soup.p.sourcepos.name)