test_resources_manager.py 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. import os
  2. import unittest
  3. from mock import mock
  4. from kalliope import ResourcesManager
  5. from kalliope.core.Models import Resources
  6. from kalliope.core.Models.Dna import Dna
  7. class TestResourcesmanager(unittest.TestCase):
  8. def setUp(self):
  9. pass
  10. def tearDown(self):
  11. pass
  12. def test_is_settings_ok(self):
  13. # -----------------
  14. # valid resource
  15. # -----------------
  16. # valid neuron
  17. valid_resource = Resources()
  18. valid_resource.neuron_folder = "/path"
  19. dna = Dna()
  20. dna.module_type = "neuron"
  21. self.assertTrue(ResourcesManager.is_settings_ok(valid_resource, dna))
  22. # valid stt
  23. valid_resource = Resources()
  24. valid_resource.stt_folder = "/path"
  25. dna = Dna()
  26. dna.module_type = "stt"
  27. self.assertTrue(ResourcesManager.is_settings_ok(valid_resource, dna))
  28. # valid tts
  29. valid_resource = Resources()
  30. valid_resource.tts_folder = "/path"
  31. dna = Dna()
  32. dna.module_type = "tss"
  33. self.assertTrue(ResourcesManager.is_settings_ok(valid_resource, dna))
  34. # valid trigger
  35. valid_resource = Resources()
  36. valid_resource.trigger_folder = "/path"
  37. dna = Dna()
  38. dna.module_type = "trigger"
  39. self.assertTrue(ResourcesManager.is_settings_ok(valid_resource, dna))
  40. # valid signal
  41. valid_resource = Resources()
  42. valid_resource.signal_folder = "/path"
  43. dna = Dna()
  44. dna.module_type = "signal"
  45. self.assertTrue(ResourcesManager.is_settings_ok(valid_resource, dna))
  46. # -----------------
  47. # invalid resource
  48. # -----------------
  49. # valid neuron
  50. valid_resource = Resources()
  51. valid_resource.neuron_folder = None
  52. dna = Dna()
  53. dna.module_type = "neuron"
  54. self.assertFalse(ResourcesManager.is_settings_ok(valid_resource, dna))
  55. # valid stt
  56. valid_resource = Resources()
  57. valid_resource.stt_folder = None
  58. dna = Dna()
  59. dna.module_type = "stt"
  60. self.assertFalse(ResourcesManager.is_settings_ok(valid_resource, dna))
  61. # valid tts
  62. valid_resource = Resources()
  63. valid_resource.tts_folder = None
  64. dna = Dna()
  65. dna.module_type = "tts"
  66. self.assertFalse(ResourcesManager.is_settings_ok(valid_resource, dna))
  67. # valid trigger
  68. valid_resource = Resources()
  69. valid_resource.trigger_folder = None
  70. dna = Dna()
  71. dna.module_type = "trigger"
  72. self.assertFalse(ResourcesManager.is_settings_ok(valid_resource, dna))
  73. # valid signal
  74. valid_resource = Resources()
  75. valid_resource.signal_folder = None
  76. dna = Dna()
  77. dna.module_type = "signal"
  78. self.assertFalse(ResourcesManager.is_settings_ok(valid_resource, dna))
  79. def test_is_repo_ok(self):
  80. # valid repo
  81. if "/Tests" in os.getcwd():
  82. dna_file_path = "modules/dna.yml"
  83. install_file_path = "modules/install.yml"
  84. else:
  85. dna_file_path = "Tests/modules/dna.yml"
  86. install_file_path = "Tests/modules/install.yml"
  87. self.assertTrue(ResourcesManager.is_repo_ok(dna_file_path=dna_file_path, install_file_path=install_file_path))
  88. # missing dna
  89. if "/Tests" in os.getcwd():
  90. dna_file_path = ""
  91. install_file_path = "modules/install.yml"
  92. else:
  93. dna_file_path = "T"
  94. install_file_path = "Tests/modules/install.yml"
  95. self.assertFalse(ResourcesManager.is_repo_ok(dna_file_path=dna_file_path, install_file_path=install_file_path))
  96. # missing install
  97. if "/Tests" in os.getcwd():
  98. dna_file_path = "modules/dna.yml"
  99. install_file_path = ""
  100. else:
  101. dna_file_path = "Tests/modules/dna.yml"
  102. install_file_path = ""
  103. self.assertFalse(ResourcesManager.is_repo_ok(dna_file_path=dna_file_path, install_file_path=install_file_path))
  104. def test_get_target_folder(self):
  105. # test get neuron folder
  106. resources = Resources()
  107. resources.neuron_folder = '/var/tmp/test/resources'
  108. self.assertEqual(ResourcesManager._get_target_folder(resources, "neuron"), "/var/tmp/test/resources")
  109. # test get stt folder
  110. resources = Resources()
  111. resources.stt_folder = '/var/tmp/test/resources'
  112. self.assertEqual(ResourcesManager._get_target_folder(resources, "stt"), "/var/tmp/test/resources")
  113. # test get tts folder
  114. resources = Resources()
  115. resources.tts_folder = '/var/tmp/test/resources'
  116. self.assertEqual(ResourcesManager._get_target_folder(resources, "tts"), "/var/tmp/test/resources")
  117. # test get trigger folder
  118. resources = Resources()
  119. resources.trigger_folder = '/var/tmp/test/resources'
  120. self.assertEqual(ResourcesManager._get_target_folder(resources, "trigger"), "/var/tmp/test/resources")
  121. # test get signal folder
  122. resources = Resources()
  123. resources.signal_folder = '/var/tmp/test/resources'
  124. self.assertEqual(ResourcesManager._get_target_folder(resources, "signal"), "/var/tmp/test/resources")
  125. # test get non existing resource
  126. resources = Resources()
  127. self.assertIsNone(ResourcesManager._get_target_folder(resources, "not_existing"))
  128. def test_check_supported_version(self):
  129. # version ok
  130. current_version = '0.4.0'
  131. supported_version = ['0.4', '0.3', '0.2']
  132. self.assertTrue(ResourcesManager._check_supported_version(current_version=current_version,
  133. supported_versions=supported_version))
  134. # version ok
  135. current_version = '11.23.0'
  136. supported_version = ['11.23', '12.3', '2.23']
  137. self.assertTrue(ResourcesManager._check_supported_version(current_version=current_version,
  138. supported_versions=supported_version))
  139. # version non ok, user does not config
  140. # Testing with integer values instead of string
  141. current_version = '0.4.0'
  142. supported_version = [0.3, 0.2]
  143. with mock.patch('kalliope.Utils.query_yes_no', return_value=True):
  144. self.assertTrue(ResourcesManager._check_supported_version(current_version=current_version,
  145. supported_versions=supported_version))
  146. with mock.patch('kalliope.Utils.query_yes_no', return_value=False):
  147. self.assertFalse(ResourcesManager._check_supported_version(current_version=current_version,
  148. supported_versions=supported_version))