|
| 1 | +"""Targeted tests to cover previously uncovered code paths.""" |
| 2 | + |
| 3 | +import pandas as pd |
| 4 | + |
| 5 | +from bluecast.config.training_config import ( |
| 6 | + CatboostFinalParamConfig, |
| 7 | + CatboostRegressionFinalParamConfig, |
| 8 | + CatboostTuneParamsConfig, |
| 9 | + CatboostTuneParamsRegressionConfig, |
| 10 | + TrainingConfig, |
| 11 | + XgboostFinalParamConfig, |
| 12 | + XgboostRegressionFinalParamConfig, |
| 13 | + XgboostTuneParamsConfig, |
| 14 | + XgboostTuneParamsRegressionConfig, |
| 15 | +) |
| 16 | +from bluecast.preprocessing.train_test_split import train_test_split_time |
| 17 | + |
| 18 | + |
| 19 | +class TestConfigRepr: |
| 20 | + def test_training_config_repr(self): |
| 21 | + tc = TrainingConfig() |
| 22 | + r = repr(tc) |
| 23 | + assert "TrainingConfig(" in r |
| 24 | + assert "global_random_state=33" in r |
| 25 | + |
| 26 | + def test_xgboost_tune_params_repr(self): |
| 27 | + cfg = XgboostTuneParamsConfig() |
| 28 | + r = repr(cfg) |
| 29 | + assert "XgboostTuneParamsConfig(" in r |
| 30 | + assert "max_depth_min" in r |
| 31 | + |
| 32 | + def test_xgboost_tune_params_regression_repr(self): |
| 33 | + cfg = XgboostTuneParamsRegressionConfig() |
| 34 | + r = repr(cfg) |
| 35 | + assert "XgboostTuneParamsRegressionConfig(" in r |
| 36 | + |
| 37 | + def test_xgboost_final_param_repr(self): |
| 38 | + cfg = XgboostFinalParamConfig() |
| 39 | + r = repr(cfg) |
| 40 | + assert "XgboostFinalParamConfig(" in r |
| 41 | + assert "params=" in r |
| 42 | + |
| 43 | + def test_xgboost_regression_final_param_repr(self): |
| 44 | + cfg = XgboostRegressionFinalParamConfig() |
| 45 | + r = repr(cfg) |
| 46 | + assert "XgboostRegressionFinalParamConfig(" in r |
| 47 | + |
| 48 | + def test_catboost_tune_params_repr(self): |
| 49 | + cfg = CatboostTuneParamsConfig() |
| 50 | + r = repr(cfg) |
| 51 | + assert "CatboostTuneParamsConfig(" in r |
| 52 | + |
| 53 | + def test_catboost_tune_params_regression_repr(self): |
| 54 | + cfg = CatboostTuneParamsRegressionConfig() |
| 55 | + r = repr(cfg) |
| 56 | + assert "CatboostTuneParamsRegressionConfig(" in r |
| 57 | + |
| 58 | + def test_catboost_final_param_repr(self): |
| 59 | + cfg = CatboostFinalParamConfig() |
| 60 | + r = repr(cfg) |
| 61 | + assert "CatboostFinalParamConfig(" in r |
| 62 | + assert "params=" in r |
| 63 | + |
| 64 | + def test_catboost_regression_final_param_repr(self): |
| 65 | + cfg = CatboostRegressionFinalParamConfig() |
| 66 | + r = repr(cfg) |
| 67 | + assert "CatboostRegressionFinalParamConfig(" in r |
| 68 | + |
| 69 | + |
| 70 | +class TestShapWaterfallIndicesElseBranch: |
| 71 | + def test_shap_waterfall_indices_with_value(self): |
| 72 | + tc = TrainingConfig(shap_waterfall_indices=[0, 5, 99]) |
| 73 | + assert tc.shap_waterfall_indices == [0, 5, 99] |
| 74 | + |
| 75 | + def test_shap_waterfall_indices_default(self): |
| 76 | + tc = TrainingConfig() |
| 77 | + assert tc.shap_waterfall_indices == [] |
| 78 | + |
| 79 | + |
| 80 | +class TestTrainTestSplitTimeFString: |
| 81 | + def test_time_split_with_column(self): |
| 82 | + df = pd.DataFrame( |
| 83 | + {"a": range(50), "b": range(50), "order": range(50), "target": range(50)} |
| 84 | + ) |
| 85 | + x_train, x_test, y_train, y_test = train_test_split_time( |
| 86 | + df, "target", "order", 0.8 |
| 87 | + ) |
| 88 | + assert len(x_train) == 40 |
| 89 | + assert len(x_test) == 10 |
| 90 | + |
| 91 | + def test_time_split_without_column(self): |
| 92 | + df = pd.DataFrame({"a": range(50), "b": range(50), "target": range(50)}) |
| 93 | + x_train, x_test, y_train, y_test = train_test_split_time( |
| 94 | + df, "target", "", 0.8 |
| 95 | + ) |
| 96 | + assert len(x_train) == 40 |
| 97 | + assert len(x_test) == 10 |
0 commit comments