Run a trivial command and validate output streaming and exit code. Uses `uv run python -c "print('hello')"` to ensure we respect the repository rule that all Python execution goes through `uv run python`.
(self: "TestRunningProcess")
| 18 | @pytest.mark.serial |
| 19 | class TestRunningProcess(unittest.TestCase): |
| 20 | def test_sanity(self: "TestRunningProcess") -> None: |
| 21 | """Run a trivial command and validate output streaming and exit code. |
| 22 | |
| 23 | Uses `uv run python -c "print('hello')"` to ensure we respect the |
| 24 | repository rule that all Python execution goes through `uv run python`. |
| 25 | """ |
| 26 | |
| 27 | command: list[str] = [ |
| 28 | "uv", |
| 29 | "run", |
| 30 | "python", |
| 31 | "-c", |
| 32 | "print('hello')", |
| 33 | ] |
| 34 | |
| 35 | rp: RunningProcess = RunningProcess( |
| 36 | command=command, |
| 37 | cwd=Path(".").absolute(), |
| 38 | check=False, |
| 39 | auto_run=True, |
| 40 | timeout=30, |
| 41 | on_complete=None, |
| 42 | output_formatter=None, |
| 43 | ) |
| 44 | |
| 45 | captured_lines: list[str] = [] |
| 46 | |
| 47 | while True: |
| 48 | out: Any = rp.get_next_line_non_blocking() |
| 49 | if isinstance(out, EndOfStream): |
| 50 | break |
| 51 | if isinstance(out, str): |
| 52 | captured_lines.append(out) |
| 53 | else: |
| 54 | time.sleep(0.01) |
| 55 | |
| 56 | rc: Any = rp.wait() |
| 57 | self.assertEqual(rc, 0) |
| 58 | |
| 59 | combined: str = "\n".join(captured_lines).strip() |
| 60 | self.assertIn("hello", combined) |
| 61 | |
| 62 | def test_line_iter_basic(self: "TestRunningProcess") -> None: |
| 63 | """Validate context-managed line iteration yields only strings and completes.""" |