Download local_test.py from cefrefdwe/warp-proxy-test-1769392021: direct link, hf CLI and curl.
- Browser
- Download file 5.16 kB
-
https://huggingface.co/spaces/cefrefdwe/warp-proxy-test-1769392021/resolve/main/local_test.py
- Command line
-
hf download hf://spaces/cefrefdwe/warp-proxy-test-1769392021/local_test.py
-
curl -L -o local_test.py https://huggingface.co/spaces/cefrefdwe/warp-proxy-test-1769392021/resolve/main/local_test.py
5.16 kB
| #!/usr/bin/env python3 | |
| # -*- coding: utf-8 -*- | |
| """ | |
| 本地测试脚本 - 验证代码和配置 | |
| """ | |
| import subprocess | |
| import sys | |
| import os | |
| def test_syntax(): | |
| """测试 Python 语法""" | |
| print("=" * 50) | |
| print("🧪 语法检查") | |
| print("=" * 50) | |
| files = ["server.py", "worker.py"] | |
| all_pass = True | |
| for f in files: | |
| result = subprocess.run( | |
| [sys.executable, "-m", "py_compile", f], | |
| capture_output=True, | |
| text=True | |
| ) | |
| if result.returncode == 0: | |
| print(f"✅ {f} 语法正确") | |
| else: | |
| print(f"❌ {f} 语法错误: {result.stderr}") | |
| all_pass = False | |
| return all_pass | |
| def test_imports(): | |
| """测试导入""" | |
| print("\n" + "=" * 50) | |
| print("🧪 依赖检查") | |
| print("=" * 50) | |
| # 检查 Flask | |
| try: | |
| import flask | |
| print(f"✅ Flask {flask.__version__}") | |
| except ImportError: | |
| print("⚠️ Flask 未安装 (Docker 会自动安装)") | |
| # 检查 aiohttp | |
| try: | |
| import aiohttp | |
| print(f"✅ aiohttp {aiohttp.__version__}") | |
| except ImportError: | |
| print("⚠️ aiohttp 未安装 (Docker 会自动安装)") | |
| # 检查 Playwright | |
| try: | |
| import playwright | |
| print(f"✅ Playwright 已安装") | |
| except ImportError: | |
| print("⚠️ Playwright 未安装 (Docker 会自动安装)") | |
| return True | |
| def test_dockerfile(): | |
| """测试 Dockerfile""" | |
| print("\n" + "=" * 50) | |
| print("🧪 Dockerfile 检查") | |
| print("=" * 50) | |
| with open("Dockerfile", "r") as f: | |
| content = f.read() | |
| checks = [ | |
| ("FROM python:3.9-slim", "基础镜像"), | |
| ("playwright install chromium", "Playwright 浏览器"), | |
| ("useradd -m -u 1000 user", "普通用户"), | |
| ("EXPOSE 7860", "端口暴露"), | |
| ("supervisord", "进程管理"), | |
| ] | |
| all_pass = True | |
| for keyword, desc in checks: | |
| if keyword in content: | |
| print(f"✅ {desc}") | |
| else: | |
| print(f"❌ 缺少: {desc}") | |
| all_pass = False | |
| return all_pass | |
| def test_supervisord(): | |
| """测试 supervisord.conf""" | |
| print("\n" + "=" * 50) | |
| print("🧪 Supervisord 配置检查") | |
| print("=" * 50) | |
| with open("supervisord.conf", "r") as f: | |
| content = f.read() | |
| checks = [ | |
| ("[supervisord]", "主配置"), | |
| ("[program:fake-website]", "Web 服务"), | |
| ("[program:adfoc-worker]", "Worker 进程"), | |
| ("autostart=true", "自动启动"), | |
| ("autorestart=true", "自动重启"), | |
| ] | |
| all_pass = True | |
| for keyword, desc in checks: | |
| if keyword in content: | |
| print(f"✅ {desc}") | |
| else: | |
| print(f"❌ 缺少: {desc}") | |
| all_pass = False | |
| return all_pass | |
| def test_worker_config(): | |
| """测试 Worker 配置""" | |
| print("\n" + "=" * 50) | |
| print("🧪 Worker 配置检查") | |
| print("=" * 50) | |
| with open("worker.py", "r") as f: | |
| content = f.read() | |
| checks = [ | |
| ("ADFOC_URL", "AdFoc 链接配置"), | |
| ("FreeProxyManager", "代理管理器"), | |
| ("BrowserFingerprint", "指纹生成器"), | |
| ("HumanBehavior", "行为模拟"), | |
| ("StealthMode", "反检测模式"), | |
| ("AdaptiveFrequencyController", "频率控制"), | |
| ("RevenueTracker", "收益统计"), | |
| ("AdFocAutomation", "自动化核心"), | |
| ] | |
| all_pass = True | |
| for keyword, desc in checks: | |
| if keyword in content: | |
| print(f"✅ {desc}") | |
| else: | |
| print(f"❌ 缺少: {desc}") | |
| all_pass = False | |
| return all_pass | |
| def main(): | |
| """运行所有测试""" | |
| print("\n" + "🚀" * 20) | |
| print(" 无限制容器工具 - 本地测试") | |
| print("🚀" * 20 + "\n") | |
| os.chdir(os.path.dirname(os.path.abspath(__file__))) | |
| results = [] | |
| results.append(("语法检查", test_syntax())) | |
| results.append(("依赖检查", test_imports())) | |
| results.append(("Dockerfile", test_dockerfile())) | |
| results.append(("Supervisord", test_supervisord())) | |
| results.append(("Worker 配置", test_worker_config())) | |
| # 汇总 | |
| print("\n" + "=" * 50) | |
| print("📊 测试结果") | |
| print("=" * 50) | |
| all_pass = True | |
| for name, passed in results: | |
| status = "✅ 通过" if passed else "❌ 失败" | |
| print(f" {name}: {status}") | |
| if not passed: | |
| all_pass = False | |
| print("\n" + "=" * 50) | |
| if all_pass: | |
| print("🎉 所有测试通过!") | |
| print("\n📝 下一步:") | |
| print(" 1. 修改 worker.py 中的 ADFOC_URL 为您的链接") | |
| print(" 2. 启动 Docker Desktop") | |
| print(" 3. 运行: docker build -t adfoc-auto .") | |
| print(" 4. 运行: docker run -p 7860:7860 adfoc-auto") | |
| print(" 5. 或直接部署到 Hugging Face Spaces") | |
| else: | |
| print("⚠️ 部分测试失败,请检查上述错误") | |
| print("=" * 50) | |
| return 0 if all_pass else 1 | |
| if __name__ == "__main__": | |
| sys.exit(main()) | |