99import threading
1010import time
1111import unittest
12+ from datetime import datetime
1213from pathlib import Path
1314from types import SimpleNamespace
1415from unittest .mock import MagicMock , patch
@@ -49,7 +50,7 @@ def __init__(self):
4950
5051 def _save_report_to_file (self , content , filename = None ):
5152 self .saved_reports .append ((content , filename ))
52- return f"/tmp/{ filename or 'report_20260814 .md' } "
53+ return f"/tmp/{ filename or 'report .md' } "
5354
5455 def _send (
5556 self ,
@@ -89,6 +90,8 @@ def _make_result(code: str, success: bool = True) -> AnalysisResult:
8990
9091
9192class TestPipelineSingleStockNotify (unittest .TestCase ):
93+ _FROZEN_REPORT_TIME = datetime (2030 , 1 , 2 , 12 , 0 , 0 )
94+
9295 @staticmethod
9396 def _build_batch_pipeline () -> StockAnalysisPipeline :
9497 pipeline = StockAnalysisPipeline .__new__ (StockAnalysisPipeline )
@@ -146,19 +149,21 @@ def test_process_single_stock_direct_path_keeps_notify_compatibility(self):
146149 pipeline .analyze_stock = MagicMock (return_value = _make_result ("600519" ))
147150 pipeline .notifier = _TrackingNotifier ()
148151
149- result = pipeline .process_single_stock (
150- code = "600519" ,
151- skip_analysis = False ,
152- single_stock_notify = True ,
153- report_type = ReportType .BRIEF ,
154- analysis_query_id = "query-1" ,
155- )
152+ with patch ("src.core.pipeline.datetime" ) as mock_datetime :
153+ mock_datetime .now .return_value = self ._FROZEN_REPORT_TIME
154+ result = pipeline .process_single_stock (
155+ code = "600519" ,
156+ skip_analysis = False ,
157+ single_stock_notify = True ,
158+ report_type = ReportType .BRIEF ,
159+ analysis_query_id = "query-1" ,
160+ )
156161
157162 self .assertIsNotNone (result )
158163 pipeline .notifier .generate_brief_report .assert_called_once_with ([result ])
159164 save_call = pipeline .notifier .save_report_to_file .call_args
160165 self .assertEqual (save_call .args [0 ], "brief:600519" )
161- self .assertEqual (save_call .kwargs ["filename" ], "report_20260814_600519 .md" )
166+ self .assertEqual (save_call .kwargs ["filename" ], "report_20300102_600519 .md" )
162167 pipeline .notifier .send .assert_called_once_with (
163168 "brief:600519" ,
164169 email_stock_codes = ["600519" ],
@@ -175,18 +180,20 @@ def test_process_single_stock_saves_report_even_when_notifier_is_unavailable(sel
175180 pipeline .notifier = _TrackingNotifier ()
176181 pipeline .notifier .is_available .return_value = False
177182
178- result = pipeline .process_single_stock (
179- code = "600519" ,
180- skip_analysis = False ,
181- single_stock_notify = True ,
182- report_type = ReportType .SIMPLE ,
183- analysis_query_id = "query-1" ,
184- )
183+ with patch ("src.core.pipeline.datetime" ) as mock_datetime :
184+ mock_datetime .now .return_value = self ._FROZEN_REPORT_TIME
185+ result = pipeline .process_single_stock (
186+ code = "600519" ,
187+ skip_analysis = False ,
188+ single_stock_notify = True ,
189+ report_type = ReportType .SIMPLE ,
190+ analysis_query_id = "query-1" ,
191+ )
185192
186193 self .assertIsNotNone (result )
187194 save_call = pipeline .notifier .save_report_to_file .call_args
188195 self .assertEqual (save_call .args [0 ], "single:600519" )
189- self .assertEqual (save_call .kwargs ["filename" ], "report_20260814_600519 .md" )
196+ self .assertEqual (save_call .kwargs ["filename" ], "report_20300102_600519 .md" )
190197 pipeline .notifier .send .assert_not_called ()
191198
192199 def test_process_single_stock_updates_saved_diagnostics_after_notification (self ):
0 commit comments