mirror of https://github.com/scrapy/scrapy.git
updated JsonLinesItemExporter to new exporters API
This commit is contained in:
parent
3152e66fec
commit
6b7162f3ca
|
|
@ -12,6 +12,8 @@ class JsonLinesItemExporter(BaseItemExporter):
|
|||
self.file = file
|
||||
self.encoder = json.JSONEncoder(*args, **kwargs)
|
||||
|
||||
def export(self, item):
|
||||
itemdict = dict(self._get_fields_to_export(item))
|
||||
def export_item(self, item):
|
||||
itemdict = {}
|
||||
for field, value in self._get_fields_to_export(item):
|
||||
itemdict[field] = self.serialize(item.fields[field], field, value)
|
||||
self.file.write(self.encoder.encode(itemdict) + '\n')
|
||||
|
|
|
|||
|
|
@ -134,7 +134,7 @@ class XmlItemExporterTest(BaseTest):
|
|||
self.assertEqual(self.output.getvalue(), expected_value)
|
||||
|
||||
|
||||
class JSONItemExporterTest(BaseTest):
|
||||
class JsonLinesItemExporterTest(BaseTest):
|
||||
|
||||
def setUp(self):
|
||||
try:
|
||||
|
|
@ -145,18 +145,17 @@ class JSONItemExporterTest(BaseTest):
|
|||
except ImportError:
|
||||
raise unittest.SkipTest("simplejson module not available")
|
||||
|
||||
from scrapy.contrib.exporter.jsonlines import JsonLinesItemExporter
|
||||
|
||||
super(JSONItemExporterTest, self).__init__()
|
||||
super(JsonLinesItemExporterTest, self).setUp()
|
||||
|
||||
def test_export(self):
|
||||
from scrapy.contrib.exporter.jsonlines import JsonLinesItemExporter
|
||||
|
||||
ie = JsonLinesItemExporter(output)
|
||||
ie = JsonLinesItemExporter(self.output)
|
||||
ie.start_exporting()
|
||||
ie.export_item(self.i)
|
||||
ie.finish_exporting()
|
||||
|
||||
self.assertEqual(output.getvalue(), '{"age": "22", "name": "John"}\n')
|
||||
self.assertEqual(self.output.getvalue(), '{"age": "22", "name": "John"}\n')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
|
|
|||
Loading…
Reference in New Issue