run_all_tests.py 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. #!/usr/bin/env python3
  2. """
  3. Test Runner for Hyperliquid Trading Bot
  4. Runs all test modules and provides a summary of results.
  5. """
  6. import sys
  7. import os
  8. import importlib.util
  9. from pathlib import Path
  10. # Add the project root to the path
  11. project_root = Path(__file__).parent.parent
  12. sys.path.insert(0, str(project_root))
  13. sys.path.insert(0, str(project_root / 'src'))
  14. def run_test_module(test_file_path):
  15. """Run a single test module and return results."""
  16. test_name = test_file_path.stem
  17. try:
  18. print(f"\n{'='*60}")
  19. print(f"🧪 Running {test_name}")
  20. print(f"{'='*60}")
  21. # Load and execute the test module
  22. spec = importlib.util.spec_from_file_location(test_name, test_file_path)
  23. module = importlib.util.module_from_spec(spec)
  24. # Execute the module
  25. spec.loader.exec_module(module)
  26. # Try to find and run a main test function
  27. if hasattr(module, 'main') and callable(module.main):
  28. result = module.main()
  29. return test_name, result if isinstance(result, bool) else True
  30. elif hasattr(module, f'test_{test_name.replace("test_", "")}') and callable(getattr(module, f'test_{test_name.replace("test_", "")}')):
  31. func_name = f'test_{test_name.replace("test_", "")}'
  32. result = getattr(module, func_name)()
  33. return test_name, result if isinstance(result, bool) else True
  34. else:
  35. # If no specific test function, assume module execution was the test
  36. print(f"✅ {test_name} completed (no return value)")
  37. return test_name, True
  38. except Exception as e:
  39. print(f"❌ {test_name} failed: {e}")
  40. import traceback
  41. traceback.print_exc()
  42. return test_name, False
  43. def main():
  44. """Run all tests and provide summary."""
  45. print("🚀 Hyperliquid Trading Bot - Test Suite")
  46. print("="*60)
  47. # Find all test files
  48. tests_dir = Path(__file__).parent
  49. test_files = list(tests_dir.glob("test_*.py"))
  50. if not test_files:
  51. print("❌ No test files found!")
  52. return False
  53. print(f"📋 Found {len(test_files)} test files:")
  54. for test_file in test_files:
  55. print(f" • {test_file.name}")
  56. # Run all tests
  57. results = []
  58. for test_file in test_files:
  59. test_name, success = run_test_module(test_file)
  60. results.append((test_name, success))
  61. # Print summary
  62. print(f"\n{'='*60}")
  63. print(f"📊 TEST SUMMARY")
  64. print(f"{'='*60}")
  65. passed = sum(1 for _, success in results if success)
  66. failed = len(results) - passed
  67. print(f"✅ Passed: {passed}")
  68. print(f"❌ Failed: {failed}")
  69. print(f"📊 Total: {len(results)}")
  70. print(f"\n📋 Individual Results:")
  71. for test_name, success in results:
  72. status = "✅ PASS" if success else "❌ FAIL"
  73. print(f" {status} {test_name}")
  74. if failed == 0:
  75. print(f"\n🎉 ALL TESTS PASSED!")
  76. print(f"🚀 Bot is ready for deployment!")
  77. return True
  78. else:
  79. print(f"\n💥 {failed} TEST(S) FAILED!")
  80. print(f"🔧 Please fix failing tests before deployment.")
  81. return False
  82. if __name__ == "__main__":
  83. success = main()
  84. sys.exit(0 if success else 1)