test_trigger_launcher.py 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import unittest
  2. import mock
  3. from kalliope.core.Models.Settings import Settings
  4. from kalliope.core.TriggerLauncher import TriggerLauncher
  5. from kalliope.core.Models.Trigger import Trigger
  6. class TestTriggerLauncher(unittest.TestCase):
  7. """
  8. Class to test Launchers Classes (TriggerLauncher) and methods
  9. """
  10. def setUp(self):
  11. pass
  12. ####
  13. # Trigger Launcher
  14. def test_get_trigger(self):
  15. """
  16. Test the Trigger Launcher trying to run the trigger
  17. """
  18. trigger1 = Trigger("Trigger", {})
  19. trigger2 = Trigger("Trigger2", {'pmdl_file': "trigger/snowboy/resources/kalliope-FR-6samples.pmdl"})
  20. settings = Settings()
  21. settings.triggers = [trigger1, trigger2]
  22. with mock.patch("kalliope.core.Utils.get_dynamic_class_instantiation") as mock_get_class_instantiation:
  23. # Get the trigger 1
  24. settings.default_trigger_name = "Trigger"
  25. TriggerLauncher.get_trigger(settings=settings,
  26. callback=None)
  27. mock_get_class_instantiation.assert_called_once_with(package_name="trigger",
  28. module_name=trigger1.name,
  29. parameters=trigger1.parameters)
  30. mock_get_class_instantiation.reset_mock()
  31. # Get the trigger 2
  32. settings.default_trigger_name = "Trigger2"
  33. TriggerLauncher.get_trigger(settings=settings,
  34. callback=None)
  35. mock_get_class_instantiation.assert_called_once_with(package_name="trigger",
  36. module_name=trigger2.name,
  37. parameters=trigger2.parameters)
  38. mock_get_class_instantiation.reset_mock()