MCPcopy Create free account
hub / github.com/Emmimal/control-layer / TestTokenBudget

Class TestTokenBudget

tests/test_control_layer.py:114–143  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

112# =============================================================================
113
114class TestTokenBudget:
115
116 def test_accurate_count(self):
117 budget = TokenBudget(total_tokens=100)
118 count = budget.count("Hello world")
119 assert count > 0
120 assert isinstance(count, int)
121
122 def test_reserve_succeeds_within_budget(self):
123 budget = TokenBudget(total_tokens=1000)
124 ok = budget.reserve("system", "You are a helpful assistant.")
125 assert ok is True
126 assert budget.used() > 0
127
128 def test_reserve_fails_when_over_budget(self):
129 budget = TokenBudget(total_tokens=5)
130 ok = budget.reserve("system", "This is a very long string that definitely exceeds five tokens.")
131 assert ok is False
132
133 def test_remaining_decreases_on_reserve(self):
134 budget = TokenBudget(total_tokens=500)
135 before = budget.remaining()
136 budget.reserve("slot1", "Some text to reserve")
137 assert budget.remaining() < before
138
139 def test_report_returns_slot_names(self):
140 budget = TokenBudget(total_tokens=500)
141 budget.reserve("system_prompt", "You are a helpful assistant.")
142 report = budget.report()
143 assert "system_prompt" in report
144
145
146# =============================================================================

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected