import pytest
import numpy as np
class TestModel:
@pytest.fixture
def model(self):
return load_model("models/churn_model.pkl")
def test_prediction_shape(self, model):
X = np.random.randn(10, 15)
predictions = model.predict(X)
assert predictions.shape == (10,)
def test_prediction_range(self, model):
X = np.random.randn(100, 15)
predictions = model.predict_proba(X)
assert np.all(predictions >= 0) and np.all(predictions <= 1)
def test_known_input(self, model):
high_risk = np.array([[0, 100, 365, 0, 1, ...]])
prob = model.predict_proba(high_risk)[0, 1]
assert prob > 0.7, "High-risk customer should have high churn probability"