···
21
+
from test_driver.errors import RequestedAssertionFailed, TestScriptError
from test_driver.logger import AbstractLogger
from .qmp import QMPSession
···
132
+
raise TestScriptError(
f"Image processing failed with exit code {ret.returncode}, stdout: {ret.stdout.decode()}, stderr: {ret.stderr.decode()}"
···
screenshot_path: str, model_ids: Iterable[int]
if shutil.which("tesseract") is None:
142
-
raise Exception("OCR requested but enableOCR is false")
143
+
raise TestScriptError("OCR requested but enableOCR is false")
processed_image = _preprocess_screenshot(screenshot_path, negate=False)
processed_negative = _preprocess_screenshot(screenshot_path, negate=True)
···
165
-
raise Exception(f"OCR failed with exit code {ret.returncode}")
166
+
raise TestScriptError(f"OCR failed with exit code {ret.returncode}")
model_results.append(ret.stdout.decode("utf-8"))
···
182
-
raise Exception(f"action timed out after {timeout} seconds")
183
+
raise RequestedAssertionFailed(
184
+
f"action timed out after {timeout} tries with one-second pause in-between"
···
def check_active(_last_try: bool) -> bool:
state = self.get_unit_property(unit, "ActiveState", user)
405
-
raise Exception(f'unit "{unit}" reached state "{state}"')
408
+
raise RequestedAssertionFailed(f'unit "{unit}" reached state "{state}"')
status, jobs = self.systemctl("list-jobs --full 2>&1", user)
info = self.get_unit_info(unit, user)
if info["ActiveState"] == state:
415
+
raise RequestedAssertionFailed(
f'unit "{unit}" is inactive and there are no pending jobs'
···
def get_unit_info(self, unit: str, user: str | None = None) -> dict[str, str]:
status, lines = self.systemctl(f'--no-pager show "{unit}"', user)
430
+
raise RequestedAssertionFailed(
f'retrieving systemctl info for unit "{unit}"'
+ ("" if user is None else f' under user "{user}"')
+ f" failed with exit code {status}"
···
460
+
raise RequestedAssertionFailed(
f'retrieving systemctl property "{property}" for unit "{unit}"'
+ ("" if user is None else f' under user "{user}"')
+ f" failed with exit code {status}"
···
info = self.get_unit_info(unit)
state = info["ActiveState"]
if state != require_state:
508
+
raise RequestedAssertionFailed(
f"Expected unit '{unit}' to to be in state "
f"'{require_state}' but it is in state '{state}'"
···
(status, out) = self.execute(command, timeout=timeout)
self.log(f"output: {out}")
659
-
raise Exception(f"command `{command}` failed (exit code {status})")
662
+
raise RequestedAssertionFailed(
663
+
f"command `{command}` failed (exit code {status})"
···
with self.nested(f"must fail: {command}"):
(status, out) = self.execute(command, timeout=timeout)
673
-
raise Exception(f"command `{command}` unexpectedly succeeded")
678
+
raise RequestedAssertionFailed(
679
+
f"command `{command}` unexpectedly succeeded"
···
ret = subprocess.run(f"pnmtopng '{tmp}' > '{filename}'", shell=True)
918
-
raise Exception("Cannot convert screenshot")
925
+
raise TestScriptError("Cannot convert screenshot")
def copy_from_host_via_shell(self, source: str, target: str) -> None:
"""Copy a file from the host into the guest by piping it over the