Skip to content

Commit 050bd1b

Browse files
committed
add test
1 parent a3c014b commit 050bd1b

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

Lib/test/test_io.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4222,6 +4222,29 @@ def test_check_encoding_errors(self):
42224222
proc = assert_python_failure('-X', 'dev', '-c', code)
42234223
self.assertEqual(proc.rc, 10, proc)
42244224

4225+
def test_check_encoding_warning(self):
4226+
# PEP 597: Raise warning when encoding is not specified
4227+
# and dev mode is enabled.
4228+
mod = self.io.__name__
4229+
filename = __file__
4230+
code = textwrap.dedent(f'''\
4231+
import sys
4232+
from {mod} import open, TextIOWrapper
4233+
import pathlib
4234+
4235+
with open({filename!r}) as f: # line 5
4236+
pass
4237+
4238+
pathlib.Path({filename!r}).read_text() # line 8
4239+
''')
4240+
proc = assert_python_ok('-X', 'dev', '-c', code)
4241+
warnings = proc.err.splitlines()
4242+
self.assertEqual(len(warnings), 2)
4243+
self.assertTrue(
4244+
warnings[0].startswith(b"<string>:5: DeprecationWarning: "))
4245+
self.assertTrue(
4246+
warnings[1].startswith(b"<string>:8: DeprecationWarning: "))
4247+
42254248

42264249
class CMiscIOTest(MiscIOTest):
42274250
io = io

0 commit comments

Comments
 (0)