Download tests/test_cli.py from hkblockchaintechnology/tiny-computer-agent: direct link, hf CLI and curl.
- Browser
- Download file 2.44 kB
-
https://huggingface.co/hkblockchaintechnology/tiny-computer-agent/resolve/08e397198eb2d07c8af9e032dc80fdceee4f9b9a/tests/test_cli.py
- Command line
-
hf download hf://hkblockchaintechnology/tiny-computer-agent@08e397198eb2d07c8af9e032dc80fdceee4f9b9a/tests/test_cli.py
-
curl -L -o test_cli.py https://huggingface.co/hkblockchaintechnology/tiny-computer-agent/resolve/08e397198eb2d07c8af9e032dc80fdceee4f9b9a/tests/test_cli.py
2.44 kB
| import pytest | |
| from tiny_computer_agent import __main__ as cli | |
| def test_demo_runs_dry_run_by_default(capsys): | |
| assert cli.main([]) == 0 | |
| out = capsys.readouterr().out | |
| assert "dry-run" in out | |
| assert "(dry-run) would click" in out | |
| assert "result: success" in out | |
| def test_real_input_needs_the_allow_env_var(monkeypatch, capsys): | |
| monkeypatch.delenv(cli.ALLOW_REAL_INPUT_ENV, raising=False) | |
| assert cli.main(["--real-input"]) == 2 | |
| assert "refusing --real-input" in capsys.readouterr().err | |
| def test_bad_script_json_is_reported(capsys): | |
| assert cli.main(["--script", "{not json"]) == 2 | |
| assert "not valid JSON" in capsys.readouterr().err | |
| def test_script_replay(capsys): | |
| assert cli.main(["--script", '[{"kind": "done", "reason": "nothing to do"}]']) == 0 | |
| assert "nothing to do" in capsys.readouterr().out | |
| def test_failure_exit_code(capsys): | |
| # the planner gives up when the target never appears, so the CLI exits non-zero | |
| assert cli.main(["click 'Nonexistent button'"]) == 1 | |
| assert "gave up" in capsys.readouterr().out | |
| def test_doctor_exits_with_a_status(capsys): | |
| assert cli.main(["--doctor"]) in (0, 1) | |
| assert "preflight" in capsys.readouterr().out | |
| def test_live_is_refused_without_a_display(capsys, monkeypatch): | |
| from tiny_computer_agent.desktop import display_available | |
| if display_available()[0]: | |
| pytest.skip("this machine has a display, so --live would really run") | |
| assert cli.main(["--live"]) == 2 | |
| captured = capsys.readouterr() | |
| assert "refusing to run live" in captured.err | |
| assert "no DISPLAY" in captured.out | |
| def test_screenshot_replay_needs_no_display(capsys): | |
| """The whole pipeline - OCR index, menu, action - on a still image.""" | |
| from tiny_computer_agent.perception import detector_available | |
| if not detector_available()[0]: | |
| pytest.skip("no OCR engine installed") | |
| assert cli.main(["--image", "example", "--brain", "planner"]) == 0 | |
| out = capsys.readouterr().out | |
| assert "screenshot replay" in out | |
| assert "elements detected" in out | |
| assert "would click" in out | |
| def test_a_missing_image_is_reported_not_crashed(capsys): | |
| assert cli.main(["--image", "/nonexistent/shot.png"]) == 2 | |
| assert "could not start" in capsys.readouterr().err | |
| def test_vlm_brain_requires_a_live_screen(capsys): | |
| assert cli.main(["--brain", "vlm"]) == 2 | |
| assert "needs --live" in capsys.readouterr().err | |