4
4
from itemloaders .processors import Identity , Compose , TakeFirst
5
5
6
6
7
- class TestOutputProcessorDict (unittest .TestCase ):
8
- def test_output_processor (self ):
7
+ def take_first (value ):
8
+ return value [0 ]
9
+
10
+
11
+ class TestOutputProcessor (unittest .TestCase ):
12
+
13
+ def test_item_class (self ):
9
14
10
15
class TempDict (dict ):
11
16
def __init__ (self , * args , ** kwargs ):
@@ -22,9 +27,8 @@ class TempLoader(ItemLoader):
22
27
self .assertIsInstance (item , TempDict )
23
28
self .assertEqual (dict (item ), {'temp' : 0.3 })
24
29
30
+ def test_item_object (self ):
25
31
26
- class TestOutputProcessorItem (unittest .TestCase ):
27
- def test_output_processor (self ):
28
32
class TempLoader (ItemLoader ):
29
33
default_input_processor = Identity ()
30
34
default_output_processor = Compose (TakeFirst ())
@@ -35,3 +39,14 @@ class TempLoader(ItemLoader):
35
39
item = loader .load_item ()
36
40
self .assertIsInstance (item , dict )
37
41
self .assertEqual (dict (item ), {'temp' : 0.3 })
42
+
43
+ def test_unbound_processor (self ):
44
+ """Ensure that a processor not taking a `self` parameter does not break
45
+ anything"""
46
+
47
+ class TempLoader (ItemLoader ):
48
+ default_output_processor = take_first
49
+
50
+ loader = TempLoader ()
51
+ loader .add_value ('foo' , 'bar' )
52
+ self .assertEqual (loader .load_item (), {'foo' : 'bar' })
0 commit comments