diff options
author | Éric Araujo <merwok@netwok.org> | 2011-07-31 16:33:00 (GMT) |
---|---|---|
committer | Éric Araujo <merwok@netwok.org> | 2011-07-31 16:33:00 (GMT) |
commit | ad548b8534645ebb7590eb557c04d86814bde203 (patch) | |
tree | 054e0527512d7c6fcd59283d0a26a2b2173ef0ee /Lib/lib2to3 | |
parent | 052c83cf058c0511810d96253d0d4c391d11be0a (diff) | |
parent | 548c054fb70c504150ec8bafa4503d6b4e74e535 (diff) | |
download | cpython-ad548b8534645ebb7590eb557c04d86814bde203.zip cpython-ad548b8534645ebb7590eb557c04d86814bde203.tar.gz cpython-ad548b8534645ebb7590eb557c04d86814bde203.tar.bz2 |
Merge fixes for #9860, #11104/#8688 and #12331 from 3.2
Diffstat (limited to 'Lib/lib2to3')
-rw-r--r-- | Lib/lib2to3/tests/test_refactor.py | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/Lib/lib2to3/tests/test_refactor.py b/Lib/lib2to3/tests/test_refactor.py index 73122d8..54edeb4 100644 --- a/Lib/lib2to3/tests/test_refactor.py +++ b/Lib/lib2to3/tests/test_refactor.py @@ -177,22 +177,26 @@ from __future__ import print_function""" self.assertEqual(results, expected) def check_file_refactoring(self, test_file, fixers=_2TO3_FIXERS): + tmpdir = tempfile.mkdtemp(prefix="2to3-test_refactor") + self.addCleanup(shutil.rmtree, tmpdir) + # make a copy of the tested file that we can write to + shutil.copy(test_file, tmpdir) + test_file = os.path.join(tmpdir, os.path.basename(test_file)) + os.chmod(test_file, 0o644) + def read_file(): with open(test_file, "rb") as fp: return fp.read() + old_contents = read_file() rt = self.rt(fixers=fixers) rt.refactor_file(test_file) self.assertEqual(old_contents, read_file()) - try: - rt.refactor_file(test_file, True) - new_contents = read_file() - self.assertNotEqual(old_contents, new_contents) - finally: - with open(test_file, "wb") as fp: - fp.write(old_contents) + rt.refactor_file(test_file, True) + new_contents = read_file() + self.assertNotEqual(old_contents, new_contents) return new_contents def test_refactor_file(self): |