Files
daily_stock_analysis/tests/test_refresh_stock_index.py
LouisHong 43d05b4179 feat: Enhance A-share stock name correction and index generation (#1462)
- Improved `fetch_tushare_stock_list.py` to support A-share name corrections for stocks with prefixes XD/XR/DR/N/C using the `--a-rk` option.
- Updated documentation to reflect the new functionality and usage of the correction script.
- Added a new script `refresh_stock_index.py` to automate the fetching of stock lists and index generation.
- Implemented tests for the new features, ensuring the correct functionality of stock name corrections and index generation.
- Enhanced error handling for missing dependencies and improved user feedback during execution.
2026-05-25 20:26:24 +08:00

39 lines
1.1 KiB
Python

# -*- coding: utf-8 -*-
"""Tests for scripts.refresh_stock_index default fetch behavior."""
from __future__ import annotations
import importlib
import sys
from pathlib import Path
from unittest.mock import patch
ROOT = Path(__file__).resolve().parent.parent
SCRIPTS_DIR = ROOT / "scripts"
if str(SCRIPTS_DIR) not in sys.path:
sys.path.insert(0, str(SCRIPTS_DIR))
refresh_stock_index = importlib.import_module("refresh_stock_index")
def test_main_fetches_tushare_with_a_rk_by_default():
with (
patch.object(refresh_stock_index, "_has_tushare_token", return_value=True),
patch.object(refresh_stock_index, "_run") as run,
patch.object(refresh_stock_index, "_sync_static_index"),
):
exit_code = refresh_stock_index.main([])
assert exit_code == 0
assert run.call_args_list[0].args[0] == [
sys.executable,
"scripts/fetch_tushare_stock_list.py",
"--a-rk",
]
assert run.call_args_list[1].args[0] == [
sys.executable,
"scripts/generate_index_from_csv.py",
"--source",
"tushare",
]