File tree 1 file changed +23
-0
lines changed 1 file changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -4222,6 +4222,29 @@ def test_check_encoding_errors(self):
4222
4222
proc = assert_python_failure ('-X' , 'dev' , '-c' , code )
4223
4223
self .assertEqual (proc .rc , 10 , proc )
4224
4224
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
+
4225
4248
4226
4249
class CMiscIOTest (MiscIOTest ):
4227
4250
io = io
You can’t perform that action at this time.
0 commit comments