mirror of
https://github.com/TauricResearch/TradingAgents.git
synced 2026-09-27 15:02: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"]
|
||||
|
||||
@@ -21,6 +21,13 @@ import pytest
|
||||
from tradingagents.dataflows import stockstats_utils as su
|
||||
from tradingagents.dataflows.symbol_utils import NoMarketDataError
|
||||
|
||||
|
||||
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))
|
||||
|
||||
# --- date normalization -----------------------------------------------------
|
||||
|
||||
@pytest.mark.unit
|
||||
@@ -93,7 +100,7 @@ def _run_load(monkeypatch, tmp_path, frame, curr_date):
|
||||
monkeypatch.setattr(su.pd.Timestamp, "today", staticmethod(lambda: today))
|
||||
cache_file = tmp_path / "AAPL-YFin-data.csv"
|
||||
cache_file.write_text(frame.to_csv(index=False))
|
||||
os.utime(cache_file, (today.timestamp(), today.timestamp()))
|
||||
_stamp(cache_file, today)
|
||||
|
||||
def _fail_download(*a, **k):
|
||||
raise AssertionError("should use the seeded cache, not download")
|
||||
@@ -189,7 +196,7 @@ def test_the_snapshot_does_not_present_a_filled_price_as_reported(monkeypatch, t
|
||||
monkeypatch.setattr(su.pd.Timestamp, "today", staticmethod(lambda: today))
|
||||
cache = tmp_path / "AAPL-YFin-data.csv"
|
||||
cache.write_text(frame.to_csv(index=False))
|
||||
os.utime(cache, (today.timestamp(), today.timestamp()))
|
||||
_stamp(cache, today)
|
||||
monkeypatch.setattr(su.yf, "download", lambda *a, **k: (_ for _ in ()).throw(
|
||||
AssertionError("should read the seeded cache")))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user