@@ -94,31 +94,31 @@ def verify_bad_module(self, module_name):
9494
9595 def test_exec_valid_coding (self ):
9696 d = {}
97- exec ('# coding: cp949\n a = 5 \n ' , d )
98- self .assertEqual (d ['a' ], 5 )
97+ exec (b '# coding: cp949\n a = " \xaa \xa7 " \n ' , d )
98+ self .assertEqual (d ['a' ], ' \u3047 ' )
9999
100100 def test_file_parse (self ):
101101 # issue1134: all encodings outside latin-1 and utf-8 fail on
102102 # multiline strings and long lines (>512 columns)
103103 unload (TESTFN )
104- sys .path .insert (0 , os .curdir )
105104 filename = TESTFN + ".py"
106- f = open (filename , "w" )
105+ f = open (filename , "w" , encoding = "cp1252" )
106+ sys .path .insert (0 , os .curdir )
107107 try :
108- f . write ( "# -*- coding: cp1252 -*- \n " )
109- f .write ("'''A short string \n " )
110- f .write ("'''\n " )
111- f .write ("'A very long string %s' \n " % ( "X" * 1000 ) )
112- f . close ( )
108+ with f :
109+ f .write ("# -*- coding: cp1252 -*- \n " )
110+ f .write ("'''A short string \n " )
111+ f .write ("''' \n " )
112+ f . write ( "'A very long string %s' \n " % ( "X" * 1000 ) )
113113
114114 importlib .invalidate_caches ()
115115 __import__ (TESTFN )
116116 finally :
117- f . close ()
117+ del sys . path [ 0 ]
118118 unlink (filename )
119119 unlink (filename + "c" )
120+ unlink (filename + "o" )
120121 unload (TESTFN )
121- del sys .path [0 ]
122122
123123 def test_error_from_string (self ):
124124 # See http://bugs.python.org/issue6289
@@ -127,7 +127,8 @@ def test_error_from_string(self):
127127 compile (input , "<string>" , "exec" )
128128 expected = "'ascii' codec can't decode byte 0xe2 in position 16: " \
129129 "ordinal not in range(128)"
130- self .assertTrue (c .exception .args [0 ].startswith (expected ))
130+ self .assertTrue (c .exception .args [0 ].startswith (expected ),
131+ msg = c .exception .args [0 ])
131132
132133
133134if __name__ == "__main__" :
0 commit comments