Validate context-managed line iteration yields only strings and completes.
(self: "TestRunningProcess")
| 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.""" |
| 64 | |
| 65 | command: list[str] = [ |
| 66 | "uv", |
| 67 | "run", |
| 68 | "python", |
| 69 | "-c", |
| 70 | "print('a'); print('b'); print('c')", |
| 71 | ] |
| 72 | |
| 73 | rp: RunningProcess = RunningProcess( |
| 74 | command=command, |
| 75 | cwd=Path(".").absolute(), |
| 76 | check=False, |
| 77 | auto_run=True, |
| 78 | timeout=10, |
| 79 | on_complete=None, |
| 80 | output_formatter=None, |
| 81 | ) |
| 82 | |
| 83 | iter_lines: list[str] = [] |
| 84 | with rp.line_iter(timeout=60) as it: |
| 85 | for ln in it: |
| 86 | # Should always be a string, never None |
| 87 | self.assertIsInstance(ln, str) |
| 88 | iter_lines.append(ln) |
| 89 | |
| 90 | # Process should have finished; ensure exit success |
| 91 | rc: Any = rp.wait() |
| 92 | self.assertEqual(rc, 0) |
| 93 | self.assertEqual(iter_lines, ["a", "b", "c"]) |
| 94 | |
| 95 | |
| 96 | class _UpperFormatter: |