From c9a0711438d32f33b65ffa29d8efd7aa37d61bdc Mon Sep 17 00:00:00 2001
From: log
Date: Thu, 23 Jul 2026 21:54:18 +0800
Subject: [PATCH] feat: add validated ML factor model training

---
 tests/test_incremental_update.py |   50 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 50 insertions(+), 0 deletions(-)

diff --git a/tests/test_incremental_update.py b/tests/test_incremental_update.py
index 56322d4..b7603c6 100644
--- a/tests/test_incremental_update.py
+++ b/tests/test_incremental_update.py
@@ -179,6 +179,56 @@
         fetch.assert_called_once()
         write_pickle.assert_called_once()
 
+    def test_incremental_update_removes_currently_excluded_stocks(self):
+        existing = pd.DataFrame([
+            {
+                "date": "2026-07-10",
+                "stock_code": "600001",
+                "stock_name": "历史正常名称",
+                "close": 10.0,
+            },
+            {
+                "date": "2026-07-10",
+                "stock_code": "000001",
+                "stock_name": "平安银行",
+                "close": 11.0,
+            },
+        ])
+        fetched = existing.loc[
+            existing["stock_code"] == "000001"
+        ].copy()
+        fetched.attrs["excluded_security_codes"] = ["600001"]
+        fetched.attrs["excluded_st_count"] = 1
+        fetched.attrs["excluded_delisted_count"] = 0
+
+        with tempfile.TemporaryDirectory() as temp_dir:
+            data_file = Path(temp_dir) / "stock.pkl"
+            with data_file.open("wb") as handle:
+                pickle.dump(existing, handle)
+
+            args = incremental.parse_args([])
+            with patch.object(incremental, "DATA_FILE", data_file), patch.object(
+                incremental,
+                "latest_expected_business_date",
+                return_value=pd.Timestamp("2026-07-10"),
+            ), patch.object(
+                incremental.data_source,
+                "fetch_real_stock_data_from_akshare",
+                return_value=fetched,
+            ), patch.object(
+                incremental, "write_pickle_atomic"
+            ) as write_pickle, patch.object(
+                incremental, "write_json_atomic"
+            ) as write_json:
+                result = incremental.run_incremental_update(args)
+
+        self.assertEqual(result, 0)
+        written = write_pickle.call_args.args[0]
+        self.assertEqual(written["stock_code"].unique().tolist(), ["000001"])
+        metadata = write_json.call_args.args[0]
+        self.assertEqual(metadata["excluded_st_count"], 1)
+        self.assertEqual(metadata["removed_ineligible_record_count"], 1)
+
 
 class SafeResetTests(unittest.TestCase):
     def test_reset_moves_generated_files_to_timestamped_backup(self):

--
Gitblit v1.8.0