1+ from sklearn .pipeline import Pipeline
2+ from sklearn .preprocessing import FunctionTransformer
3+ from sklearn .preprocessing import MinMaxScaler
4+ from sklearn .ensemble import RandomForestClassifier
5+
6+ from src .model .pipeline_utils import create_breast_cancer_pipeline
7+ from src .model .data_preprocessing import drop_unnecessary_columns
8+
9+ def test_create_breast_cancer_pipeline_returns_pipeline ():
10+ """Test that the create_breast_cancer_pipeline function returns a Pipeline object."""
11+ pipeline = create_breast_cancer_pipeline ()
12+ assert isinstance (pipeline , Pipeline )
13+
14+ def test_create_breast_cancer_pipeline_has_correct_top_level_steps ():
15+ """Test that pipeline has the expected steps (preprocessor and classifier)."""
16+ pipeline = create_breast_cancer_pipeline ()
17+ assert len (pipeline .steps ) == 2
18+ assert pipeline .steps [0 ][0 ] == 'preprocessor'
19+ assert pipeline .steps [1 ][0 ] == 'classifier'
20+
21+ def test_create_breast_cancer_pipeline_has_correct_preprocessor_steps ():
22+ """Test that pipeline has the expected 'preprocessor' steps (drop_cols and scaler)."""
23+ pipeline = create_breast_cancer_pipeline ()
24+ preprocessor = pipeline .named_steps ['preprocessor' ]
25+ assert isinstance (preprocessor , Pipeline )
26+ assert len (preprocessor .steps ) == 2
27+ assert preprocessor .steps [0 ][0 ] == 'drop_cols'
28+ assert preprocessor .steps [1 ][0 ] == 'scaler'
29+
30+ def test_drop_cols_configuration ():
31+ """Test that the 'drop_cols' step is configured correctly."""
32+ pipeline = create_breast_cancer_pipeline ()
33+ drop_cols_transformer = pipeline .named_steps ['preprocessor' ].named_steps ['drop_cols' ]
34+ assert drop_cols_transformer .func == drop_unnecessary_columns
35+ assert drop_cols_transformer .validate == False
36+
37+ def test_scaler_configuration ():
38+ """Test that the 'scaler' step is configured correctly (MinMaxScaler)."""
39+ pipeline = create_breast_cancer_pipeline ()
40+ scaler_transformer = pipeline .named_steps ['preprocessor' ].named_steps ['scaler' ]
41+ assert isinstance (scaler_transformer , MinMaxScaler )
42+
43+ def test_classifier_estimator_configuration ():
44+ """Test that the 'classifier' is a RandomForestClassifier with random_state=42."""
45+ pipeline = create_breast_cancer_pipeline ()
46+ classifier_estimator = pipeline .named_steps ['classifier' ]
47+ assert isinstance (classifier_estimator , RandomForestClassifier )
48+ assert classifier_estimator .random_state == 42
0 commit comments