From 9b9ab378049afb69edac266ba4236e6773f82cfb Mon Sep 17 00:00:00 2001 From: Pablo Hoffman Date: Wed, 27 Oct 2010 08:03:37 -0200 Subject: [PATCH] fixed bug with boolean results in lxml-based selectors --- scrapy/selector/lxmlsel.py | 2 +- scrapy/tests/test_selector_lxml.py | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/scrapy/selector/lxmlsel.py b/scrapy/selector/lxmlsel.py index af5f765b4..55d1a48e6 100644 --- a/scrapy/selector/lxmlsel.py +++ b/scrapy/selector/lxmlsel.py @@ -55,7 +55,7 @@ class XPathSelector(object_ref): if hasattr(result, '__iter__'): result = [self.__class__(root=x, expr=xpath, namespaces=self.namespaces) \ for x in result] - elif result: + else: result = [self.__class__(root=result, expr=xpath, namespaces=self.namespaces)] return XPathSelectorList(result) diff --git a/scrapy/tests/test_selector_lxml.py b/scrapy/tests/test_selector_lxml.py index b16a2e2bf..75375a57f 100644 --- a/scrapy/tests/test_selector_lxml.py +++ b/scrapy/tests/test_selector_lxml.py @@ -45,6 +45,14 @@ class XPathSelectorTestCase(unittest.TestCase): self.assertEqual([x.extract() for x in xpath.select("concat(//input[@name='a']/@value, //input[@name='b']/@value)")], [u'12']) + @libxml2debug + def test_selector_boolean_result(self): + body = "

" + response = TextResponse(url="http://example.com", body=body) + xs = HtmlXPathSelector(response) + self.assertEqual(xs.select("//input[@name='a']/@name='a'").extract(), [u'True']) + self.assertEqual(xs.select("//input[@name='a']/@name='n'").extract(), [u'False']) + @libxml2debug def test_selector_same_type(self): """Test XPathSelector returning the same type in x() method"""