Exemplo n.º 1
0
    def test_incorrect_xpath(self):
        # The lxml xpath function return boolean for following xpath
        # This breaks selector internal logic that assumes that only
        # list could be returnsed
        # So it was fixed and this test was crated
        sel = XpathSelector(self.tree).select('//ul/li/text()="oops"')
        self.assertEquals(False, sel.exists())

        # Selector list is always empty in this special case
        # Even if the xpath return True on lxml level
        self.assertEquals(True, self.tree.xpath('//ul[1]/li[1]/text()="one"'))
        sel = XpathSelector(self.tree).select('//ul[1]/li[1]/text()="one"')
        self.assertEquals(False, sel.exists())
Exemplo n.º 2
0
    def test_incorrect_xpath(self):
        # The lxml xpath function return boolean for following xpath
        # This breaks selector internal logic that assumes that only
        # list could be returnsed
        # So it was fixed and this test was crated
        sel = XpathSelector(self.tree).select('//ul/li/text()="oops"')
        self.assertEquals(False, sel.exists())

        # Selector list is always empty in this special case
        # Even if the xpath return True on lxml level
        self.assertEquals(True, self.tree.xpath('//ul[1]/li[1]/text()="one"'))
        sel = XpathSelector(self.tree).select('//ul[1]/li[1]/text()="one"')
        self.assertEquals(False, sel.exists())
Exemplo n.º 3
0
 def test_select_select(self):
     root = XpathSelector(self.tree)
     self.assertEquals(
         set(['one', 'yet one']),
         set([x.text() for x in root.select('//ul').select('./li[1]')]),
     )
Exemplo n.º 4
0
 def test_textselector(self):
     self.assertEquals(
         'one',
         XpathSelector(self.tree).select('//li/text()').text())
Exemplo n.º 5
0
 def test_text_selector(self):
     sel = XpathSelector(self.tree).select('//li/text()').one()
     self.assertTrue(isinstance(sel, TextSelector))
Exemplo n.º 6
0
 def test_select_node(self):
     self.assertEquals('test',
                       XpathSelector(self.tree).select('//h1')[0].node.text)
Exemplo n.º 7
0
 def test_html(self):
     sel = XpathSelector(self.tree.xpath('//h1')[0])
     self.assertEquals('<h1>test</h1>', sel.html().strip())
Exemplo n.º 8
0
 def test_text_list(self):
     root = XpathSelector(self.tree)
     self.assertEquals(set(['one', 'yet one']),
                       set(root.select('//ul/li[1]').text_list()),
                       )
Exemplo n.º 9
0
 def test_in_general(self):
     sel = XpathSelector(self.tree)
Exemplo n.º 10
0
 def select(self, *args, **kwargs):
     return XpathSelector(self.tree).select(*args, **kwargs)
Exemplo n.º 11
0
 def test_one(self):
     sel = XpathSelector(self.tree).select('//ul/li')
     self.assertEquals('one', sel.one().node.text)
     self.assertEquals('one', sel.text())
Exemplo n.º 12
0
    def test_exists(self):
        sel = XpathSelector(self.tree).select('//li[4]')
        self.assertEquals(True, sel.exists())

        sel = XpathSelector(self.tree).select('//li[5]')
        self.assertEquals(False, sel.exists())
Exemplo n.º 13
0
 def _selector(self):
     return XpathSelector(self._node)
Exemplo n.º 14
0
 def test_number(self):
     sel = XpathSelector(self.tree).select('//li[4]')
     self.assertEquals(4, sel.number())
Exemplo n.º 15
0
 def test_one(self):
     sel = XpathSelector(self.tree).select('//ul/li')
     self.assertEquals('one', sel.one().node.text)
     self.assertEquals('one', sel.text())
Exemplo n.º 16
0
 def test_attr_list(self):
     root = XpathSelector(self.tree)
     self.assertEquals(set(['li-1', 'li-2']),
                       set(root.select('//ul[@id="second-list"]/li')\
                               .attr_list('class'))
                       )
Exemplo n.º 17
0
 def test_text_list(self):
     root = XpathSelector(self.tree)
     self.assertEquals(
         set(['one', 'yet one']),
         set(root.select('//ul/li[1]').text_list()),
     )
Exemplo n.º 18
0
 def test_html(self):
     sel = XpathSelector(self.tree.xpath('//h1')[0])
     self.assertEquals('<h1>test</h1>', sel.html().strip())
Exemplo n.º 19
0
 def test_attr_list(self):
     root = XpathSelector(self.tree)
     self.assertEquals(set(['li-1', 'li-2']),
                       set(root.select('//ul[@id="second-list"]/li')\
                               .attr_list('class'))
                       )
Exemplo n.º 20
0
 def test_select_select(self):
     root = XpathSelector(self.tree)
     self.assertEquals(set(['one', 'yet one']),
                       set([x.text() for x in root.select('//ul').select('./li[1]')]),
                       )
Exemplo n.º 21
0
 def test_number(self):
     sel = XpathSelector(self.tree).select('//ul/li[4]')
     self.assertEquals(4, sel.number())
Exemplo n.º 22
0
    def test_exists(self):
        sel = XpathSelector(self.tree).select('//ul/li[4]')
        self.assertEquals(True, sel.exists())

        sel = XpathSelector(self.tree).select('//ul/li[5]')
        self.assertEquals(False, sel.exists())