1313from maseval .core .registry import ComponentRegistry
1414from maseval .core .tracing import TraceableMixin
1515from maseval .core .config import ConfigurableMixin
16+ from maseval .core .usage import UsageTrackableMixin
1617
1718
1819# ==================== Test Components ====================
@@ -276,6 +277,7 @@ def gather_traces(self) -> Dict[str, Any]:
276277
277278 def gather_usage (self ):
278279 from maseval .core .usage import TokenUsage
280+
279281 return TokenUsage (
280282 cost = self ._cost ,
281283 input_tokens = self ._input_tokens ,
@@ -297,10 +299,6 @@ def gather_usage(self):
297299 raise RuntimeError ("Usage collection failed" )
298300
299301
300- # Ensure MockUsageComponent also inherits UsageTrackableMixin
301- from maseval .core .usage import UsageTrackableMixin
302-
303-
304302class UsageAwareComponent (TraceableMixin , UsageTrackableMixin ):
305303 """Component with both tracing and usage tracking."""
306304
@@ -315,6 +313,7 @@ def gather_traces(self) -> Dict[str, Any]:
315313
316314 def gather_usage (self ):
317315 from maseval .core .usage import TokenUsage
316+
318317 return TokenUsage (
319318 cost = self ._cost ,
320319 input_tokens = self ._input_tokens ,
@@ -362,7 +361,6 @@ def test_non_usage_component_not_in_usage_registry(self):
362361
363362 def test_collect_usage_basic (self ):
364363 """collect_usage returns structured dict with usage from registered components."""
365- from maseval .core .usage import TokenUsage
366364
367365 registry = ComponentRegistry ()
368366 model = UsageAwareComponent (cost = 0.10 , input_tokens = 500 , output_tokens = 200 )
@@ -445,7 +443,10 @@ def test_usage_by_component_accumulates(self):
445443 by_comp = registry .usage_by_component
446444 assert "models:main_model" in by_comp
447445
446+ from maseval .core .usage import TokenUsage
447+
448448 total = by_comp ["models:main_model" ]
449+ assert isinstance (total , TokenUsage )
449450 assert total .input_tokens == 300
450451 assert total .output_tokens == 150
451452 assert total .cost == pytest .approx (0.30 )
0 commit comments