| 119 | |
| 120 | # Check output logs from last found (stateful) |
| 121 | def expect(self, to_expect, *, stream="stderr"): |
| 122 | __tracebackhide__ = True |
| 123 | |
| 124 | if stream == "stdout": |
| 125 | buffer = self.stdout_output |
| 126 | cursor = self._stdout_cursor |
| 127 | else: |
| 128 | buffer = self.stderr_output |
| 129 | cursor = self._stderr_cursor |
| 130 | |
| 131 | start_time = time.time() |
| 132 | while time.time() - start_time < self.expect_timeout: |
| 133 | new_lines = buffer[cursor:] |
| 134 | for idx, line in enumerate(new_lines): |
| 135 | if to_expect in line: |
| 136 | cursor += idx + 1 |
| 137 | return |
| 138 | time.sleep(0.05) |
| 139 | |
| 140 | output = "\n".join(buffer[-5:]) |
| 141 | self.on_fail(f"Timed out waiting for '{to_expect}' after {self.expect_timeout} seconds. Got\n{output}") |
| 142 | |
| 143 | # Check all output logs (stateless) |
| 144 | def expect_any(self, to_expect, *, stream="stderr"): |