inference-capacity-planner / test_engine.py
DataDrivenAlex's picture
Add interactive inference capacity planner
c75a170 verified
Raw History Blame Contribute Delete
1.14 kB
import unittest
from engine import Workload, estimate
class EstimateTests(unittest.TestCase):
def test_capacity_and_cost_scale_with_replicas(self):
a=estimate(Workload(60,500,500,1,2,100)); b=estimate(Workload(60,500,500,1,4,100)); self.assertEqual(a.tokens_per_second_capacity,200); self.assertEqual(b.tokens_per_second_capacity,400); self.assertEqual(b.estimated_cost_per_hour,2*a.estimated_cost_per_hour)
def test_over_capacity_is_flagged(self):
r=estimate(Workload(600,1000,1000,1,1,10)); self.assertGreater(r.utilization,1); self.assertFalse(r.meets_slo); self.assertTrue(any("exceeds" in n for n in r.notes))
def test_zero_load_has_zero_utilization(self):
r=estimate(Workload(0,1000,1000,1,1,10)); self.assertEqual(r.utilization,0); self.assertGreaterEqual(r.estimated_cost_per_hour,0)
def test_invalid_dimensions_rejected(self):
with self.assertRaises(ValueError): estimate(Workload(1,2,3,0,1,10))
def test_custom_cost_and_slo(self):
r=estimate(Workload(1,10,10,1,3,100,target_p95_seconds=1),2.5); self.assertEqual(r.estimated_cost_per_hour,7.5); self.assertTrue(r.meets_slo)
if __name__=='__main__': unittest.main()