예제 #1
0
파일: selector.py 프로젝트: ArturFis/grab
    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())
예제 #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())
예제 #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]')]),
     )
예제 #4
0
 def test_textselector(self):
     self.assertEquals(
         'one',
         XpathSelector(self.tree).select('//li/text()').text())
예제 #5
0
 def test_text_selector(self):
     sel = XpathSelector(self.tree).select('//li/text()').one()
     self.assertTrue(isinstance(sel, TextSelector))
예제 #6
0
 def test_select_node(self):
     self.assertEquals('test',
                       XpathSelector(self.tree).select('//h1')[0].node.text)
예제 #7
0
 def test_html(self):
     sel = XpathSelector(self.tree.xpath('//h1')[0])
     self.assertEquals('<h1>test</h1>', sel.html().strip())
예제 #8
0
파일: selector.py 프로젝트: vasia123/grab
 def test_text_list(self):
     root = XpathSelector(self.tree)
     self.assertEquals(set(['one', 'yet one']),
                       set(root.select('//ul/li[1]').text_list()),
                       )
예제 #9
0
 def test_in_general(self):
     sel = XpathSelector(self.tree)
예제 #10
0
파일: document.py 프로젝트: sergithon/grab
 def select(self, *args, **kwargs):
     return XpathSelector(self.tree).select(*args, **kwargs)
예제 #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())
예제 #12
0
파일: selector.py 프로젝트: vasia123/grab
    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())
예제 #13
0
파일: reference.py 프로젝트: sergithon/grab
 def _selector(self):
     return XpathSelector(self._node)
예제 #14
0
파일: selector.py 프로젝트: vasia123/grab
 def test_number(self):
     sel = XpathSelector(self.tree).select('//li[4]')
     self.assertEquals(4, sel.number())
예제 #15
0
파일: selector.py 프로젝트: vasia123/grab
 def test_one(self):
     sel = XpathSelector(self.tree).select('//ul/li')
     self.assertEquals('one', sel.one().node.text)
     self.assertEquals('one', sel.text())
예제 #16
0
파일: selector.py 프로젝트: vasia123/grab
 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'))
                       )
예제 #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()),
     )
예제 #18
0
파일: selector.py 프로젝트: vasia123/grab
 def test_html(self):
     sel = XpathSelector(self.tree.xpath('//h1')[0])
     self.assertEquals('<h1>test</h1>', sel.html().strip())
예제 #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'))
                       )
예제 #20
0
파일: selector.py 프로젝트: vasia123/grab
 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]')]),
                       )
예제 #21
0
 def test_number(self):
     sel = XpathSelector(self.tree).select('//ul/li[4]')
     self.assertEquals(4, sel.number())
예제 #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())