85 lines
2.3 KiB
Python
85 lines
2.3 KiB
Python
"""
|
|
Test runner for pyWebLayout.
|
|
|
|
This script runs all unit tests and provides a summary of results.
|
|
"""
|
|
|
|
import unittest
|
|
import sys
|
|
import os
|
|
|
|
# Add the project root to the Python path
|
|
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
|
|
|
|
|
def run_all_tests():
|
|
"""Run all unit tests and return the result."""
|
|
# Discover and run all tests
|
|
loader = unittest.TestLoader()
|
|
start_dir = os.path.dirname(os.path.abspath(__file__))
|
|
suite = loader.discover(start_dir, pattern='test_*.py')
|
|
|
|
# Run tests with detailed output
|
|
runner = unittest.TextTestRunner(
|
|
verbosity=2,
|
|
stream=sys.stdout,
|
|
descriptions=True,
|
|
failfast=False
|
|
)
|
|
|
|
result = runner.run(suite)
|
|
|
|
# Print summary
|
|
print("\n" + "="*70)
|
|
print("TEST SUMMARY")
|
|
print("="*70)
|
|
print(f"Tests run: {result.testsRun}")
|
|
print(f"Failures: {len(result.failures)}")
|
|
print(f"Errors: {len(result.errors)}")
|
|
print(f"Skipped: {len(result.skipped) if hasattr(result, 'skipped') else 0}")
|
|
|
|
if result.failures:
|
|
print(f"\nFAILURES ({len(result.failures)}):")
|
|
for test, traceback in result.failures:
|
|
print(f"- {test}")
|
|
|
|
if result.errors:
|
|
print(f"\nERRORS ({len(result.errors)}):")
|
|
for test, traceback in result.errors:
|
|
print(f"- {test}")
|
|
|
|
success = len(result.failures) == 0 and len(result.errors) == 0
|
|
print(f"\nResult: {'PASSED' if success else 'FAILED'}")
|
|
print("="*70)
|
|
|
|
return success
|
|
|
|
|
|
def run_specific_test(test_module):
|
|
"""Run a specific test module."""
|
|
loader = unittest.TestLoader()
|
|
suite = loader.loadTestsFromName(test_module)
|
|
|
|
runner = unittest.TextTestRunner(verbosity=2)
|
|
result = runner.run(suite)
|
|
|
|
return len(result.failures) == 0 and len(result.errors) == 0
|
|
|
|
|
|
if __name__ == '__main__':
|
|
if len(sys.argv) > 1:
|
|
# Run specific test
|
|
test_name = sys.argv[1]
|
|
if not test_name.startswith('test_'):
|
|
test_name = f'test_{test_name}'
|
|
if not test_name.endswith('.py'):
|
|
test_name = f'{test_name}.py'
|
|
|
|
module_name = test_name[:-3] # Remove .py extension
|
|
success = run_specific_test(module_name)
|
|
else:
|
|
# Run all tests
|
|
success = run_all_tests()
|
|
|
|
sys.exit(0 if success else 1)
|