mirror of https://github.com/scrapy/scrapy.git
Do not fail on when json exporter are instanciated with extra keywords. closes #379
This commit is contained in:
parent
92d14d4a03
commit
2be3f7132a
|
|
@ -79,7 +79,7 @@ class BaseItemExporter(object):
|
|||
class JsonLinesItemExporter(BaseItemExporter):
|
||||
|
||||
def __init__(self, file, **kwargs):
|
||||
self._configure(kwargs)
|
||||
self._configure(kwargs, dont_fail=True)
|
||||
self.file = file
|
||||
self.encoder = ScrapyJSONEncoder(**kwargs)
|
||||
|
||||
|
|
@ -91,7 +91,7 @@ class JsonLinesItemExporter(BaseItemExporter):
|
|||
class JsonItemExporter(JsonLinesItemExporter):
|
||||
|
||||
def __init__(self, file, **kwargs):
|
||||
self._configure(kwargs)
|
||||
self._configure(kwargs, dont_fail=True)
|
||||
self.file = file
|
||||
self.encoder = ScrapyJSONEncoder(**kwargs)
|
||||
self.first_item = True
|
||||
|
|
@ -248,6 +248,6 @@ class PythonItemExporter(BaseItemExporter):
|
|||
def _serialize_dict(self, value):
|
||||
for key, val in value.iteritems():
|
||||
yield key, self._serialize_value(val)
|
||||
|
||||
|
||||
def export_item(self, item):
|
||||
return dict(self._get_serialized_fields(item))
|
||||
|
|
|
|||
|
|
@ -103,7 +103,7 @@ class PythonItemExporterTest(BaseItemExporterTest):
|
|||
self.assertEqual(exported, {'age': [{'age': [{'age': '22', 'name': u'Joseph'}], 'name': u'Maria'}], 'name': 'Jesus'})
|
||||
self.assertEqual(type(exported['age'][0]), dict)
|
||||
self.assertEqual(type(exported['age'][0]['age'][0]), dict)
|
||||
|
||||
|
||||
class PprintItemExporterTest(BaseItemExporterTest):
|
||||
|
||||
def _get_exporter(self, **kwargs):
|
||||
|
|
@ -266,6 +266,13 @@ class JsonLinesItemExporterTest(BaseItemExporterTest):
|
|||
exported = json.loads(self.output.getvalue())
|
||||
self.assertEqual(exported, self._expected_nested)
|
||||
|
||||
def test_extra_keywords(self):
|
||||
self.ie = self._get_exporter(sort_keys=True)
|
||||
self.test_export_item()
|
||||
self._check_output()
|
||||
self.assertRaises(TypeError, self._get_exporter, foo_unknown_keyword_bar=True)
|
||||
|
||||
|
||||
class JsonItemExporterTest(JsonLinesItemExporterTest):
|
||||
|
||||
_expected_nested = [JsonLinesItemExporterTest._expected_nested]
|
||||
|
|
|
|||
Loading…
Reference in New Issue