71 lines
2.0 KiB
Python
71 lines
2.0 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
测试配置加载功能
|
|
"""
|
|
|
|
import sys
|
|
import os
|
|
sys.path.append(os.path.dirname(__file__))
|
|
|
|
from config_model import AppConfig
|
|
from pathlib import Path
|
|
|
|
def test_config_load():
|
|
"""测试配置加载"""
|
|
print("🧪 测试配置加载功能")
|
|
|
|
config_path = Path("default.json")
|
|
|
|
if not config_path.exists():
|
|
print("❌ default.json 不存在")
|
|
return
|
|
|
|
try:
|
|
# 加载配置
|
|
config = AppConfig.load(config_path)
|
|
|
|
print("✅ 配置加载成功")
|
|
print(f"📋 InfluxDB配置:")
|
|
print(f" URL: {config.influx.url}")
|
|
print(f" Org: {config.influx.org}")
|
|
print(f" Token: {config.influx.token[:20]}..." if config.influx.token else " Token: N/A")
|
|
print(f" Username: {config.influx.username}")
|
|
print(f" Password: {config.influx.password}")
|
|
print(f" Landing URL: {config.influx.landingUrl}")
|
|
|
|
# 测试bucket和measurement字段
|
|
bucket = getattr(config.influx, 'bucket', 'DEFAULT')
|
|
measurement = getattr(config.influx, 'measurement', 'DEFAULT')
|
|
|
|
print(f" Bucket: {bucket}")
|
|
print(f" Measurement: {measurement}")
|
|
|
|
# 检查是否有这些属性
|
|
has_bucket = hasattr(config.influx, 'bucket')
|
|
has_measurement = hasattr(config.influx, 'measurement')
|
|
|
|
print(f"\n🔍 属性检查:")
|
|
print(f" 有bucket属性: {has_bucket}")
|
|
print(f" 有measurement属性: {has_measurement}")
|
|
|
|
if has_bucket and has_measurement:
|
|
print("✅ 所有必要属性都存在")
|
|
else:
|
|
print("⚠️ 某些属性缺失")
|
|
|
|
return True
|
|
|
|
except Exception as e:
|
|
print(f"❌ 配置加载失败: {e}")
|
|
import traceback
|
|
traceback.print_exc()
|
|
return False
|
|
|
|
def main():
|
|
print("配置加载测试工具")
|
|
print("=" * 30)
|
|
test_config_load()
|
|
|
|
if __name__ == "__main__":
|
|
main()
|