diff options
author | Leonard Richardson <leonardr@segfault.org> | 2019-07-21 15:50:49 -0400 |
---|---|---|
committer | Leonard Richardson <leonardr@segfault.org> | 2019-07-21 15:50:49 -0400 |
commit | 41c2b7c056e73c63c872eeb0a5e3a1f65473eaf0 (patch) | |
tree | 514f0a3ccd449c74d847917471ec6c09642e1318 /bs4/tests/test_lxml.py | |
parent | b2294f4f05d9e8583613560986f8aa64b18866b9 (diff) |
Implemented line number tracking for html5lib.
Diffstat (limited to 'bs4/tests/test_lxml.py')
-rw-r--r-- | bs4/tests/test_lxml.py | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/bs4/tests/test_lxml.py b/bs4/tests/test_lxml.py index 3b7858f..f96e4ae 100644 --- a/bs4/tests/test_lxml.py +++ b/bs4/tests/test_lxml.py @@ -71,6 +71,21 @@ class LXMLTreeBuilderSmokeTest(SoupTest, HTMLTreeBuilderSmokeTest): self.assertEqual(u"<b/>", unicode(soup.b)) self.assertTrue("BeautifulStoneSoup class is deprecated" in str(w[0].message)) + def test_tracking_line_numbers(self): + # The lxml TreeBuilder cannot keep track of line numbers from + # the original markup. Even if you ask for line numbers, we + # don't have 'em. + # + # This means that if you have a tag like <sourceline> or + # <sourcepos>, attribute access will find it rather than + # giving you a numeric answer. + soup = self.soup( + "\n <p>\n\n<sourceline>\n<b>text</b></sourceline><sourcepos></p>", + store_line_numbers=True + ) + self.assertEqual("sourceline", soup.p.sourceline.name) + self.assertEqual("sourcepos", soup.p.sourcepos.name) + @skipIf( not LXML_PRESENT, "lxml seems not to be present, not testing its XML tree builder.") |