]> granicus.if.org Git - python/commitdiff
Stop trying to write into the stdlib during lib2to3 tests (#12331).
authorÉric Araujo <merwok@netwok.org>
Sun, 31 Jul 2011 15:58:46 +0000 (17:58 +0200)
committerÉric Araujo <merwok@netwok.org>
Sun, 31 Jul 2011 15:58:46 +0000 (17:58 +0200)
This prevents tests from failing when run from a Python installed in a
read-only directory.

Lib/lib2to3/tests/test_refactor.py
Misc/NEWS

index 73122d87b451d1887aa74320a88e22c2938662c4..54edeb413e10f9b0dca42c454d1cea6e15dbc3fb 100644 (file)
@@ -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):
index aab5e1ad7139fc72342be7287917c30087e50ce5..e1060f6e41c11a00d33591785d08de17700b7b9c 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -140,6 +140,9 @@ Tools/Demos
 Tests
 -----
 
+- Issue #12331: The test suite for lib2to3 can now run from an installed
+  Python.
+
 - Issue #12626: In regrtest, allow to filter tests using a glob filter
   with the ``-m`` (or ``--match``) option.  This works with all test cases
   using the unittest module.  This is useful with long test suites