Scrapy, a fast high-level web crawling & scraping framework for Python.
Test the life cycle of a storage file
Adrián Chavesd599fff2b97f
diff --git a/tests/test_feedexport.py b/tests/test_feedexport.pyindex ecd1b59d3..a5fd1e467 100644--- a/tests/test_feedexport.py+++ b/tests/test_feedexport.py@@ -1517,6 +1517,61 @@ class FeedExportTest(FeedExportTestBase):data = yield self.exported_data(items, settings)self.assertEqual(row['expected'], data[feed_options['format']])+ @defer.inlineCallbacks+ def test_storage_file_no_postprocessing(self):++ @implementer(IFeedStorage)+ class Storage:++ def __init__(self, uri, *, feed_options=None):+ pass++ def open(self, spider):+ Storage.open_file = tempfile.NamedTemporaryFile(prefix='feed-')+ return Storage.open_file++ def store(self, file):+ Storage.store_file = file+ file.close()++ settings = {+ 'FEEDS': {self._random_temp_filename(): {'format': 'jsonlines'}},+ 'FEED_STORAGES': {'file': Storage},+ }+ yield self.exported_no_data(settings)+ self.assertIs(Storage.open_file, Storage.store_file)++ @defer.inlineCallbacks+ def test_storage_file_postprocessing(self):++ @implementer(IFeedStorage)+ class Storage:++ def __init__(self, uri, *, feed_options=None):+ pass++ def open(self, spider):+ Storage.open_file = tempfile.NamedTemporaryFile(prefix='feed-')+ return Storage.open_file++ def store(self, file):+ Storage.store_file = file+ file.close()++ settings = {+ 'FEEDS': {+ self._random_temp_filename(): {+ 'format': 'jsonlines',+ 'postprocessing': [+ 'scrapy.extensions.postprocessing.GzipPlugin',+ ],+ },+ },+ 'FEED_STORAGES': {'file': Storage},+ }+ yield self.exported_no_data(settings)+ self.assertIs(Storage.open_file, Storage.store_file)+class FeedPostProcessedExportsTest(FeedExportTestBase):__test__ = True