##// END OF EJS Templates
Do not return filehandle as unused
Matthias Bussonnier -
r25106:7c1c9976
parent child
Show More
@@ -62,9 +62,8 def test_parser():
62
62
63 def test_temp_pyfile():
63 def test_temp_pyfile():
64 src = 'pass\n'
64 src = 'pass\n'
65 fname, fh = tt.temp_pyfile(src)
65 fname = tt.temp_pyfile(src)
66 assert os.path.isfile(fname)
66 assert os.path.isfile(fname)
67 fh.close()
68 with open(fname) as fh2:
67 with open(fname) as fh2:
69 src2 = fh2.read()
68 src2 = fh2.read()
70 nt.assert_equal(src2, src)
69 nt.assert_equal(src2, src)
@@ -269,20 +269,19 class TempFileMixin(object):
269
269
270 def mktmp(self, src, ext='.py'):
270 def mktmp(self, src, ext='.py'):
271 """Make a valid python temp file."""
271 """Make a valid python temp file."""
272 fname, f = temp_pyfile(src, ext)
272 fname = temp_pyfile(src, ext)
273 if not hasattr(self, 'tmps'):
273 if not hasattr(self, 'tmps'):
274 self.tmps=[]
274 self.tmps=[]
275 self.tmps.append((f, fname))
275 self.tmps.append(fname)
276 self.fname = fname
276 self.fname = fname
277
277
278 def tearDown(self):
278 def tearDown(self):
279 # If the tmpfile wasn't made because of skipped tests, like in
279 # If the tmpfile wasn't made because of skipped tests, like in
280 # win32, there's nothing to cleanup.
280 # win32, there's nothing to cleanup.
281 if hasattr(self, 'tmps'):
281 if hasattr(self, 'tmps'):
282 for f,fname in self.tmps:
282 for fname in self.tmps:
283 # If the tmpfile wasn't made because of skipped tests, like in
283 # If the tmpfile wasn't made because of skipped tests, like in
284 # win32, there's nothing to cleanup.
284 # win32, there's nothing to cleanup.
285 f.close()
286 try:
285 try:
287 os.unlink(fname)
286 os.unlink(fname)
288 except:
287 except:
@@ -205,10 +205,10 def temp_pyfile(src, ext='.py'):
205 It is the caller's responsibility to close the open file and unlink it.
205 It is the caller's responsibility to close the open file and unlink it.
206 """
206 """
207 fname = tempfile.mkstemp(ext)[1]
207 fname = tempfile.mkstemp(ext)[1]
208 f = open(fname,'w')
208 with open(fname,'w') as f:
209 f.write(src)
209 f.write(src)
210 f.flush()
210 f.flush()
211 return fname, f
211 return fname
212
212
213 @undoc
213 @undoc
214 def atomic_writing(*args, **kwargs):
214 def atomic_writing(*args, **kwargs):
General Comments 0
You need to be logged in to leave comments. Login now