liurenchaxin/tests/test_openbb_fallback.py

27 lines
771 B
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
验证在未安装 OpenBB 时OpenBB Tab 的数据加载回退行为。
该测试不强制要求安装 OpenBB因此仅检查函数能返回非空 DataFrame。
"""
import importlib
import types
import pandas as pd
from app.tabs.openbb_tab import _load_price_data
def test_openbb_fallback_without_openbb():
# 尝试卸载 openbb 以模拟未安装环境(若本地未安装会抛错,忽略)
try:
if 'openbb' in list(importlib.sys.modules.keys()):
del importlib.sys.modules['openbb']
except Exception:
pass
df = _load_price_data('AAPL', 180)
assert isinstance(df, pd.DataFrame)
assert not df.empty
assert 'Date' in df.columns and 'Close' in df.columns