[Python-checkins] r80195 - in python/branches/py3k: Lib/test/test_linecache.py

antoine.pitrou python-checkins at python.org
Sun Apr 18 21:17:01 CEST 2010


Author: antoine.pitrou
Date: Sun Apr 18 21:17:01 2010
New Revision: 80195

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

........
  r80194 | antoine.pitrou | 2010-04-18 21:14:38 +0200 (dim., 18 avril 2010) | 3 lines
  
  Fix catastrophic file opening and closing logic in test_linecache
........


Modified:
   python/branches/py3k/   (props changed)
   python/branches/py3k/Lib/test/test_linecache.py

Modified: python/branches/py3k/Lib/test/test_linecache.py
==============================================================================
--- python/branches/py3k/Lib/test/test_linecache.py	(original)
+++ python/branches/py3k/Lib/test/test_linecache.py	Sun Apr 18 21:17:01 2010
@@ -86,31 +86,28 @@
             source_name = support.TESTFN + '.py'
             with open(source_name, 'w') as source:
                 source.write(SOURCE_1)
-                source.close()
-                getline(source_name, 1)
+            getline(source_name, 1)
 
-                # Keep a copy of the old contents
-                source_list = []
-                source = open(source_name)
+            # Keep a copy of the old contents
+            source_list = []
+            with open(source_name) as source:
                 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')
+            with open(source_name, 'w') as source:
                 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))
+            # Try to update a bogus cache entry
+            linecache.checkcache('dummy')
 
-                # Update the cache and check whether it matches the new source file
-                linecache.checkcache(source_name)
-                source = open(source_name)
+            # 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)
+            with open(source_name) as source:
                 for index, line in enumerate(source):
                     self.assertEquals(line, getline(source_name, index + 1))
                     source_list.append(line)


More information about the Python-checkins mailing list