Skip to content

Commit d4c416a

Browse files
committed
Refactor: Organize unit tests and add pipeline_utils tests
Moved existing unit test files from: - tests/unit/data_ingestion/ - tests/unit/data_preprocessing/ To: - tests/unit/model/data_ingestion/ - tests/unit/model/data_preprocessing/ Additionally, created new unit tests for pipeline_utils under: - tests/unit/model/pipeline_utils/
1 parent 3a3afa8 commit d4c416a

File tree

5 files changed

+48
-0
lines changed

5 files changed

+48
-0
lines changed
File renamed without changes.

tests/unit/data_preprocessing/test_drop_unnecessary_columns.py renamed to tests/unit/model/data_preprocessing/test_drop_unnecessary_columns.py

File renamed without changes.

tests/unit/data_preprocessing/test_map_diagnosis_to_numerical.py renamed to tests/unit/model/data_preprocessing/test_map_diagnosis_to_numerical.py

File renamed without changes.

tests/unit/data_preprocessing/test_prepare_features_and_target.py renamed to tests/unit/model/data_preprocessing/test_prepare_features_and_target.py

File renamed without changes.
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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

Comments
 (0)