Spaces:
Sleeping
Sleeping
Download app/tools/test_forge/routes.py from Moealsarraj/devkit: direct link, hf CLI and curl.
- Browser
- Download file 1.34 kB
-
https://huggingface.co/spaces/Moealsarraj/devkit/resolve/main/app/tools/test_forge/routes.py
- Command line
-
hf download hf://spaces/Moealsarraj/devkit/app/tools/test_forge/routes.py
-
curl -L -o routes.py https://huggingface.co/spaces/Moealsarraj/devkit/resolve/main/app/tools/test_forge/routes.py
1.34 kB
| """Test Forge routes.""" | |
| from flask import Blueprint, render_template, request, jsonify | |
| from .forge import generate_tests | |
| bp = Blueprint("test_forge", __name__, template_folder="templates") | |
| SUPPORTED_FRAMEWORKS = { | |
| "TypeScript / Jest", | |
| "Python / pytest", | |
| "JavaScript / Mocha", | |
| "Java / JUnit", | |
| "Go / testing", | |
| "Ruby / RSpec", | |
| "PHP / PHPUnit", | |
| "C# / xUnit", | |
| } | |
| def index(): | |
| return render_template("test_forge/index.html") | |
| def api_generate(): | |
| body = request.get_json(silent=True) or {} | |
| source_code = (body.get("source_code") or "").strip() | |
| framework = (body.get("framework") or "Python / pytest").strip() | |
| instructions = (body.get("instructions") or "").strip() | |
| if not source_code: | |
| return jsonify({"error": "source_code is required — paste your code"}), 400 | |
| if len(source_code) < 20: | |
| return jsonify({"error": "Source code too short — paste a real function or class"}), 400 | |
| if framework not in SUPPORTED_FRAMEWORKS: | |
| return jsonify({"error": f"Unsupported framework: {framework}"}), 400 | |
| result = generate_tests(source_code, framework, instructions) | |
| if not result: | |
| return jsonify({"error": "AI failed to generate tests — please try again"}), 502 | |
| return jsonify(result) | |