import sys sys.path.insert(0, 'bin') from unittest.mock import patch import pytest from check_budget import is_budget_ok, get_used_usd def test_budget_ok_when_used_less_than_limit(): with patch('check_budget.get_used_usd', return_value=2.0): assert is_budget_ok(limit_usd=5.0) is True def test_budget_not_ok_when_used_exceeds_limit(): with patch('check_budget.get_used_usd', return_value=5.5): assert is_budget_ok(limit_usd=5.0) is False def test_budget_ok_on_api_error(): """Fail open: if we can't check the budget, assume OK to avoid blocking research.""" with patch('check_budget.get_used_usd', side_effect=Exception("network error")): assert is_budget_ok(limit_usd=5.0) is True def test_budget_exactly_at_limit_is_not_ok(): with patch('check_budget.get_used_usd', return_value=5.0): assert is_budget_ok(limit_usd=5.0) is False