Publish tests/ from marimo
Browse files
tests/test_windows_platform.py
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""The things only real Windows can verify.
|
| 2 |
+
|
| 3 |
+
Skipped everywhere else, so the suite stays green on Linux while these stay honest:
|
| 4 |
+
they are the reason `display_available()` and the capture backend are more than an
|
| 5 |
+
assertion about a code path. The `windows-latest` CI job runs them, and so does a
|
| 6 |
+
Windows machine with `-m pytest tests/test_windows_platform.py`.
|
| 7 |
+
"""
|
| 8 |
+
|
| 9 |
+
import os
|
| 10 |
+
import platform
|
| 11 |
+
|
| 12 |
+
import pytest
|
| 13 |
+
|
| 14 |
+
WINDOWS = platform.system() == "Windows"
|
| 15 |
+
|
| 16 |
+
pytestmark = pytest.mark.skipif(not WINDOWS, reason="needs real Windows")
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
def test_display_available_says_so_on_windows():
|
| 20 |
+
from tiny_computer_agent import display_available
|
| 21 |
+
|
| 22 |
+
ok, detail = display_available()
|
| 23 |
+
assert ok is True
|
| 24 |
+
assert "Windows" in detail
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
def test_capture_returns_the_real_screen():
|
| 28 |
+
from tiny_computer_agent import GrabScreen
|
| 29 |
+
|
| 30 |
+
observation = GrabScreen(monitor=1).capture()
|
| 31 |
+
frame = observation.frame
|
| 32 |
+
assert frame.width > 100 and frame.height > 100
|
| 33 |
+
sampled = {pixel for row in list(frame.resize((8, 8)).getdata()) for pixel in [row]}
|
| 34 |
+
assert len(sampled) > 1, "the screenshot came back as one flat colour"
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
def test_a_detector_that_needs_nothing_still_indexes_the_screen():
|
| 38 |
+
from tiny_computer_agent import GrabScreen, make_detector
|
| 39 |
+
|
| 40 |
+
frame = GrabScreen(monitor=1).capture().frame
|
| 41 |
+
assert len(make_detector("grid").detect(frame)) == 96
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
def test_ui_automation_is_reported_truthfully():
|
| 45 |
+
from tiny_computer_agent import accessibility_available
|
| 46 |
+
|
| 47 |
+
ok, detail = accessibility_available("uia")
|
| 48 |
+
assert isinstance(ok, bool) and detail
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
def test_the_doctor_reports_a_ready_windows_desktop():
|
| 52 |
+
from tiny_computer_agent import run_checks
|
| 53 |
+
|
| 54 |
+
checks = {check.name: check for check in run_checks(brain="planner", detector="grid")}
|
| 55 |
+
assert checks["display server"].ok is True
|
| 56 |
+
assert checks["pillow"].ok is True
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
@pytest.mark.skipif(os.environ.get("TINY_COMPUTER_AGENT_LIVE_TEST") != "1",
|
| 60 |
+
reason="moves the real mouse: opt in, and use a throwaway desktop")
|
| 61 |
+
def test_the_real_mouse_goes_where_it_is_asked():
|
| 62 |
+
pyautogui = pytest.importorskip("pyautogui")
|
| 63 |
+
|
| 64 |
+
pyautogui.moveTo(120, 140)
|
| 65 |
+
assert abs(pyautogui.position().x - 120) <= 2
|
| 66 |
+
assert abs(pyautogui.position().y - 140) <= 2
|