Skip to content

Commit 7f04156

Browse files
committed
add test: sink_to_textfile closes file when deleted
1 parent 31018a7 commit 7f04156

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

streamz/tests/test_sinks.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
from time import sleep
22

3+
import pytest
34
from streamz import Stream
5+
from streamz.sinks import _global_sinks
46
from streamz.utils_test import tmpfile
57

68

@@ -43,3 +45,15 @@ def test_sink_to_textfile_named():
4345
sleep(0.01)
4446

4547
assert open(filename, "r").read() == "0\n1\n"
48+
49+
50+
def test_sink_to_textfile_closes():
51+
source = Stream()
52+
with tmpfile() as filename:
53+
sink = source.sink_to_textfile(filename)
54+
fp = sink._fp
55+
_global_sinks.remove(sink)
56+
del sink
57+
58+
with pytest.raises(ValueError): # I/O operation on closed file
59+
fp.write(".")

0 commit comments

Comments
 (0)