mirror of
https://github.com/smittix/intercept.git
synced 2026-06-19 02:49:45 -07:00
9463d53763
- document str defaults / bytes for binary-mode callers - wire __exit__ to False so exceptions are not suppressed - exercise exited-process path through subprocess.run Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
28 lines
1.2 KiB
Python
28 lines
1.2 KiB
Python
"""Tests for shared conftest fixtures."""
|
|
|
|
import subprocess
|
|
from unittest.mock import patch
|
|
|
|
|
|
class TestFakeProcess:
|
|
def test_works_with_subprocess_run(self, fake_process):
|
|
"""subprocess.run() must unpack communicate() and enter the context manager."""
|
|
proc = fake_process(stdout="hello", stderr="", returncode=0)
|
|
with patch("subprocess.Popen", return_value=proc):
|
|
result = subprocess.run(["anything"], capture_output=True, text=True, timeout=5)
|
|
assert result.stdout == "hello"
|
|
|
|
def test_running_process_defaults(self, fake_process):
|
|
proc = fake_process()
|
|
assert proc.poll() is None # still running
|
|
assert proc.pid == 12345
|
|
assert proc.communicate() == ("", "")
|
|
|
|
def test_exited_process_detected_via_run(self, fake_process):
|
|
"""An exited process's returncode and stderr surface through subprocess.run."""
|
|
proc = fake_process(running=False, returncode=1, stdout=b"", stderr=b"device busy")
|
|
with patch("subprocess.Popen", return_value=proc):
|
|
result = subprocess.run(["anything"], capture_output=True)
|
|
assert result.returncode == 1
|
|
assert result.stderr == b"device busy"
|