Merge pull request #148 from madprog/issue-147
dataset.freeze should not close provided fileobj
This commit is contained in:
commit
5e9745b858
@ -47,4 +47,5 @@ class CSVSerializer(Serializer):
|
||||
|
||||
def close(self):
|
||||
for writer, fh in self.handles.values():
|
||||
fh.close()
|
||||
if fh != self.fileobj:
|
||||
fh.close()
|
||||
|
||||
@ -55,4 +55,5 @@ class JSONSerializer(Serializer):
|
||||
self.export.get('callback'),
|
||||
data)
|
||||
fh.write(data)
|
||||
fh.close()
|
||||
if self.fileobj is None:
|
||||
fh.close()
|
||||
|
||||
@ -62,6 +62,15 @@ class FreezeTestCase(unittest.TestCase):
|
||||
finally:
|
||||
fh.close()
|
||||
|
||||
def test_memory_streams(self):
|
||||
import io
|
||||
|
||||
for fmt in ('csv', 'json', 'tabson'):
|
||||
with io.StringIO() as fd:
|
||||
freeze(self.tbl.all(), format=fmt, fileobj=fd)
|
||||
self.assertFalse(fd.closed, 'fileobj was closed for format %s' % fmt)
|
||||
fd.getvalue() # should not throw
|
||||
|
||||
|
||||
class SerializerTestCase(unittest.TestCase):
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user