mirror of
https://github.com/TauricResearch/TradingAgents.git
synced 2026-09-27 06:56:39 +03:00
test(ohlcv): stamp cache mtimes in local time (#1372)
- the cache reads mtimes back in local time; the tests wrote them as UTC
This commit is contained in:
@@ -18,11 +18,17 @@ NOW = pd.Timestamp("2026-07-18 12:00")
|
||||
STALE = su.OHLCV_CACHE_TTL_SECONDS + 60
|
||||
|
||||
|
||||
def _stamp(path, ts):
|
||||
"""Set ``path``'s mtime to the wall-clock ``ts``, read back in local time as
|
||||
the cache does. A naive ``pd.Timestamp.timestamp()`` would be taken as UTC."""
|
||||
t = ts.to_pydatetime().timestamp()
|
||||
os.utime(path, (t, t))
|
||||
|
||||
|
||||
def _write(tmp_path, name="AAPL-YFin-data.csv", age_seconds=0.0, last_date="2026-07-17"):
|
||||
f = tmp_path / name
|
||||
pd.DataFrame({"Date": [last_date], "Close": [100.0]}).to_csv(f, index=False)
|
||||
written = NOW.timestamp() - age_seconds
|
||||
os.utime(f, (written, written))
|
||||
_stamp(f, NOW - pd.Timedelta(seconds=age_seconds))
|
||||
return f
|
||||
|
||||
|
||||
@@ -99,7 +105,7 @@ def test_one_cache_file_per_symbol_across_days(tmp_path, monkeypatch):
|
||||
monkeypatch.setattr(su.pd.Timestamp, "today", staticmethod(lambda now=now: now))
|
||||
su.load_ohlcv("AAPL", "2026-07-17")
|
||||
written = list(tmp_path.glob("AAPL-*.csv"))
|
||||
os.utime(written[0], (now.timestamp(), now.timestamp()))
|
||||
_stamp(written[0], now)
|
||||
|
||||
assert len(downloads) == 3, "each new day refetches"
|
||||
assert [p.name for p in tmp_path.iterdir()] == ["AAPL-YFin-data.csv"]
|
||||
|
||||
Reference in New Issue
Block a user