diff --git a/scrapy/tests/test_contrib_loader.py b/scrapy/tests/test_contrib_loader.py
index 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='
marta
paragraph
')
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="marta
")
- 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="marta
")
- 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()