fixed bug with boolean results in lxml-based selectors

This commit is contained in:
Pablo Hoffman 2010-10-27 08:03:37 -02:00
parent a8be54a8ea
commit 9b9ab37804
2 changed files with 9 additions and 1 deletions

View File

@ -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)

View File

@ -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 = "<p><input name='a'value='1'/><input name='b'value='2'/></p>"
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"""