Add test case for marshal item exporter

This commit is contained in:
Daniel Graña 2016-01-26 00:26:27 -03:00
parent 2dfdde3c79
commit d0eacfe0f9
2 changed files with 16 additions and 2 deletions

View File

@ -158,7 +158,7 @@ class XmlItemExporter(BaseItemExporter):
if not isinstance(serialized_value, six.text_type):
serialized_value = serialized_value.decode(self.encoding)
return self.xg.characters(serialized_value)
else:
else: # pragma: no cover
def _xg_characters(self, serialized_value):
return self.xg.characters(serialized_value)

View File

@ -1,6 +1,8 @@
from __future__ import absolute_import
import re
import json
import marshal
import tempfile
import unittest
from io import BytesIO
from six.moves import cPickle as pickle
@ -12,7 +14,8 @@ from scrapy.item import Item, Field
from scrapy.utils.python import to_unicode
from scrapy.exporters import (
BaseItemExporter, PprintItemExporter, PickleItemExporter, CsvItemExporter,
XmlItemExporter, JsonLinesItemExporter, JsonItemExporter, PythonItemExporter
XmlItemExporter, JsonLinesItemExporter, JsonItemExporter,
PythonItemExporter, MarshalItemExporter
)
@ -163,6 +166,17 @@ class PickleItemExporterTest(BaseItemExporterTest):
self.assertEqual(pickle.load(f), i2)
class MarshalItemExporterTest(BaseItemExporterTest):
def _get_exporter(self, **kwargs):
self.output = tempfile.TemporaryFile()
return MarshalItemExporter(self.output, **kwargs)
def _check_output(self):
self.output.seek(0)
self._assert_expected_item(marshal.load(self.output))
class CsvItemExporterTest(BaseItemExporterTest):
def _get_exporter(self, **kwargs):
return CsvItemExporter(self.output, **kwargs)