summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2010-05-21 21:16:12 (GMT)
committerBenjamin Peterson <benjamin@python.org>2010-05-21 21:16:12 (GMT)
commit6722ac2f00a51a33624e547e591fc2c81907acb1 (patch)
tree634167b321e8673f7ddd75a10292d7eb0a0ba581 /Lib/test
parent233eb540511c1ad8ebd3dbc6fa98b4db9ad56ae0 (diff)
downloadcpython-6722ac2f00a51a33624e547e591fc2c81907acb1.zip
cpython-6722ac2f00a51a33624e547e591fc2c81907acb1.tar.gz
cpython-6722ac2f00a51a33624e547e591fc2c81907acb1.tar.bz2
use addCleanup
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_linecache.py57
1 files changed, 27 insertions, 30 deletions
diff --git a/Lib/test/test_linecache.py b/Lib/test/test_linecache.py
index 613c7b4..6b6eb15 100644
--- a/Lib/test/test_linecache.py
+++ b/Lib/test/test_linecache.py
@@ -81,39 +81,36 @@ class LineCacheTests(unittest.TestCase):
def test_checkcache(self):
getline = linecache.getline
- try:
- # Create a source file and cache its contents
- source_name = support.TESTFN + '.py'
- with open(source_name, 'w') as source:
- source.write(SOURCE_1)
- getline(source_name, 1)
-
- # 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)
-
- with open(source_name, 'w') as source:
- source.write(SOURCE_2)
-
- # 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):
+ # Create a source file and cache its contents
+ source_name = support.TESTFN + '.py'
+ self.addCleanup(test_support.unlink, source_name)
+ with open(source_name, 'w') as source:
+ source.write(SOURCE_1)
+ getline(source_name, 1)
+
+ # 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)
- # 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)
+ with open(source_name, 'w') as source:
+ source.write(SOURCE_2)
- 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)
+ with open(source_name) as source:
+ for index, line in enumerate(source):
+ self.assertEquals(line, getline(source_name, index + 1))
+ source_list.append(line)
def test_main():
support.run_unittest(LineCacheTests)