hkblockchaintechnology commited on
Commit
669597a
·
verified ·
1 Parent(s): cb71765

Publish tests/ from marimo

Browse files
Files changed (2) hide show
  1. tests/test_api_surface.py +38 -0
  2. tests/test_models.py +46 -0
tests/test_api_surface.py ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """The public API is a promise: everything advertised is importable, once."""
2
+
3
+ import importlib
4
+ import inspect
5
+
6
+ import tiny_computer_agent as tca
7
+
8
+
9
+ def test_everything_in_all_is_reachable_from_the_package_root():
10
+ missing = [name for name in tca.__all__ if not hasattr(tca, name)]
11
+ assert missing == [], f"advertised but not exported: {missing}"
12
+
13
+
14
+ def test_all_is_sorted_and_free_of_duplicates():
15
+ assert tca.__all__ == sorted(tca.__all__), "keep __all__ alphabetical"
16
+ assert len(tca.__all__) == len(set(tca.__all__)), "no duplicate exports"
17
+
18
+
19
+ def test_no_public_callable_in_a_module_is_missing_from_all():
20
+ """A capability a user cannot import is a capability they cannot use."""
21
+ modules = ["actions", "act", "observe", "perception", "brain", "models", "loop",
22
+ "safety", "desktop", "demo", "trace"]
23
+ unexported = []
24
+ for name in modules:
25
+ module = importlib.import_module(f"tiny_computer_agent.{name}")
26
+ for attr, obj in vars(module).items():
27
+ if attr.startswith("_") or getattr(obj, "__module__", "") != module.__name__:
28
+ continue
29
+ if attr in tca.__all__ or attr.endswith(("Error", "Unavailable", "Violation")):
30
+ continue
31
+ unexported.append(f"{name}.{attr}")
32
+ assert unexported == [], f"public names not exported from the package root: {unexported}"
33
+
34
+
35
+ def test_the_documented_entry_points_are_callable():
36
+ for name in ["doctor", "run_checks", "display_available", "build_agent",
37
+ "make_detector", "make_model_brain", "benchmark", "score"]:
38
+ assert callable(getattr(tca, name)), name
tests/test_models.py ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """The model backends: laziness, device choice, and honest failures."""
2
+
3
+ import pytest
4
+
5
+ from tiny_computer_agent import (DEFAULT_TEXT_MODEL, DEFAULT_VISION_MODEL, MODEL_BRAINS,
6
+ BrainError, make_model_brain, model_cached, model_dependencies,
7
+ pick_dtype, resolve_device)
8
+
9
+
10
+ def test_building_a_brain_does_not_load_any_weights():
11
+ """Constructing must be free: --doctor builds one on machines with no cache."""
12
+ for name in MODEL_BRAINS:
13
+ brain = make_model_brain(name)
14
+ assert brain.loaded is False
15
+ assert brain.model_id in (DEFAULT_TEXT_MODEL, DEFAULT_VISION_MODEL)
16
+
17
+
18
+ def test_unload_returns_a_brain_to_the_unloaded_state():
19
+ brain = make_model_brain("text-planner")
20
+ brain.unload()
21
+ assert brain.loaded is False
22
+
23
+
24
+ def test_an_unknown_brain_name_is_refused_with_the_alternatives():
25
+ with pytest.raises(BrainError, match="unknown brain"):
26
+ make_model_brain("gpt-9")
27
+
28
+
29
+ def test_the_text_planner_needs_an_index_but_the_vlm_does_not():
30
+ assert make_model_brain("text-planner").requires_index is True
31
+ assert make_model_brain("vlm").requires_index is False
32
+
33
+
34
+ def test_the_model_runtime_report_is_a_pair():
35
+ ok, detail = model_dependencies()
36
+ assert isinstance(ok, bool) and detail
37
+
38
+
39
+ def test_model_cached_is_false_for_a_model_that_cannot_exist():
40
+ assert model_cached("definitely/not-a-real-model") is False
41
+
42
+
43
+ def test_device_and_dtype_are_chosen_without_a_gpu():
44
+ assert resolve_device("cpu") == "cpu"
45
+ assert pick_dtype("cpu") is not None
46
+ assert pick_dtype("cuda") is not None