test_configuration_checker.py 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. import unittest
  2. from kalliope.core.ConfigurationManager.ConfigurationChecker import ConfigurationChecker, NoSynapeName, \
  3. NoSynapeNeurons, NoSynapeSignals, NoValidSignal, MultipleSameSynapseName
  4. from kalliope.core.Models import Synapse
  5. from kalliope.core.Utils.Utils import ModuleNotFoundError
  6. class TestConfigurationChecker(unittest.TestCase):
  7. """
  8. Class used to test the ConfigurationChecker class
  9. """
  10. def setUp(self):
  11. pass
  12. def test_check_synape_dict(self):
  13. valid_synapse_dict = {
  14. 'signals': [{'order': 'test_order'}],
  15. 'neurons': [{'say': {'message': ['test message']}}],
  16. 'name': 'test'
  17. }
  18. synapse_dict_without_name = {
  19. 'signals': [{'order': 'test_order'}],
  20. 'neurons': [{'say': {'message': ['test message']}}]
  21. }
  22. synapse_dict_without_neurons = {
  23. 'signals': [{'order': 'test_order'}],
  24. 'name': 'test'
  25. }
  26. synapse_dict_without_signals = {
  27. 'neurons': [{'say': {'message': ['test message']}}],
  28. 'name': 'test'
  29. }
  30. self.assertTrue(ConfigurationChecker.check_synape_dict(valid_synapse_dict))
  31. with self.assertRaises(NoSynapeName):
  32. ConfigurationChecker.check_synape_dict(synapse_dict_without_name)
  33. with self.assertRaises(NoSynapeNeurons):
  34. ConfigurationChecker.check_synape_dict(synapse_dict_without_neurons)
  35. with self.assertRaises(NoSynapeSignals):
  36. ConfigurationChecker.check_synape_dict(synapse_dict_without_signals)
  37. def test_check_neuron_dict(self):
  38. valid_neuron = {'say': {'message': ['test message']}}
  39. invalid_neuron = {'not_existing_neuron': {'message': ['test message']}}
  40. self.assertTrue(ConfigurationChecker.check_neuron_dict(valid_neuron))
  41. with self.assertRaises(ModuleNotFoundError):
  42. ConfigurationChecker.check_neuron_dict(invalid_neuron)
  43. def test_check_signal_dict(self):
  44. valid_signal = {'event': {'parameter_1': ['value1']}}
  45. invalid_signal = {'non_existing_signal_name': {'parameter_2': ['value2']}}
  46. self.assertTrue(ConfigurationChecker.check_signal_dict(valid_signal))
  47. with self.assertRaises(ModuleNotFoundError):
  48. ConfigurationChecker.check_signal_dict(invalid_signal)
  49. def test_check_synapes(self):
  50. synapse_1 = Synapse(name="test")
  51. synapse_2 = Synapse(name="test2")
  52. synapse_3 = Synapse(name="test")
  53. valid_synapse_list = [synapse_1, synapse_2]
  54. invalid_synapse_list = [synapse_1, synapse_3]
  55. self.assertTrue(ConfigurationChecker.check_synapes(valid_synapse_list))
  56. with self.assertRaises(MultipleSameSynapseName):
  57. ConfigurationChecker.check_synapes(invalid_synapse_list)
  58. if __name__ == '__main__':
  59. unittest.main()