Skip to content
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

Make close method idempotent + add dummy flush method for S3 #212

Merged
merged 27 commits into from
Aug 13, 2018
Merged

Make close method idempotent + add dummy flush method for S3 #212

merged 27 commits into from
Aug 13, 2018

Conversation

mpenkov
Copy link
Collaborator

@mpenkov mpenkov commented Aug 5, 2018

According to the python docs, the close method should have no effect if the file is already closed.

Also, we need to expose a flush method in order to quack like a built-in file object.

There are many commits in this branch, most of them are just back-and-forth between me and the reporting user. It took us a long time to understand what the problem actually was.

fout.close()
fout.close()

def test_flush_close(self):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's an idea of this test?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test_flush_close checks if we have a flush method.

test_double_close checks that calling close twice doesn't cause a crash.

Both of these tests were written as part of TDD. They capture the problematic behavior of smart open before the corresponding changes to s3 were made.

smart_open/s3.py Outdated
@@ -472,6 +473,14 @@ def __exit__(self, exc_type, exc_val, exc_tb):
self.close()


def _insert_spaces(the_string):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's a function _insert_spaces (here and below)? I see no usages.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Used for debugging only. Deleted.

import smart_open

s3_url, local_path = sys.argv[1:]
with smart_open.smart_open(s3_url, 'rb') as fin, open(local_path, 'wb') as fout:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

description needed: I see copy s3 -> local disk, what you test here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an analog of the "aws s3 cp" command. I used it for debugging only, so I deleted it.

@menshikh-iv menshikh-iv changed the title Make close method idempotent, add dummy flush method Make close method idempotent + add dummy flush method for S3 Aug 13, 2018
@menshikh-iv
Copy link
Contributor

Thank you @mpenkov 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants