Scrapy, a fast high-level web crawling & scraping framework for Python.
added tests for builtin loader processors
Pablo Hoffman162498144365
diff --git a/scrapy/tests/test_contrib_loader.py b/scrapy/tests/test_contrib_loader.pyindex 0b8c90930..7ffb0e666 100644--- a/scrapy/tests/test_contrib_loader.py+++ b/scrapy/tests/test_contrib_loader.py@@ -1,7 +1,8 @@import unittestfrom scrapy.contrib.loader import ItemLoader, XPathItemLoader-from scrapy.contrib.loader.processor import Join, Identity, Compose, MapCompose+from scrapy.contrib.loader.processor import Join, Identity, TakeFirst, \+ Compose, MapComposefrom scrapy.newitem import Item, Fieldfrom scrapy.xpath import HtmlXPathSelectorfrom scrapy.http import HtmlResponse@@ -254,6 +255,33 @@ class ItemLoaderTest(unittest.TestCase):item = il.load_item()self.assertEqual(item['name'], u'Mart')+class ProcessorsTest(unittest.TestCase):++ def test_take_first(self):+ proc = TakeFirst()+ self.assertEqual(proc([None, '', 'hello', 'world']), 'hello')++ def test_identity(self):+ proc = Identity()+ self.assertEqual(proc([None, '', 'hello', 'world']),+ [None, '', 'hello', 'world'])++ def test_join(self):+ proc = Join()+ self.assertRaises(TypeError, proc, [None, '', 'hello', 'world'])+ self.assertEqual(proc(['', 'hello', 'world']), u' hello world')+ self.assertEqual(proc(['hello', 'world']), u'hello world')+ self.assert_(isinstance(proc(['hello', 'world']), unicode))++ def test_compose(self):+ proc = Compose(lambda v: v[0], str.upper)+ self.assertEqual(proc(['hello', 'world']), 'HELLO')++ def test_mapcompose(self):+ filter_world = lambda x: None if x == 'world' else x+ proc = MapCompose(filter_world, unicode.upper)+ self.assertEqual(proc([u'hello', u'world', u'this', u'is', u'scrapy']),+ [u'HELLO', u'THIS', u'IS', u'SCRAPY'])class TestXPathItemLoader(XPathItemLoader):default_item_class = TestItem