37 lines
1.2 KiB
Python
37 lines
1.2 KiB
Python
import sys
|
||
import os
|
||
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
|
||
|
||
# 导入必要的模块
|
||
from config_juxiting import db_mysql, logger
|
||
from lib.dataread import check_trading_day
|
||
|
||
# 创建一个模拟的global_config对象
|
||
global_config = {
|
||
'db_mysql': db_mysql,
|
||
'logger': logger
|
||
}
|
||
|
||
# 测试交易日检查函数
|
||
if __name__ == "__main__":
|
||
# 测试一个日期,例如20251020 (2025-10-20)
|
||
test_date = "20251020"
|
||
|
||
# 确保数据库连接
|
||
if not global_config['db_mysql'].is_connected():
|
||
global_config['db_mysql'].connect()
|
||
print("数据库连接成功")
|
||
|
||
# 检查交易日
|
||
is_trading = check_trading_day(test_date, global_config)
|
||
print(f"日期 {test_date} 是否为交易日: {is_trading}")
|
||
|
||
# 测试数据库查询失败的情况(模拟)
|
||
print("\n测试数据库查询失败的情况:")
|
||
# 创建一个模拟的数据库配置对象,不包含有效的数据库连接
|
||
mock_global_config = {
|
||
'db_mysql': None,
|
||
'logger': logger
|
||
}
|
||
is_trading_default = check_trading_day(test_date, mock_global_config)
|
||
print(f"数据库查询失败时,日期 {test_date} 是否为交易日: {is_trading_default}") |