~facelessuser/beautifulsoup/lxml-fix

« back to all changes in this revision

Viewing changes to bs4/tests/test_lxml.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:
71
71
        self.assertEqual(u"<b/>", unicode(soup.b))
72
72
        self.assertTrue("BeautifulStoneSoup class is deprecated" in str(w[0].message))
73
73
 
 
74
    def test_tracking_line_numbers(self):
 
75
        # The lxml TreeBuilder cannot keep track of line numbers from
 
76
        # the original markup. Even if you ask for line numbers, we
 
77
        # don't have 'em.
 
78
        #
 
79
        # This means that if you have a tag like <sourceline> or
 
80
        # <sourcepos>, attribute access will find it rather than
 
81
        # giving you a numeric answer.
 
82
        soup = self.soup(
 
83
            "\n   <p>\n\n<sourceline>\n<b>text</b></sourceline><sourcepos></p>",
 
84
            store_line_numbers=True
 
85
        )
 
86
        self.assertEqual("sourceline", soup.p.sourceline.name)
 
87
        self.assertEqual("sourcepos", soup.p.sourcepos.name)
 
88
        
74
89
@skipIf(
75
90
    not LXML_PRESENT,
76
91
    "lxml seems not to be present, not testing its XML tree builder.")