diff options
author | Éric Araujo <merwok@netwok.org> | 2011-07-31 15:59:28 (GMT) |
---|---|---|
committer | Éric Araujo <merwok@netwok.org> | 2011-07-31 15:59:28 (GMT) |
commit | 498da2c16252686caa6a9a556def015ed8ed230e (patch) | |
tree | 7950266622f2f4a28b619e3362fabdbf45888c05 /Lib/lib2to3/tests | |
parent | 560bf855d3788c31273162f0ccf777b3c1eedaa8 (diff) | |
download | cpython-498da2c16252686caa6a9a556def015ed8ed230e.zip cpython-498da2c16252686caa6a9a556def015ed8ed230e.tar.gz cpython-498da2c16252686caa6a9a556def015ed8ed230e.tar.bz2 |
Stop trying to write into the stdlib during lib2to3 tests (#12331).
This prevents tests from failing when run from a Python installed in a
read-only directory.
Diffstat (limited to 'Lib/lib2to3/tests')
-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 3eecde8..9773fc9 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): |