test_integration.py 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. #!/usr/bin/env python3
  2. """
  3. Integration test for Trixy voice assistant components.
  4. """
  5. import sys
  6. import time
  7. from trixy_core import create_application, DeploymentMode
  8. from trixy_core.events import EventType
  9. def test_basic_integration():
  10. """Test basic integration of all components."""
  11. print("=== Trixy Integration Test ===")
  12. try:
  13. # Create application
  14. print("1. Creating application...")
  15. app = create_application(mode=DeploymentMode.STANDALONE, debug_mode=True)
  16. # Start application
  17. print("2. Starting application...")
  18. app.start()
  19. # Test component access
  20. print("3. Testing component access...")
  21. event_handler = app.get_event_handler()
  22. config_manager = app.get_config_manager()
  23. plugin_system = app.get_plugin_system()
  24. network_manager = app.get_network_manager()
  25. scheduler = app.get_scheduler()
  26. conversation_manager = app.get_conversation_manager()
  27. asset_manager = app.get_asset_manager()
  28. arbitration_manager = app.get_arbitration_manager()
  29. print("✓ All components accessible")
  30. # Test event system
  31. print("4. Testing event system...")
  32. event_handler.trigger_event(EventType.SYSTEM_STARTUP)
  33. print("✓ Event triggered successfully")
  34. # Test asset manager
  35. print("5. Testing asset manager...")
  36. success_audio = asset_manager.get_path("audio/success.wav")
  37. print(f"✓ Asset found: {success_audio}")
  38. # Test configuration
  39. print("6. Testing configuration...")
  40. config = config_manager.get_config()
  41. print(f"✓ Config loaded: network ports={config.network.command_port}")
  42. # Test plugin system
  43. print("7. Testing plugin system...")
  44. plugin_count = len(plugin_system._plugins)
  45. print(f"✓ Plugins loaded: {plugin_count} plugins")
  46. # Test health check
  47. print("8. Testing health check...")
  48. health = app.get_health_report()
  49. print(f"✓ System healthy: {health['healthy']}")
  50. print("\n=== All Tests Passed! ===")
  51. return True
  52. except Exception as e:
  53. print(f"✗ Test failed: {e}")
  54. import traceback
  55. traceback.print_exc()
  56. return False
  57. finally:
  58. print("9. Shutting down...")
  59. try:
  60. app.shutdown()
  61. print("✓ Shutdown completed")
  62. except:
  63. pass
  64. def test_event_workflow():
  65. """Test a basic conversation workflow."""
  66. print("\n=== Testing Event Workflow ===")
  67. try:
  68. app = create_application(mode=DeploymentMode.STANDALONE, debug_mode=True)
  69. app.start()
  70. event_handler = app.get_event_handler()
  71. # Simulate wakeword detection
  72. print("1. Simulating wakeword detection...")
  73. from trixy_core.events.event_data import SpeakerInfo, SatelliteInfo
  74. speaker_info = SpeakerInfo(speaker_id="user1", speaker_name="Test User")
  75. satellite_info = SatelliteInfo(
  76. satellite_id="test_sat",
  77. mac_address="AA:BB:CC:DD:EE:FF",
  78. room_id="test_room",
  79. alias="Test Satellite",
  80. version="1.0.0"
  81. )
  82. event_handler.trigger_event(
  83. EventType.WAKEWORD_RECEIVED,
  84. wakeword_id="trixy",
  85. speaker_info=speaker_info,
  86. satellite_info=satellite_info,
  87. volume=0.8
  88. )
  89. print("✓ Wakeword event triggered")
  90. # Check event history
  91. history = event_handler.get_event_history(limit=5)
  92. print(f"✓ Event history contains {len(history)} events")
  93. print("=== Event Workflow Test Passed! ===")
  94. return True
  95. except Exception as e:
  96. print(f"✗ Event workflow test failed: {e}")
  97. import traceback
  98. traceback.print_exc()
  99. return False
  100. finally:
  101. try:
  102. app.shutdown()
  103. except:
  104. pass
  105. if __name__ == "__main__":
  106. success = True
  107. # Run basic integration test
  108. if not test_basic_integration():
  109. success = False
  110. # Run event workflow test
  111. if not test_event_workflow():
  112. success = False
  113. if success:
  114. print("\n🎉 All integration tests passed!")
  115. sys.exit(0)
  116. else:
  117. print("\n❌ Some tests failed!")
  118. sys.exit(1)