55import pdb
66import sys
77import types
8+ import codecs
89import unittest
910import subprocess
1011import textwrap
@@ -1226,9 +1227,7 @@ def run_pdb_module(self, script, commands):
12261227 return self ._run_pdb (['-m' , self .module_name ], commands )
12271228
12281229 def _assert_find_function (self , file_content , func_name , expected ):
1229- file_content = textwrap .dedent (file_content )
1230-
1231- with open (support .TESTFN , 'w' ) as f :
1230+ with open (support .TESTFN , 'wb' ) as f :
12321231 f .write (file_content )
12331232
12341233 expected = None if not expected else (
@@ -1237,22 +1236,49 @@ def _assert_find_function(self, file_content, func_name, expected):
12371236 expected , pdb .find_function (func_name , support .TESTFN ))
12381237
12391238 def test_find_function_empty_file (self ):
1240- self ._assert_find_function ('' , 'foo' , None )
1239+ self ._assert_find_function (b '' , 'foo' , None )
12411240
12421241 def test_find_function_found (self ):
12431242 self ._assert_find_function (
12441243 """\
1245- def foo():
1246- pass
1244+ def foo():
1245+ pass
12471246
1248- def bar ():
1249- pass
1247+ def bœr ():
1248+ pass
12501249
1251- def quux():
1252- pass
1253- """ ,
1254- 'bar' ,
1255- ('bar' , 4 ),
1250+ def quux():
1251+ pass
1252+ """ .encode (),
1253+ 'bœr' ,
1254+ ('bœr' , 4 ),
1255+ )
1256+
1257+ def test_find_function_found_with_encoding_cookie (self ):
1258+ self ._assert_find_function (
1259+ """\
1260+ # coding: iso-8859-15
1261+ def foo():
1262+ pass
1263+
1264+ def bœr():
1265+ pass
1266+
1267+ def quux():
1268+ pass
1269+ """ .encode ('iso-8859-15' ),
1270+ 'bœr' ,
1271+ ('bœr' , 5 ),
1272+ )
1273+
1274+ def test_find_function_found_with_bom (self ):
1275+ self ._assert_find_function (
1276+ codecs .BOM_UTF8 + """\
1277+ def bœr():
1278+ pass
1279+ """ .encode (),
1280+ 'bœr' ,
1281+ ('bœr' , 1 ),
12561282 )
12571283
12581284 def test_issue7964 (self ):
0 commit comments