-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #29 from Gallaecio/scrapy-iterable-single-values
Restore support for nested Scrapy items
- Loading branch information
Showing
5 changed files
with
74 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import unittest | ||
|
||
from itemloaders import ItemLoader | ||
|
||
|
||
class NestedItemTest(unittest.TestCase): | ||
"""Test that adding items as values works as expected.""" | ||
|
||
def _test_item(self, item): | ||
il = ItemLoader() | ||
il.add_value('item_list', item) | ||
self.assertEqual(il.load_item(), {'item_list': [item]}) | ||
|
||
def test_attrs(self): | ||
try: | ||
import attr | ||
except ImportError: | ||
self.skipTest("Cannot import attr") | ||
|
||
@attr.s | ||
class TestItem: | ||
foo = attr.ib() | ||
|
||
self._test_item(TestItem(foo='bar')) | ||
|
||
def test_dataclass(self): | ||
try: | ||
from dataclasses import dataclass | ||
except ImportError: | ||
self.skipTest("Cannot import dataclasses.dataclass") | ||
|
||
@dataclass | ||
class TestItem: | ||
foo: str | ||
|
||
self._test_item(TestItem(foo='bar')) | ||
|
||
def test_dict(self): | ||
self._test_item({'foo': 'bar'}) | ||
|
||
def test_scrapy_item(self): | ||
try: | ||
from scrapy import Field, Item | ||
except ImportError: | ||
self.skipTest("Cannot import Field or Item from scrapy") | ||
|
||
class TestItem(Item): | ||
foo = Field() | ||
|
||
self._test_item(TestItem(foo='bar')) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters