-
-
Notifications
You must be signed in to change notification settings - Fork 30k
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
bpo-32236: Issue RuntimeWarning if buffering=1 for open() in binary mode #4842
Changes from all commits
2b0a0d8
888ee4d
0deefe1
42a43c1
164470a
54c12b2
3fe49c4
aff54cf
cec8cd7
64dfd42
2538bde
250adb4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -164,22 +164,33 @@ def testBadModeArgument(self): | |
f.close() | ||
self.fail("no error for invalid mode: %s" % bad_mode) | ||
|
||
def _checkBufferSize(self, s): | ||
try: | ||
f = self.open(TESTFN, 'wb', s) | ||
f.write(str(s).encode("ascii")) | ||
f.close() | ||
f.close() | ||
f = self.open(TESTFN, 'rb', s) | ||
d = int(f.read().decode("ascii")) | ||
f.close() | ||
f.close() | ||
except OSError as msg: | ||
self.fail('error setting buffer size %d: %s' % (s, str(msg))) | ||
self.assertEqual(d, s) | ||
|
||
def testSetBufferSize(self): | ||
# make sure that explicitly setting the buffer size doesn't cause | ||
# misbehaviour especially with repeated close() calls | ||
for s in (-1, 0, 1, 512): | ||
try: | ||
f = self.open(TESTFN, 'wb', s) | ||
f.write(str(s).encode("ascii")) | ||
f.close() | ||
f.close() | ||
f = self.open(TESTFN, 'rb', s) | ||
d = int(f.read().decode("ascii")) | ||
f.close() | ||
f.close() | ||
except OSError as msg: | ||
self.fail('error setting buffer size %d: %s' % (s, str(msg))) | ||
self.assertEqual(d, s) | ||
for s in (-1, 0, 512): | ||
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. Would it be possible to check that these calls don't emit RuntimeWarning? 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. I've added the check. |
||
with support.check_no_warnings(self, | ||
message='line buffering', | ||
category=RuntimeWarning): | ||
self._checkBufferSize(s) | ||
|
||
# test that attempts to use line buffering in binary mode cause | ||
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. No need to test this both here and in 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. OK, I've preserved only one check here. I think that |
||
# a warning | ||
with self.assertWarnsRegex(RuntimeWarning, 'line buffering'): | ||
self._checkBufferSize(1) | ||
|
||
def testTruncateOnWindows(self): | ||
# SF bug <http://www.python.org/sf/801631> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Warn that line buffering is not supported if :func:`open` is called with | ||
binary mode and ``buffering=1``. | ||
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. I would prefer to be more explicit and list more impact functions: open, io.open, codecs.open. Would it be possible to put functions first in the sentence? Something like: "open(), io.open(), codecs.open() now emit a warning if the file is opened in binary mode with buffering=1." So the reader directly gets the context. 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. Some other functions are impacted too, like |
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.
what's the point of calling close() twice here? with should be used, no?
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.
This is just a refactor of an existing test.