mirror of
https://github.com/scrapy/scrapy.git
synced 2025-02-25 12:24:19 +00:00
moved scrapy.newitem.exporters to scrapy.contrib.exporter
--HG-- rename : scrapy/newitem/exporters/__init__.py => scrapy/contrib/exporter/__init__.py rename : scrapy/newitem/exporters/jsonexporter.py => scrapy/contrib/exporter/jsonexporter.py rename : scrapy/tests/test_itemexporters.py => scrapy/tests/test_contrib_exporter.py
This commit is contained in:
parent
c99e572fdb
commit
f0aea4aa4a
@ -1,11 +1,11 @@
|
||||
from scrapy.newitem.exporters import BaseItemExporter
|
||||
from scrapy.contrib.exporter import BaseItemExporter
|
||||
from scrapy.utils.serialization import serialize
|
||||
|
||||
|
||||
class JSONItemExporter(BaseItemExporter):
|
||||
|
||||
def __init__(self, file):
|
||||
super(BaseItemExporter, self).__init__()
|
||||
super(JSONItemExporter, self).__init__()
|
||||
self.file = file
|
||||
|
||||
def export(self, item):
|
@ -1,10 +1,11 @@
|
||||
from cPickle import Pickler
|
||||
from cStringIO import StringIO
|
||||
import pprint
|
||||
|
||||
from twisted.trial import unittest
|
||||
|
||||
from scrapy.newitem import Item, Field
|
||||
from scrapy.newitem.exporters import *
|
||||
from scrapy.contrib.exporter import BaseItemExporter, PprintItemExporter, \
|
||||
PickleItemExporter, CsvItemExporter, XmlItemExporter
|
||||
|
||||
class TestItem(Item):
|
||||
name = Field()
|
||||
@ -115,17 +116,20 @@ class JSONItemExporterTest(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
try:
|
||||
from scrapy.newitem.exporters.jsonexporter import JSONItemExporter
|
||||
self.output = StringIO()
|
||||
self.ie = JSONItemExporter(self.output)
|
||||
|
||||
except ImportError, e:
|
||||
raise unittest.SkipTest("Json library not available")
|
||||
import json
|
||||
except ImportError:
|
||||
try:
|
||||
import simplejson
|
||||
except ImportError:
|
||||
raise unittest.SkipTest("simplejson module not available")
|
||||
|
||||
def test_export(self):
|
||||
from scrapy.contrib.exporter.jsonexporter import JSONItemExporter
|
||||
|
||||
output = StringIO()
|
||||
ie = JSONItemExporter(output)
|
||||
i = TestItem(name=u'John', age=22)
|
||||
ie.export(i)
|
||||
|
||||
self.ie.export(i)
|
||||
|
||||
self.assertEqual(self.output.getvalue(), '{"age": 22, "name": "John"}\n')
|
||||
self.assertEqual(output.getvalue(), '{"age": 22, "name": "John"}\n')
|
||||
|
Loading…
x
Reference in New Issue
Block a user