[itemloader-errors] added test for Compose and MapCompose

#3836
This commit is contained in:
Mabel Villalba 2019-06-25 14:35:49 +02:00
parent 99eb03a810
commit a753ea7e16
1 changed files with 9 additions and 0 deletions

View File

@ -483,12 +483,21 @@ class ProcessorsTest(unittest.TestCase):
self.assertEqual(proc(None), None)
proc = Compose(str.upper, stop_on_none=False)
self.assertRaises(ValueError, proc, None)
proc = Compose(str.upper, lambda x: x + 1)
self.assertRaises(ValueError, proc, 'hello')
def test_mapcompose(self):
filter_world = lambda x: None if x == 'world' else x
proc = MapCompose(filter_world, six.text_type.upper)
self.assertEqual(proc([u'hello', u'world', u'this', u'is', u'scrapy']),
[u'HELLO', u'THIS', u'IS', u'SCRAPY'])
proc = MapCompose(filter_world, six.text_type.upper)
self.assertEqual(proc(None), [])
proc = MapCompose(filter_world, six.text_type.upper)
self.assertRaises(ValueError, proc, [1])
proc = MapCompose(filter_world, lambda x: x + 1)
self.assertRaises(ValueError, proc, 'hello')
class SelectortemLoaderTest(unittest.TestCase):