test_settings_loader.py 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. import platform
  2. import unittest
  3. from kalliope.core.ConfigurationManager import SettingLoader
  4. from kalliope.core.Models import Singleton
  5. from kalliope.core.Models.RestAPI import RestAPI
  6. from kalliope.core.Models.Settings import Settings
  7. from kalliope.core.Models.Stt import Stt
  8. from kalliope.core.Models.Trigger import Trigger
  9. from kalliope.core.Models.Tts import Tts
  10. class TestSettingLoader(unittest.TestCase):
  11. def setUp(self):
  12. self.settings_file_to_test = "../Tests/settings/settings_test.yml"
  13. self.settings_dict = {
  14. 'rest_api':
  15. {'active': True,
  16. 'login': 'admin',
  17. 'password': 'secret',
  18. 'password_protected': True,
  19. 'port': 5000},
  20. 'default_trigger': 'snowboy',
  21. 'triggers': [{'snowboy': {'pmdl_file': 'trigger/snowboy/resources/kalliope-FR-6samples.pmdl'}}],
  22. 'speech_to_text': [{'google': {'language': 'fr-FR'}}],
  23. 'cache_path': '/tmp/kalliope_tts_cache',
  24. 'random_wake_up_answers': ['Oui monsieur?'],
  25. 'default_text_to_speech': 'pico2wave',
  26. 'default_speech_to_text': 'google',
  27. 'random_wake_up_sounds': ['ding.wav', 'dong.wav'],
  28. 'text_to_speech': [
  29. {'pico2wave': {'cache': True, 'language': 'fr-FR'}},
  30. {'voxygen': {'voice': 'Agnes', 'cache': True}}
  31. ]
  32. }
  33. def tearDown(self):
  34. Singleton._instances = {}
  35. def test_singleton(self):
  36. s1 = SettingLoader(file_path=self.settings_file_to_test)
  37. s2 = SettingLoader(file_path=self.settings_file_to_test)
  38. self.assertTrue(s1.settings is s2.settings)
  39. del s1
  40. del s2
  41. def test_get_yaml_config(self):
  42. sl = SettingLoader(file_path=self.settings_file_to_test)
  43. self.assertEqual(sl.yaml_config, self.settings_dict)
  44. del sl
  45. def test_get_settings(self):
  46. settings_object = Settings()
  47. settings_object.default_tts_name = "pico2wave"
  48. settings_object.default_stt_name = "google"
  49. settings_object.default_trigger_name = "snowboy"
  50. tts1 = Tts(name="pico2wave", parameters={'cache': True, 'language': 'fr-FR'})
  51. tts2 = Tts(name="voxygen", parameters={'voice': 'Agnes', 'cache': True})
  52. settings_object.ttss = [tts1, tts2]
  53. stt = Stt(name="google", parameters={'language': 'fr-FR'})
  54. settings_object.stts = [stt]
  55. settings_object.random_wake_up_answers = ['Oui monsieur?']
  56. settings_object.random_wake_up_sounds = ['ding.wav', 'dong.wav']
  57. trigger1 = Trigger(name="snowboy",
  58. parameters={'pmdl_file': 'trigger/snowboy/resources/kalliope-FR-6samples.pmdl'})
  59. settings_object.triggers = [trigger1]
  60. settings_object.rest_api = RestAPI(password_protected=True, active=True,
  61. login="admin", password="secret", port=5000)
  62. settings_object.cache_path = '/tmp/kalliope_tts_cache'
  63. settings_object.machine = platform.machine()
  64. sl = SettingLoader(file_path=self.settings_file_to_test)
  65. self.assertEqual(settings_object, sl.settings)
  66. del sl
  67. def test_get_default_speech_to_text(self):
  68. expected_default_speech_to_text = "google"
  69. sl = SettingLoader(file_path=self.settings_file_to_test)
  70. self.assertEqual(expected_default_speech_to_text, sl._get_default_speech_to_text(self.settings_dict))
  71. del sl
  72. def test_get_default_text_to_speech(self):
  73. expected_default_text_to_speech = "pico2wave"
  74. sl = SettingLoader(file_path=self.settings_file_to_test)
  75. self.assertEqual(expected_default_text_to_speech, sl._get_default_text_to_speech(self.settings_dict))
  76. del sl
  77. def test_get_default_trigger(self):
  78. expected_default_trigger = "snowboy"
  79. sl = SettingLoader(file_path=self.settings_file_to_test)
  80. self.assertEqual(expected_default_trigger, sl._get_default_trigger(self.settings_dict))
  81. del sl
  82. def test_get_stts(self):
  83. stt = Stt(name="google", parameters={'language': 'fr-FR'})
  84. sl = SettingLoader(file_path=self.settings_file_to_test)
  85. self.assertEqual([stt], sl._get_stts(self.settings_dict))
  86. del sl
  87. def test_get_ttss(self):
  88. tts1 = Tts(name="pico2wave", parameters={'cache': True, 'language': 'fr-FR'})
  89. tts2 = Tts(name="voxygen", parameters={'voice': 'Agnes', 'cache': True})
  90. sl = SettingLoader(file_path=self.settings_file_to_test)
  91. self.assertEqual([tts1, tts2], sl._get_ttss(self.settings_dict))
  92. del sl
  93. def test_get_triggers(self):
  94. trigger1 = Trigger(name="snowboy",
  95. parameters={'pmdl_file': 'trigger/snowboy/resources/kalliope-FR-6samples.pmdl'})
  96. sl = SettingLoader(file_path=self.settings_file_to_test)
  97. self.assertEqual([trigger1], sl._get_triggers(self.settings_dict))
  98. del sl
  99. def test_get_random_wake_up_answers(self):
  100. expected_random_wake_up_answers = ['Oui monsieur?']
  101. sl = SettingLoader(file_path=self.settings_file_to_test)
  102. self.assertEqual(expected_random_wake_up_answers, sl._get_random_wake_up_answers(self.settings_dict))
  103. del sl
  104. def test_get_rest_api(self):
  105. expected_rest_api = RestAPI(password_protected=True, active=True,
  106. login="admin", password="secret", port=5000)
  107. sl = SettingLoader(file_path=self.settings_file_to_test)
  108. self.assertEqual(expected_rest_api, sl._get_rest_api(self.settings_dict))
  109. del sl
  110. def test_get_cache_path(self):
  111. expected_cache_path = '/tmp/kalliope_tts_cache'
  112. sl = SettingLoader(file_path=self.settings_file_to_test)
  113. self.assertEqual(expected_cache_path, sl._get_cache_path(self.settings_dict))
  114. del sl
  115. if __name__ == '__main__':
  116. unittest.main()