summaryrefslogtreecommitdiff
path: root/Lib/test/test_linecache.py
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2010-04-18 19:14:38 +0000
committerAntoine Pitrou <solipsis@pitrou.net>2010-04-18 19:14:38 +0000
commit9958c56eb0e2b71c1bea5abcc627899d0bed17dc (patch)
tree48a69fad65c1d595e6585c4433839394a339eab6 /Lib/test/test_linecache.py
parent814b6c222dfbff0a9ea7d96b493c565e9b3beb24 (diff)
downloadcpython-git-9958c56eb0e2b71c1bea5abcc627899d0bed17dc.tar.gz
Fix catastrophic file opening and closing logic in test_linecache
Diffstat (limited to 'Lib/test/test_linecache.py')
-rw-r--r--Lib/test/test_linecache.py29
1 files changed, 13 insertions, 16 deletions
diff --git a/Lib/test/test_linecache.py b/Lib/test/test_linecache.py
index 4ec9eb4fa2..613c7b4e00 100644
--- a/Lib/test/test_linecache.py
+++ b/Lib/test/test_linecache.py
@@ -86,31 +86,28 @@ class LineCacheTests(unittest.TestCase):
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')
+ # 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))
+ # 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)
+ # 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)