From d32a0ffa1db44dd44010bc340ecaf0fd8105c68c Mon Sep 17 00:00:00 2001 From: Austin Macdonald Date: Mon, 13 May 2024 20:28:37 -0500 Subject: [PATCH] test close --- src/duct.py | 3 +++ test/test_tailpipe.py | 9 +++++++++ 2 files changed, 12 insertions(+) diff --git a/src/duct.py b/src/duct.py index cb3f4a1d..79a929f1 100755 --- a/src/duct.py +++ b/src/duct.py @@ -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() diff --git a/test/test_tailpipe.py b/test/test_tailpipe.py index 11d715c1..1f363ccc 100644 --- a/test/test_tailpipe.py +++ b/test/test_tailpipe.py @@ -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()