New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added --overwrite-output (-O) option #716
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,38 +12,58 @@ | |
|
||
class FileFeedStorageTest(unittest.TestCase): | ||
|
||
settings = {"FEED_OVERWRITE": False} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be created inside |
||
|
||
def test_store_file_uri(self): | ||
path = os.path.abspath(self.mktemp()) | ||
uri = path_to_file_uri(path) | ||
return self._assert_stores(FileFeedStorage(uri), path) | ||
return self._assert_stores(FileFeedStorage(uri, self.settings), path) | ||
|
||
def test_store_file_uri_makedirs(self): | ||
path = os.path.abspath(self.mktemp()) | ||
path = os.path.join(path, 'more', 'paths', 'file.txt') | ||
uri = path_to_file_uri(path) | ||
return self._assert_stores(FileFeedStorage(uri), path) | ||
return self._assert_stores(FileFeedStorage(uri, self.settings), path) | ||
|
||
def test_store_direct_path(self): | ||
path = os.path.abspath(self.mktemp()) | ||
return self._assert_stores(FileFeedStorage(path), path) | ||
return self._assert_stores(FileFeedStorage(path, self.settings), path) | ||
|
||
def test_store_direct_path_relative(self): | ||
path = self.mktemp() | ||
return self._assert_stores(FileFeedStorage(path), path) | ||
return self._assert_stores(FileFeedStorage(path, self.settings), path) | ||
|
||
def test_interface(self): | ||
path = self.mktemp() | ||
st = FileFeedStorage(path) | ||
st = FileFeedStorage(path, self.settings) | ||
verifyObject(IFeedStorage, st) | ||
|
||
@defer.inlineCallbacks | ||
def _assert_stores(self, storage, path): | ||
def _store(self, path, settings, content="content"): | ||
storage = FileFeedStorage(path, settings) | ||
spider = Spider("default") | ||
file = storage.open(spider) | ||
file.write("content") | ||
storage.store(file) | ||
|
||
def test_append(self): | ||
path = os.path.abspath(self.mktemp()) | ||
self._store(path, self.settings) | ||
return self._assert_stores(FileFeedStorage(path, self.settings), path, verify="contentcontent") | ||
|
||
def test_overwrite(self): | ||
path = os.path.abspath(self.mktemp()) | ||
settings = {"FEED_OVERWRITE": True} | ||
self._store(path, settings) | ||
return self._assert_stores(FileFeedStorage(path, settings), path) | ||
|
||
@defer.inlineCallbacks | ||
def _assert_stores(self, storage, path, content="content", verify="content"): | ||
spider = Spider("default") | ||
file = storage.open(spider) | ||
file.write(content) | ||
yield storage.store(file) | ||
self.failUnless(os.path.exists(path)) | ||
self.failUnlessEqual(open(path).read(), "content") | ||
self.failUnlessEqual(open(path).read(), verify) | ||
|
||
|
||
class FTPFeedStorageTest(unittest.TestCase): | ||
|
@@ -53,7 +73,7 @@ def test_store(self): | |
path = os.environ.get('FEEDTEST_FTP_PATH') | ||
if not (uri and path): | ||
raise unittest.SkipTest("No FTP server available for testing") | ||
st = FTPFeedStorage(uri) | ||
st = FTPFeedStorage(uri, settings={}) | ||
verifyObject(IFeedStorage, st) | ||
return self._assert_stores(st, path) | ||
|
||
|
@@ -79,7 +99,7 @@ def test_store(self): | |
if not uri: | ||
raise unittest.SkipTest("No S3 URI available for testing") | ||
from boto import connect_s3 | ||
storage = S3FeedStorage(uri) | ||
storage = S3FeedStorage(uri, settings={}) | ||
verifyObject(IFeedStorage, storage) | ||
file = storage.open(Spider("default")) | ||
file.write("content") | ||
|
@@ -93,7 +113,7 @@ class StdoutFeedStorageTest(unittest.TestCase): | |
@defer.inlineCallbacks | ||
def test_store(self): | ||
out = StringIO() | ||
storage = StdoutFeedStorage('stdout:', _stdout=out) | ||
storage = StdoutFeedStorage('stdout:', settings={} ,_stdout=out) | ||
file = storage.open(Spider("default")) | ||
file.write("content") | ||
yield storage.store(file) | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think
settings.getbool('FEED_OVERWRITE', default=False)
fits better.