first commi
This commit is contained in:
127
checker/scripts/test_structure.py
Normal file
127
checker/scripts/test_structure.py
Normal file
@@ -0,0 +1,127 @@
|
||||
#!/usr/bin/env python3
|
||||
"""快速测试脚本 - 验证新项目结构"""
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
# 添加src到路径
|
||||
src_path = Path(__file__).parent.parent / 'src'
|
||||
sys.path.insert(0, str(src_path))
|
||||
|
||||
from checker import Card, CheckStatus
|
||||
|
||||
def test_imports():
|
||||
"""测试所有模块导入"""
|
||||
print("🔍 测试模块导入...")
|
||||
|
||||
try:
|
||||
from checker.models import Card, CheckResult, BinInfo
|
||||
print("✅ models 模块导入成功")
|
||||
|
||||
from checker.utils import format_ts, generate_password, gstr
|
||||
print("✅ utils 模块导入成功")
|
||||
|
||||
from checker.cards import parse_card_file, lookup_bin
|
||||
print("✅ cards 模块导入成功")
|
||||
|
||||
from checker.checkers import StripeChecker
|
||||
print("✅ checkers 模块导入成功")
|
||||
|
||||
from checker.integrations import RecaptchaSolver, ProxyRotator
|
||||
print("✅ integrations 模块导入成功")
|
||||
|
||||
from checker.cli import main
|
||||
print("✅ cli 模块导入成功")
|
||||
|
||||
return True
|
||||
except Exception as e:
|
||||
print(f"❌ 导入失败: {e}")
|
||||
return False
|
||||
|
||||
|
||||
def test_card_model():
|
||||
"""测试卡片模型"""
|
||||
print("\n🔍 测试卡片模型...")
|
||||
|
||||
try:
|
||||
# 测试解析
|
||||
card = Card.parse("4111111111111111|12|2025|123")
|
||||
assert card.number == "4111111111111111"
|
||||
assert card.month == "12"
|
||||
assert card.year == "2025"
|
||||
assert card.cvv == "123"
|
||||
assert card.bin == "411111"
|
||||
print("✅ 卡片解析正常")
|
||||
|
||||
# 测试格式化
|
||||
formatted = card.formatted
|
||||
assert formatted == "4111111111111111|12|25|123"
|
||||
print("✅ 卡片格式化正常")
|
||||
|
||||
return True
|
||||
except Exception as e:
|
||||
print(f"❌ 卡片模型测试失败: {e}")
|
||||
return False
|
||||
|
||||
|
||||
def test_utils():
|
||||
"""测试工具函数"""
|
||||
print("\n🔍 测试工具函数...")
|
||||
|
||||
try:
|
||||
from checker.utils import generate_password, gstr
|
||||
|
||||
# 测试密码生成
|
||||
pwd = generate_password(10, 16)
|
||||
assert 10 <= len(pwd) <= 16
|
||||
print(f"✅ 密码生成正常: {pwd}")
|
||||
|
||||
# 测试字符串提取
|
||||
text = "prefix:EXTRACTED:suffix"
|
||||
result = gstr(text, "prefix:", ":suffix")
|
||||
assert result == "EXTRACTED"
|
||||
print("✅ 字符串提取正常")
|
||||
|
||||
return True
|
||||
except Exception as e:
|
||||
print(f"❌ 工具函数测试失败: {e}")
|
||||
return False
|
||||
|
||||
|
||||
def main():
|
||||
"""主测试函数"""
|
||||
print("=" * 60)
|
||||
print("🚀 Checker 项目结构测试")
|
||||
print("=" * 60)
|
||||
|
||||
results = []
|
||||
|
||||
# 运行测试
|
||||
results.append(("模块导入", test_imports()))
|
||||
results.append(("卡片模型", test_card_model()))
|
||||
results.append(("工具函数", test_utils()))
|
||||
|
||||
# 显示结果
|
||||
print("\n" + "=" * 60)
|
||||
print("📊 测试结果汇总")
|
||||
print("=" * 60)
|
||||
|
||||
for name, passed in results:
|
||||
status = "✅ 通过" if passed else "❌ 失败"
|
||||
print(f"{name:20s}: {status}")
|
||||
|
||||
all_passed = all(result[1] for result in results)
|
||||
|
||||
if all_passed:
|
||||
print("\n🎉 所有测试通过!项目结构正常。")
|
||||
print("\n下一步:")
|
||||
print(" 1. 安装依赖: uv pip install -e .")
|
||||
print(" 2. 运行程序: python -m checker")
|
||||
print(" 3. 或使用命令: checker")
|
||||
else:
|
||||
print("\n⚠️ 部分测试失败,请检查错误信息。")
|
||||
|
||||
return 0 if all_passed else 1
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
sys.exit(main())
|
||||
Reference in New Issue
Block a user