]> granicus.if.org Git - python/commitdiff
Merged revisions 76661 via svnmerge from
authorR. David Murray <rdmurray@bitdance.com>
Fri, 4 Dec 2009 00:13:33 +0000 (00:13 +0000)
committerR. David Murray <rdmurray@bitdance.com>
Fri, 4 Dec 2009 00:13:33 +0000 (00:13 +0000)
svn+ssh://pythondev@svn.python.org/python/branches/py3k

................
  r76661 | r.david.murray | 2009-12-03 19:09:14 -0500 (Thu, 03 Dec 2009) | 11 lines

  Merged revisions 76659 via svnmerge from
  svn+ssh://pythondev@svn.python.org/python/trunk

  ........
    r76659 | r.david.murray | 2009-12-03 18:57:59 -0500 (Thu, 03 Dec 2009) | 4 lines

    Issue 7431: use TESTFN in test_linecache instead of trying to create a
    file in the Lib/test directory, which might be read-only for the
    user running the tests.
  ........
................

Lib/test/test_linecache.py
Misc/NEWS

index 14d8d595d57a69dc984b5e2eda2901b0b1294452..4899511222a6b4cfbef814b3b263753c475c36ef 100644 (file)
@@ -83,44 +83,40 @@ class LineCacheTests(unittest.TestCase):
         getline = linecache.getline
         try:
             # Create a source file and cache its contents
-            source_name = os.path.join(TEST_PATH, 'linecache_test.py')
-            source = open(source_name, 'w')
-            source.write(SOURCE_1)
-            source.close()
-            getline(source_name, 1)
-
-            # Keep a copy of the old contents
-            source_list = []
-            source = open(source_name)
-            for index, line in enumerate(source):
-                self.assertEquals(line, getline(source_name, index + 1))
-                source_list.append(line)
-            source.close()
-
-            source = open(source_name, 'w')
-            source.write(SOURCE_2)
-            source.close()
-
-            # Try to update a bogus cache entry
-            linecache.checkcache('dummy')
-
-            # Check that the cache matches the old contents
-            for index, line in enumerate(source_list):
-                self.assertEquals(line, getline(source_name, index + 1))
-
-            # Update the cache and check whether it matches the new source file
-            linecache.checkcache(source_name)
-            source = open(source_name)
-            for index, line in enumerate(source):
-                self.assertEquals(line, getline(source_name, index + 1))
-                source_list.append(line)
-            source.close()
+            source_name = support.TESTFN + '.py'
+            with open(source_name, 'w') as source:
+                source.write(SOURCE_1)
+                source.close()
+                getline(source_name, 1)
+
+                # Keep a copy of the old contents
+                source_list = []
+                source = open(source_name)
+                for index, line in enumerate(source):
+                    self.assertEquals(line, getline(source_name, index + 1))
+                    source_list.append(line)
+                source.close()
 
-        finally:
-            try:
+                source = open(source_name, 'w')
+                source.write(SOURCE_2)
                 source.close()
-            finally:
-                support.unlink(source_name)
+
+                # Try to update a bogus cache entry
+                linecache.checkcache('dummy')
+
+                # Check that the cache matches the old contents
+                for index, line in enumerate(source_list):
+                    self.assertEquals(line, getline(source_name, index + 1))
+
+                # Update the cache and check whether it matches the new source file
+                linecache.checkcache(source_name)
+                source = open(source_name)
+                for index, line in enumerate(source):
+                    self.assertEquals(line, getline(source_name, index + 1))
+                    source_list.append(line)
+
+        finally:
+            support.unlink(source_name)
 
 def test_main():
     support.run_unittest(LineCacheTests)
index 095bd6e57a780c0d3393e98cce2b4df7b2ecec92..00a9add531844f7a4dbe247b85cb95b7a9908047 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -192,6 +192,10 @@ Extension Modules
 Tests
 -----
 
+- Issue #7431: use TESTFN in test_linecache instead of trying to create a 
+  file in the Lib/test directory, which might be read-only for the
+  user running the tests.
+
 - Issue #7324: add a sanity check to regrtest argument parsing to
   catch the case of an option with no handler.