Skip to content

Commit

Permalink
test close
Browse files Browse the repository at this point in the history
  • Loading branch information
asmacdo committed May 14, 2024
1 parent 50c96f0 commit d32a0ff
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/duct.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,9 @@ class TailPipe:
def __init__(self, file_path, buffer):
self.file_path = file_path
self.buffer = buffer
self.stop_event = None
self.infile = None
self.thread = None

def start(self):
Path(self.file_path).touch()
Expand Down
9 changes: 9 additions & 0 deletions test/test_tailpipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,14 @@ def test_high_throughput(mock_stdout, fixture_path):
assert mock_stdout.getvalue() == expected


@patch("sys.stdout", new_callable=lambda: MockStream())
def test_close(mock_stdout):
with tempfile.NamedTemporaryFile(mode="wb") as tmpfile:
stream = TailPipe(tmpfile.name, mock_stdout.buffer)
stream.start()
stream.close()
assert stream.infile.closed


if __name__ == "__main__":
test_high_throughput()

0 comments on commit d32a0ff

Please sign in to comment.