Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8054a5d

Browse files
committed
Merged revisions 76661 via svnmerge from
svn+ssh://[email protected]/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://[email protected]/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. ........ ................
1 parent 8ab3101 commit 8054a5d

2 files changed

Lines changed: 36 additions & 36 deletions

File tree

Lib/test/test_linecache.py

Lines changed: 32 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -83,44 +83,40 @@ def test_checkcache(self):
8383
getline = linecache.getline
8484
try:
8585
# Create a source file and cache its contents
86-
source_name = os.path.join(TEST_PATH, 'linecache_test.py')
87-
source = open(source_name, 'w')
88-
source.write(SOURCE_1)
89-
source.close()
90-
getline(source_name, 1)
91-
92-
# Keep a copy of the old contents
93-
source_list = []
94-
source = open(source_name)
95-
for index, line in enumerate(source):
96-
self.assertEquals(line, getline(source_name, index + 1))
97-
source_list.append(line)
98-
source.close()
99-
100-
source = open(source_name, 'w')
101-
source.write(SOURCE_2)
102-
source.close()
103-
104-
# Try to update a bogus cache entry
105-
linecache.checkcache('dummy')
106-
107-
# Check that the cache matches the old contents
108-
for index, line in enumerate(source_list):
109-
self.assertEquals(line, getline(source_name, index + 1))
110-
111-
# Update the cache and check whether it matches the new source file
112-
linecache.checkcache(source_name)
113-
source = open(source_name)
114-
for index, line in enumerate(source):
115-
self.assertEquals(line, getline(source_name, index + 1))
116-
source_list.append(line)
117-
source.close()
86+
source_name = support.TESTFN + '.py'
87+
with open(source_name, 'w') as source:
88+
source.write(SOURCE_1)
89+
source.close()
90+
getline(source_name, 1)
91+
92+
# Keep a copy of the old contents
93+
source_list = []
94+
source = open(source_name)
95+
for index, line in enumerate(source):
96+
self.assertEquals(line, getline(source_name, index + 1))
97+
source_list.append(line)
98+
source.close()
11899

119-
finally:
120-
try:
100+
source = open(source_name, 'w')
101+
source.write(SOURCE_2)
121102
source.close()
122-
finally:
123-
support.unlink(source_name)
103+
104+
# Try to update a bogus cache entry
105+
linecache.checkcache('dummy')
106+
107+
# Check that the cache matches the old contents
108+
for index, line in enumerate(source_list):
109+
self.assertEquals(line, getline(source_name, index + 1))
110+
111+
# Update the cache and check whether it matches the new source file
112+
linecache.checkcache(source_name)
113+
source = open(source_name)
114+
for index, line in enumerate(source):
115+
self.assertEquals(line, getline(source_name, index + 1))
116+
source_list.append(line)
117+
118+
finally:
119+
support.unlink(source_name)
124120

125121
def test_main():
126122
support.run_unittest(LineCacheTests)

Misc/NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,10 @@ Extension Modules
192192
Tests
193193
-----
194194

195+
- Issue #7431: use TESTFN in test_linecache instead of trying to create a
196+
file in the Lib/test directory, which might be read-only for the
197+
user running the tests.
198+
195199
- Issue #7324: add a sanity check to regrtest argument parsing to
196200
catch the case of an option with no handler.
197201

0 commit comments

Comments
 (0)