Aniworld/tests/unit/web/run_tests.py

108 lines
3.0 KiB
Python

"""
Test runner for the AniWorld server test suite.
This script runs all test modules and provides a comprehensive report.
"""
import unittest
import sys
import os
from io import StringIO
# Add parent directory to path for imports
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
def run_all_tests():
"""Run all test modules and provide a summary report."""
print("=" * 60)
print("AniWorld Server Test Suite")
print("=" * 60)
# Discover and run all tests
loader = unittest.TestLoader()
test_dir = os.path.dirname(os.path.abspath(__file__))
# Load all test modules
suite = loader.discover(test_dir, pattern='test_*.py')
# Run tests with detailed output
stream = StringIO()
runner = unittest.TextTestRunner(
stream=stream,
verbosity=2,
buffer=True
)
result = runner.run(suite)
# Print results
output = stream.getvalue()
print(output)
# Summary
print("\n" + "=" * 60)
print("TEST SUMMARY")
print("=" * 60)
total_tests = result.testsRun
failures = len(result.failures)
errors = len(result.errors)
skipped = len(result.skipped) if hasattr(result, 'skipped') else 0
passed = total_tests - failures - errors - skipped
print(f"Total Tests Run: {total_tests}")
print(f"Passed: {passed}")
print(f"Failed: {failures}")
print(f"Errors: {errors}")
print(f"Skipped: {skipped}")
if result.wasSuccessful():
print("\n🎉 ALL TESTS PASSED! 🎉")
print("✅ No JavaScript or CSS generation issues found!")
print("✅ All manager classes working correctly!")
print("✅ Authentication system validated!")
return True
else:
print("\n❌ Some tests failed. Please check the output above.")
if result.failures:
print(f"\nFailures ({len(result.failures)}):")
for test, traceback in result.failures:
print(f" - {test}: {traceback.split(chr(10))[-2]}")
if result.errors:
print(f"\nErrors ({len(result.errors)}):")
for test, traceback in result.errors:
print(f" - {test}: {traceback.split(chr(10))[-2]}")
return False
def run_specific_test_module(module_name):
"""Run a specific test module."""
print(f"Running tests from module: {module_name}")
print("-" * 40)
loader = unittest.TestLoader()
suite = loader.loadTestsFromName(module_name)
runner = unittest.TextTestRunner(verbosity=2, buffer=True)
result = runner.run(suite)
return result.wasSuccessful()
if __name__ == '__main__':
if len(sys.argv) > 1:
# Run specific test module
module_name = sys.argv[1]
success = run_specific_test_module(module_name)
else:
# Run all tests
success = run_all_tests()
# Exit with appropriate code
sys.exit(0 if success else 1)