log
2026-07-23 5401f10e1aa9cd98683b8f9639b0e9ac13b05f9a
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):