Download tests/test_actions.py from hkblockchaintechnology/tiny-computer-agent: direct link, hf CLI and curl.
- Browser
- Download file 1.7 kB
-
https://huggingface.co/hkblockchaintechnology/tiny-computer-agent/resolve/main/tests/test_actions.py
- Command line
-
hf download hf://hkblockchaintechnology/tiny-computer-agent/tests/test_actions.py
-
curl -L -o test_actions.py https://huggingface.co/hkblockchaintechnology/tiny-computer-agent/resolve/main/tests/test_actions.py
1.7 kB
| import pytest | |
| from tiny_computer_agent import ACTION_KINDS, ACTION_MENU, Action, ActionError, parse_action | |
| def test_click_by_label(): | |
| action = Action("click", label="Save") | |
| assert action.kind == "click" | |
| assert "label='Save'" in action.describe() | |
| def test_click_by_pixels(): | |
| assert Action("click", x=10, y=20).x == 10 | |
| def test_validation_rejects_bad_actions(kwargs, message): | |
| with pytest.raises(ActionError, match=message): | |
| Action(**kwargs) | |
| # the same rule must hold for anything a model sends back | |
| with pytest.raises(ActionError): | |
| parse_action(kwargs) | |
| def test_parse_action_ignores_chatty_extra_keys(): | |
| action = parse_action({"kind": "type", "text": "hello", "confidence": 0.9, "thought": "..."}) | |
| assert action.text == "hello" | |
| def test_parse_action_rejects_a_non_mapping(): | |
| with pytest.raises(ActionError, match="expected a mapping"): | |
| parse_action(["click", "Save"]) | |
| def test_menu_documents_every_verb(): | |
| for kind in ACTION_KINDS: | |
| assert f'"kind": "{kind}"' in ACTION_MENU | |
| def test_round_trip_to_dict(): | |
| action = Action("scroll", amount=-3, reason="more content below") | |
| assert parse_action(action.to_dict()).amount == -3 | |