@@ -177,22 +177,26 @@ def print_output(self, old_text, new_text, filename, equal):
177177 self .assertEqual (results , expected )
178178
179179 def check_file_refactoring (self , test_file , fixers = _2TO3_FIXERS ):
180+ tmpdir = tempfile .mkdtemp (prefix = "2to3-test_refactor" )
181+ self .addCleanup (shutil .rmtree , tmpdir )
182+ # make a copy of the tested file that we can write to
183+ shutil .copy (test_file , tmpdir )
184+ test_file = os .path .join (tmpdir , os .path .basename (test_file ))
185+ os .chmod (test_file , 0o644 )
186+
180187 def read_file ():
181188 with open (test_file , "rb" ) as fp :
182189 return fp .read ()
190+
183191 old_contents = read_file ()
184192 rt = self .rt (fixers = fixers )
185193
186194 rt .refactor_file (test_file )
187195 self .assertEqual (old_contents , read_file ())
188196
189- try :
190- rt .refactor_file (test_file , True )
191- new_contents = read_file ()
192- self .assertNotEqual (old_contents , new_contents )
193- finally :
194- with open (test_file , "wb" ) as fp :
195- fp .write (old_contents )
197+ rt .refactor_file (test_file , True )
198+ new_contents = read_file ()
199+ self .assertNotEqual (old_contents , new_contents )
196200 return new_contents
197201
198202 def test_refactor_file (self ):
0 commit comments