Scrapy, a fast high-level web crawling & scraping framework for Python.
added xpathitemloader tests
Ismael Carnalesbb4871b7a744
diff --git a/scrapy/tests/test_contrib_loader.py b/scrapy/tests/test_contrib_loader.pyindex f05cb438a..40960f16a 100644--- a/scrapy/tests/test_contrib_loader.py+++ b/scrapy/tests/test_contrib_loader.py@@ -311,6 +311,7 @@ class TestXPathItemLoader(XPathItemLoader):name_in = MapCompose(lambda v: v.title())class XPathItemLoaderTest(unittest.TestCase):+ response = HtmlResponse(url="", body='<html><body><div id="id">marta</div><p>paragraph</p></body></html>')def test_constructor_errors(self):self.assertRaises(RuntimeError, XPathItemLoader)@@ -323,18 +324,32 @@ class XPathItemLoaderTest(unittest.TestCase):self.assertEqual(l.get_output_value('name'), [u'Marta'])def test_constructor_with_response(self):- response = HtmlResponse(url="", body="<html><body><div>marta</div></body></html>")- l = TestXPathItemLoader(response=response)+ l = TestXPathItemLoader(response=self.response)self.assert_(l.selector)l.add_xpath('name', '//div/text()')self.assertEqual(l.get_output_value('name'), [u'Marta'])def test_add_xpath_re(self):- response = HtmlResponse(url="", body="<html><body><div>marta</div></body></html>")- l = TestXPathItemLoader(response=response)+ l = TestXPathItemLoader(response=self.response)l.add_xpath('name', '//div/text()', re='ma')self.assertEqual(l.get_output_value('name'), [u'Ma'])+ def test_replace_xpath(self):+ l = TestXPathItemLoader(response=self.response)+ self.assert_(l.selector)+ l.add_xpath('name', '//div/text()')+ self.assertEqual(l.get_output_value('name'), [u'Marta'])+ l.replace_xpath('name', '//p/text()')+ self.assertEqual(l.get_output_value('name'), [u'Paragraph'])++ def test_replace_xpath_re(self):+ l = TestXPathItemLoader(response=self.response)+ self.assert_(l.selector)+ l.add_xpath('name', '//div/text()')+ self.assertEqual(l.get_output_value('name'), [u'Marta'])+ l.replace_xpath('name', '//div/text()', re='ma')+ self.assertEqual(l.get_output_value('name'), [u'Ma'])+if __name__ == "__main__":unittest.main()