File tree 5 files changed +74
-12
lines changed
5 files changed +74
-12
lines changed Original file line number Diff line number Diff line change @@ -7,20 +7,21 @@ branches:
7
7
8
8
matrix :
9
9
include :
10
- - python : 3.5
11
- env : TOXENV=py35
10
+ - python : 3.7
11
+ env : TOXENV=docs
12
+
12
13
- python : 3.6
13
- env : TOXENV=py36
14
+ env : TOXENV=py
14
15
- python : 3.7
15
- env : TOXENV=py37
16
+ env : TOXENV=py
16
17
- python : 3.8
17
- env : TOXENV=py38
18
+ env : TOXENV=py
18
19
19
20
- python : pypy3
20
21
env : TOXENV=pypy3
21
22
22
- - python : 3.7
23
- env : TOXENV=docs
23
+ - python : 3.8
24
+ env : TOXENV=extra-deps
24
25
25
26
install :
26
27
- pip install -U tox codecov
Original file line number Diff line number Diff line change 2
2
Copy/paste from scrapy source at the moment, to ensure tests are working.
3
3
Refactoring to come later
4
4
"""
5
- from functools import partial
6
5
import inspect
6
+ from functools import partial
7
+
8
+ from itemadapter import is_item
7
9
8
10
9
- _ITERABLE_SINGLE_VALUES = dict , str , bytes
11
+ _ITERABLE_SINGLE_VALUES = str , bytes
10
12
11
13
12
14
def arg_to_iter (arg ):
@@ -17,7 +19,11 @@ def arg_to_iter(arg):
17
19
"""
18
20
if arg is None :
19
21
return []
20
- elif not isinstance (arg , _ITERABLE_SINGLE_VALUES ) and hasattr (arg , '__iter__' ):
22
+ elif (
23
+ hasattr (arg , '__iter__' )
24
+ and not isinstance (arg , _ITERABLE_SINGLE_VALUES )
25
+ and not is_item (arg )
26
+ ):
21
27
return arg
22
28
else :
23
29
return [arg ]
Original file line number Diff line number Diff line change 27
27
'Operating System :: OS Independent' ,
28
28
'Programming Language :: Python' ,
29
29
'Programming Language :: Python :: 3' ,
30
- 'Programming Language :: Python :: 3.5' ,
31
30
'Programming Language :: Python :: 3.6' ,
32
31
'Programming Language :: Python :: 3.7' ,
33
32
'Programming Language :: Python :: 3.8' ,
34
33
'Programming Language :: Python :: Implementation :: CPython' ,
35
34
'Programming Language :: Python :: Implementation :: PyPy' ,
36
35
],
37
- python_requires = '>=3.5 ' ,
36
+ python_requires = '>=3.6 ' ,
38
37
install_requires = [
39
38
# before updating these versions, be sure they are not higher than
40
39
# scrapy's requirements
Original file line number Diff line number Diff line change
1
+ import unittest
2
+
3
+ from itemloaders import ItemLoader
4
+
5
+
6
+ class NestedItemTest (unittest .TestCase ):
7
+ """Test that adding items as values works as expected."""
8
+
9
+ def _test_item (self , item ):
10
+ il = ItemLoader ()
11
+ il .add_value ('item_list' , item )
12
+ self .assertEqual (il .load_item (), {'item_list' : [item ]})
13
+
14
+ def test_attrs (self ):
15
+ try :
16
+ import attr
17
+ except ImportError :
18
+ self .skipTest ("Cannot import attr" )
19
+
20
+ @attr .s
21
+ class TestItem :
22
+ foo = attr .ib ()
23
+
24
+ self ._test_item (TestItem (foo = 'bar' ))
25
+
26
+ def test_dataclass (self ):
27
+ try :
28
+ from dataclasses import dataclass
29
+ except ImportError :
30
+ self .skipTest ("Cannot import dataclasses.dataclass" )
31
+
32
+ @dataclass
33
+ class TestItem :
34
+ foo : str
35
+
36
+ self ._test_item (TestItem (foo = 'bar' ))
37
+
38
+ def test_dict (self ):
39
+ self ._test_item ({'foo' : 'bar' })
40
+
41
+ def test_scrapy_item (self ):
42
+ try :
43
+ from scrapy import Field , Item
44
+ except ImportError :
45
+ self .skipTest ("Cannot import Field or Item from scrapy" )
46
+
47
+ class TestItem (Item ):
48
+ foo = Field ()
49
+
50
+ self ._test_item (TestItem (foo = 'bar' ))
Original file line number Diff line number Diff line change @@ -12,6 +12,12 @@ commands =
12
12
--doctest-modules \
13
13
{posargs:itemloaders tests}
14
14
15
+ [testenv:extra-deps]
16
+ deps =
17
+ {[testenv]deps}
18
+ attrs
19
+ scrapy
20
+
15
21
[testenv:pypy3]
16
22
basepython = pypy3
17
23
You can’t perform that action at this time.
0 commit comments