forked from cleveragents/cleveragents-core
2f69358dcf
All 3 simulations tested with the fixed generate prompt that passes the original DoD to the LLM. Results: - SIM12 (Rate Limiter): 7 files — algorithms.py, store.py, middleware.py, config.py, example_app.py, requirements.txt, __init__.py - SIM14 (JSON Validator): 6 files — validator.py, types.py, errors.py, cli.py, requirements.txt, __init__.py - SIM17 (API Tester): 7 files — runner.py, assertions.py, variables.py, reporter.py, cli.py, requirements.txt, test_suite_example.yaml All Python files pass compile() syntax check. All DoD files present. Files written directly via --output-dir, no manual cleanup needed.
98 lines
2.7 KiB
Python
98 lines
2.7 KiB
Python
import argparse
|
|
import sys
|
|
from runner import TestRunner
|
|
|
|
|
|
def main():
|
|
"""Command-line interface for HTTP API testing framework."""
|
|
parser = argparse.ArgumentParser(
|
|
description="HTTP API Testing Framework",
|
|
formatter_class=argparse.RawDescriptionHelpFormatter,
|
|
epilog="""
|
|
Examples:
|
|
python cli.py --suite tests.yaml
|
|
python cli.py --suite tests.yaml --base-url https://api.example.com
|
|
python cli.py --suite tests.yaml --base-url https://api.example.com --verbose
|
|
python cli.py --suite tests.yaml --output report.txt
|
|
"""
|
|
)
|
|
|
|
parser.add_argument(
|
|
'--suite',
|
|
required=True,
|
|
help='Path to YAML test suite file'
|
|
)
|
|
|
|
parser.add_argument(
|
|
'--base-url',
|
|
help='Base URL for API endpoints (can be overridden by suite file)'
|
|
)
|
|
|
|
parser.add_argument(
|
|
'--verbose', '-v',
|
|
action='store_true',
|
|
help='Show detailed test results including passed tests'
|
|
)
|
|
|
|
parser.add_argument(
|
|
'--output', '-o',
|
|
help='Save report to specified file'
|
|
)
|
|
|
|
parser.add_argument(
|
|
'--quiet', '-q',
|
|
action='store_true',
|
|
help='Suppress console output except for final summary'
|
|
)
|
|
|
|
args = parser.parse_args()
|
|
|
|
try:
|
|
# Initialize test runner
|
|
runner = TestRunner(base_url=args.base_url or "")
|
|
|
|
if not args.quiet:
|
|
print(f"Loading test suite: {args.suite}")
|
|
if args.base_url:
|
|
print(f"Base URL: {args.base_url}")
|
|
print("Starting test execution...")
|
|
print()
|
|
|
|
# Execute tests
|
|
reporter = runner.run_test_suite(args.suite)
|
|
|
|
# Generate and display report
|
|
if not args.quiet:
|
|
print(reporter.generate_report(verbose=args.verbose))
|
|
else:
|
|
reporter.print_summary()
|
|
|
|
# Save report to file if requested
|
|
if args.output:
|
|
reporter.save_report(args.output, verbose=args.verbose)
|
|
if not args.quiet:
|
|
print(f"Report saved to: {args.output}")
|
|
|
|
# Exit with appropriate code
|
|
failed_tests = len(reporter.get_failed_tests())
|
|
if failed_tests > 0:
|
|
sys.exit(1)
|
|
else:
|
|
sys.exit(0)
|
|
|
|
except FileNotFoundError as e:
|
|
print(f"Error: {e}", file=sys.stderr)
|
|
sys.exit(2)
|
|
except ValueError as e:
|
|
print(f"Error: {e}", file=sys.stderr)
|
|
sys.exit(2)
|
|
except KeyboardInterrupt:
|
|
print("\nTest execution interrupted by user", file=sys.stderr)
|
|
sys.exit(130)
|
|
except Exception as e:
|
|
print(f"Unexpected error: {e}", file=sys.stderr)
|
|
sys.exit(1)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
main() |