-
-
Notifications
You must be signed in to change notification settings - Fork 32.3k
bpo-33563: Fileinput(bufsize=0) does not emit deprecation warning. #6959
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
Changes from all commits
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 |
---|---|---|
|
@@ -83,12 +83,13 @@ def close(self): | |
class BufferSizesTests(BaseTests, unittest.TestCase): | ||
def test_buffer_sizes(self): | ||
# First, run the tests with default and teeny buffer size. | ||
for round, bs in (0, 0), (1, 30): | ||
from fileinput import _sentinel | ||
for round, bs in (0, 0), (1, 30), (2, _sentinel): | ||
t1 = self.writeTmp(''.join("Line %s of file 1\n" % (i+1) for i in range(15))) | ||
t2 = self.writeTmp(''.join("Line %s of file 2\n" % (i+1) for i in range(10))) | ||
t3 = self.writeTmp(''.join("Line %s of file 3\n" % (i+1) for i in range(5))) | ||
t4 = self.writeTmp(''.join("Line %s of file 4\n" % (i+1) for i in range(1))) | ||
if bs: | ||
if bs is not _sentinel: | ||
with self.assertWarns(DeprecationWarning): | ||
self.buffer_size_test(t1, t2, t3, t4, bs, round) | ||
else: | ||
|
@@ -646,9 +647,10 @@ def do_test_call_input(self): | |
openhook = object() | ||
|
||
# call fileinput.input() with different values for each argument | ||
result = fileinput.input(files=files, inplace=inplace, backup=backup, | ||
bufsize=bufsize, | ||
mode=mode, openhook=openhook) | ||
with self.assertWarns(DeprecationWarning): | ||
result = fileinput.input(files=files, inplace=inplace, backup=backup, | ||
bufsize=bufsize, | ||
mode=mode, openhook=openhook) | ||
|
||
# ensure fileinput._state was set to the returned object | ||
self.assertIs(result, fileinput._state, "fileinput._state") | ||
|
@@ -658,10 +660,13 @@ def do_test_call_input(self): | |
self.assertIs(files, result.files, "files") | ||
self.assertIs(inplace, result.inplace, "inplace") | ||
self.assertIs(backup, result.backup, "backup") | ||
self.assertIs(bufsize, result.bufsize, "bufsize") | ||
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. Please restore this assertion. 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 is testing the Mock, the MockFileInput have a bufsize attribute, the rel FileInput does not. The goal of this test is to explicitly test that |
||
self.assertIs(mode, result.mode, "mode") | ||
self.assertIs(openhook, result.openhook, "openhook") | ||
|
||
# FileInput(bufsize=..) is deprecated, check that fileinut.input will | ||
# _not_ its value to the MockFileInput | ||
self.assertIsNot(bufsize, result.bufsize, "bufsize") | ||
|
||
class Test_fileinput_close(BaseFileInputGlobalMethodsTest): | ||
"""Unit tests for fileinput.close()""" | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Improve fileinput's DeprecationWarning and emit them when bufsize=0 is | ||
passed. |
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.
The tests will be not ran with non-default buffer size. Please restore tests.
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.
Ok, but that is useless as
bufsize=
is anyway ignored. That is basically running the same exact test twice...