tiny-computer-agent / tests /test_models.py
hkblockchaintechnology's picture
Publish tests/ from marimo
669597a verified
Raw History Blame Contribute Delete
1.61 kB
"""The model backends: laziness, device choice, and honest failures."""
import pytest
from tiny_computer_agent import (DEFAULT_TEXT_MODEL, DEFAULT_VISION_MODEL, MODEL_BRAINS,
BrainError, make_model_brain, model_cached, model_dependencies,
pick_dtype, resolve_device)
def test_building_a_brain_does_not_load_any_weights():
"""Constructing must be free: --doctor builds one on machines with no cache."""
for name in MODEL_BRAINS:
brain = make_model_brain(name)
assert brain.loaded is False
assert brain.model_id in (DEFAULT_TEXT_MODEL, DEFAULT_VISION_MODEL)
def test_unload_returns_a_brain_to_the_unloaded_state():
brain = make_model_brain("text-planner")
brain.unload()
assert brain.loaded is False
def test_an_unknown_brain_name_is_refused_with_the_alternatives():
with pytest.raises(BrainError, match="unknown brain"):
make_model_brain("gpt-9")
def test_the_text_planner_needs_an_index_but_the_vlm_does_not():
assert make_model_brain("text-planner").requires_index is True
assert make_model_brain("vlm").requires_index is False
def test_the_model_runtime_report_is_a_pair():
ok, detail = model_dependencies()
assert isinstance(ok, bool) and detail
def test_model_cached_is_false_for_a_model_that_cannot_exist():
assert model_cached("definitely/not-a-real-model") is False
def test_device_and_dtype_are_chosen_without_a_gpu():
assert resolve_device("cpu") == "cpu"
assert pick_dtype("cpu") is not None
assert pick_dtype("cuda") is not None