Files
flux1-edit/tests/run_tests.py
2025-08-26 02:35:44 +09:00

107 lines
3.2 KiB
Python

"""Test runner for all FLUX.1 Edit MCP Server tests"""
import unittest
import sys
from pathlib import Path
# Add src to path
sys.path.insert(0, str(Path(__file__).parent.parent / 'src'))
# Import all test modules
from test_config import TestConfig
from test_image_utils import TestImageUtils
from test_validation import TestValidation
from test_flux_client import TestFluxEditClient, TestFluxEditClientAsync
from test_handlers import TestToolHandlers
def create_test_suite():
"""Create and return the complete test suite"""
suite = unittest.TestSuite()
# Add all test cases
suite.addTest(unittest.makeSuite(TestConfig))
suite.addTest(unittest.makeSuite(TestImageUtils))
suite.addTest(unittest.makeSuite(TestValidation))
suite.addTest(unittest.makeSuite(TestFluxEditClient))
suite.addTest(unittest.makeSuite(TestFluxEditClientAsync))
suite.addTest(unittest.makeSuite(TestToolHandlers))
return suite
def run_tests():
"""Run all tests and return results"""
# Setup test runner
runner = unittest.TextTestRunner(
verbosity=2,
stream=sys.stdout,
descriptions=True,
failfast=False
)
# Create and run test suite
suite = create_test_suite()
result = runner.run(suite)
# Print summary
print(f"\n{'='*70}")
print("TEST SUMMARY")
print(f"{'='*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:")
for test, traceback in result.failures:
print(f" - {test}: {traceback.split('AssertionError: ')[-1].split()[0] if 'AssertionError:' in traceback else 'Unknown failure'}")
if result.errors:
print(f"\nERRORS:")
for test, traceback in result.errors:
error_msg = traceback.split('\n')[-2] if traceback.split('\n')[-2] else 'Unknown error'
print(f" - {test}: {error_msg}")
success = len(result.failures) == 0 and len(result.errors) == 0
print(f"\nOVERALL: {'✅ PASSED' if success else '❌ FAILED'}")
return success
def run_specific_test(test_name: str):
"""Run a specific test module"""
test_modules = {
'config': TestConfig,
'image_utils': TestImageUtils,
'validation': TestValidation,
'flux_client': TestFluxEditClient,
'flux_client_async': TestFluxEditClientAsync,
'handlers': TestToolHandlers
}
if test_name not in test_modules:
print(f"❌ Unknown test module: {test_name}")
print(f"Available modules: {', '.join(test_modules.keys())}")
return False
suite = unittest.makeSuite(test_modules[test_name])
runner = unittest.TextTestRunner(verbosity=2)
result = runner.run(suite)
return len(result.failures) == 0 and len(result.errors) == 0
if __name__ == '__main__':
# Check for specific test argument
if len(sys.argv) > 1:
test_name = sys.argv[1]
success = run_specific_test(test_name)
else:
# Run all tests
success = run_tests()
# Exit with appropriate code
sys.exit(0 if success else 1)