mirror of
https://github.com/usestrix/strix.git
synced 2026-09-15 23:31:27 +00:00
Lean up implementation
This commit is contained in:
parent
0a5d0f288b
commit
3982d50573
3 changed files with 6 additions and 43 deletions
|
|
@ -111,7 +111,6 @@ def record_failure(
|
|||
label,
|
||||
reason,
|
||||
result=None,
|
||||
screenshot_path=None,
|
||||
):
|
||||
_failures.append(
|
||||
{
|
||||
|
|
@ -119,7 +118,6 @@ def record_failure(
|
|||
"label": label,
|
||||
"reason": reason,
|
||||
"result": result,
|
||||
"screenshot": screenshot_path,
|
||||
}
|
||||
)
|
||||
|
||||
|
|
@ -138,7 +136,6 @@ def _print_summary():
|
|||
name = f.get("name", "?")
|
||||
reason = str(f.get("reason", f.get("details", "")))
|
||||
result = f.get("result")
|
||||
screenshot = f.get("screenshot")
|
||||
|
||||
_console.print(f" [bold red]── {name} ──[/]")
|
||||
|
||||
|
|
@ -150,16 +147,11 @@ def _print_summary():
|
|||
_console.print(" [red]│[/]")
|
||||
_console.print(" [red]╰─▶[/] [dim]result:[/]")
|
||||
for k, v in result.items():
|
||||
if k == "screenshot":
|
||||
continue
|
||||
v_str = str(v)
|
||||
if len(v_str) > 120:
|
||||
v_str = v_str[:120] + "…"
|
||||
_console.print(f" [dim]{k}:[/] {rich_escape(v_str)}")
|
||||
|
||||
if screenshot:
|
||||
_console.print(f" [dim]screenshot:[/] [underline]{rich_escape(screenshot)}[/]")
|
||||
|
||||
_console.print()
|
||||
|
||||
total = _passed + _failed
|
||||
|
|
|
|||
|
|
@ -1,22 +1,10 @@
|
|||
import base64
|
||||
import inspect
|
||||
import shutil
|
||||
from pathlib import Path
|
||||
|
||||
from pytest_check import check
|
||||
|
||||
from . import console as ui
|
||||
|
||||
|
||||
SCREENSHOTS_DIR = Path(__file__).parent / "screenshots"
|
||||
|
||||
|
||||
def setup_screenshots_dir():
|
||||
if SCREENSHOTS_DIR.exists():
|
||||
shutil.rmtree(SCREENSHOTS_DIR)
|
||||
SCREENSHOTS_DIR.mkdir(exist_ok=True)
|
||||
|
||||
|
||||
class Browser:
|
||||
def __init__(self, agent_id, agent_state=None):
|
||||
self._agent_id = agent_id
|
||||
|
|
@ -43,7 +31,8 @@ class Browser:
|
|||
result = future.result(timeout=120)
|
||||
if "error" in result:
|
||||
Fail(result).error(result["error"])
|
||||
_strip_screenshot(result, _caller_test_name())
|
||||
if "screenshot" in result:
|
||||
result["screenshot"] = "[Image]"
|
||||
return result
|
||||
|
||||
return call
|
||||
|
|
@ -68,20 +57,10 @@ def _caller_test_name():
|
|||
return "unknown"
|
||||
|
||||
|
||||
def _strip_screenshot(result, name):
|
||||
b64 = result.pop("screenshot", None)
|
||||
if not b64 or not isinstance(b64, str) or len(b64) < 100:
|
||||
return
|
||||
path = SCREENSHOTS_DIR / f"{name}.png"
|
||||
path.write_bytes(base64.b64decode(b64))
|
||||
result["screenshot_path"] = str(path)
|
||||
|
||||
|
||||
class Fail:
|
||||
def __init__(self, result=None):
|
||||
self._result = result
|
||||
self._name = _caller_test_name()
|
||||
self._screenshot = result.get("screenshot_path") if result else None
|
||||
|
||||
def expected(self, value):
|
||||
self._expected = value
|
||||
|
|
@ -100,7 +79,6 @@ class Fail:
|
|||
self._name,
|
||||
reason,
|
||||
self._result,
|
||||
self._screenshot,
|
||||
)
|
||||
with check:
|
||||
check.fail(f"[{self._name}] {reason}")
|
||||
|
|
|
|||
|
|
@ -1,15 +1,11 @@
|
|||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
from . import console as ui
|
||||
from .helpers import Fail, setup_screenshots_dir
|
||||
from .helpers import Fail
|
||||
|
||||
|
||||
pytestmark = pytest.mark.integration
|
||||
|
||||
setup_screenshots_dir()
|
||||
|
||||
|
||||
def test_navigate(browser):
|
||||
ui.status("test_navigate → example.com")
|
||||
|
|
@ -88,13 +84,10 @@ def test_screenshot(browser):
|
|||
browser.navigate(url="https://example.com")
|
||||
|
||||
result = browser.screenshot()
|
||||
path = result.get("screenshot_path")
|
||||
ui.log(f"screenshot → {path}")
|
||||
ui.log(f"screenshot → {result.get('screenshot')}")
|
||||
|
||||
if not path:
|
||||
Fail(result).error("no screenshot saved")
|
||||
elif not Path(path).exists():
|
||||
Fail(result).error(f"screenshot file missing: {path}")
|
||||
if result.get("screenshot") != "[Image]":
|
||||
Fail(result).error("expected screenshot in response")
|
||||
|
||||
|
||||
def test_input(browser):
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue