Files
chinese-equity-quant/tests/test_downloader.py
T
2026-06-16 17:37:16 +08:00

43 lines
1.3 KiB
Python

import os
import pytest
from data.downloader import download_daily
pytestmark = [
pytest.mark.network,
pytest.mark.skipif(
os.environ.get("CEQ_RUN_LIVE_DOWNLOADER") != "1",
reason="set CEQ_RUN_LIVE_DOWNLOADER=1 to run live baostock/akshare smoke tests",
),
]
def test_download_single_stock():
"""Smoke test: download data for 浦发银行 for a short window."""
df = download_daily("sh600000", "2024-01-01", "2024-01-31")
assert df is not None
assert len(df) > 0
assert list(df.columns) == ["symbol", "date", "open", "high", "low", "close", "volume", "amount"]
assert df["close"].notna().all()
def test_download_baostock_primary():
"""baostock is the primary source for 'auto'."""
df = download_daily("sz000001", "2024-06-01", "2024-06-15", source="baostock")
assert df is not None
assert len(df) > 0
def test_download_akshare_fallback():
"""akshare works as the secondary source when reachable.
akshare is the fallback precisely because it is unreliable on some
networks; skip rather than fail when it cannot be reached.
"""
try:
df = download_daily("sh600000", "2024-01-01", "2024-01-31", source="akshare")
except RuntimeError as e:
pytest.skip(f"akshare unreachable on this network: {e}")
assert df is not None
assert len(df) > 0