| | |
| | | sys.path.insert(0, str(PROJECT_ROOT)) |
| | | |
| | | a_stock_manager = importlib.import_module("a_stock_manager") |
| | | ml_trainer = importlib.import_module("scripts.train_ml_factor_model") |
| | | |
| | | |
| | | class AStockManagerRunScriptTests(unittest.TestCase): |
| | |
| | | args=["--full", "--n-stocks", "all", "--days", "730"], |
| | | ) |
| | | |
| | | def test_ml_menu_runs_real_training_entrypoint(self): |
| | | training_result = { |
| | | "success": True, |
| | | "approved": True, |
| | | "message": "训练完成并已发布", |
| | | "metrics": { |
| | | "ic_mean": 0.03, |
| | | "valid_ic_days": 20, |
| | | "ic_positive_rate": 0.6, |
| | | "mae": 0.01, |
| | | }, |
| | | } |
| | | with patch( |
| | | "builtins.input", |
| | | side_effect=["1", "3"], |
| | | ), patch.object( |
| | | ml_trainer, |
| | | "train_and_save_model", |
| | | return_value=training_result, |
| | | ) as train: |
| | | a_stock_manager.ml_factor_combiner() |
| | | |
| | | train.assert_called_once_with(model_type="ridge") |
| | | |
| | | |
| | | if __name__ == "__main__": |
| | | unittest.main() |