diff options
author | R. David Murray <rdmurray@bitdance.com> | 2009-12-03 23:57:59 (GMT) |
---|---|---|
committer | R. David Murray <rdmurray@bitdance.com> | 2009-12-03 23:57:59 (GMT) |
commit | 820b0ea36c9f2ad2c940f157fb69c045c6a0ad96 (patch) | |
tree | 25aeb8180ee5a60e034cd211ab0f4ccc35f2184e /Lib | |
parent | 642017224a3167d826fe490648a5d567e52c969d (diff) | |
download | cpython-820b0ea36c9f2ad2c940f157fb69c045c6a0ad96.zip cpython-820b0ea36c9f2ad2c940f157fb69c045c6a0ad96.tar.gz cpython-820b0ea36c9f2ad2c940f157fb69c045c6a0ad96.tar.bz2 |
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.
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_linecache.py | 68 |
1 files changed, 32 insertions, 36 deletions
diff --git a/Lib/test/test_linecache.py b/Lib/test/test_linecache.py index be73962..4ec9eb4 100644 --- a/Lib/test/test_linecache.py +++ b/Lib/test/test_linecache.py @@ -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) |