From 3dbe211d29c84aaceceb80fc9572ed597aac94d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Gra=C3=B1a?= Date: Fri, 13 Apr 2012 09:29:56 -0300 Subject: [PATCH] lxml boolean results fix. oops #116 --- scrapy/selector/lxmlsel.py | 7 ++++++- scrapy/tests/test_selector.py | 8 ++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/scrapy/selector/lxmlsel.py b/scrapy/selector/lxmlsel.py index 301858890..bb0a4e1ec 100644 --- a/scrapy/selector/lxmlsel.py +++ b/scrapy/selector/lxmlsel.py @@ -68,7 +68,12 @@ class XPathSelector(object_ref): return etree.tostring(self.root, method=self._tostring_method, \ encoding=unicode) except (AttributeError, TypeError): - return unicode(self.root) + if self.root is True: + return u'1' + elif self.root is False: + return u'0' + else: + return unicode(self.root) def register_namespace(self, prefix, uri): if self.namespaces is None: diff --git a/scrapy/tests/test_selector.py b/scrapy/tests/test_selector.py index 20672098f..e4197b084 100644 --- a/scrapy/tests/test_selector.py +++ b/scrapy/tests/test_selector.py @@ -63,12 +63,8 @@ class XPathSelectorTestCase(unittest.TestCase): body = "

" response = TextResponse(url="http://example.com", body=body) xs = self.hxs_cls(response) - true = xs.select("//input[@name='a']/@name='a'").extract()[0] - false = xs.select("//input[@name='a']/@name='n'").extract()[0] - - # the actual result depends on the backend used - assert true in [u'1', u'True'], true - assert false in [u'0', u'False'], false + self.assertEquals(xs.select("//input[@name='a']/@name='a'").extract(), [u'1']) + self.assertEquals(xs.select("//input[@name='a']/@name='n'").extract(), [u'0']) @libxml2debug def test_selector_xml_html(self):