test_neuron_parameter_loader.py 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. import unittest
  2. from kalliope.core.NeuronParameterLoader import NeuronParameterLoader
  3. class TestNeuronParameterLoader(unittest.TestCase):
  4. def test_get_parameters(self):
  5. synapse_order = "this is the {{ sentence }}"
  6. user_order = "this is the value"
  7. expected_result = {'sentence': 'value'}
  8. self.assertEqual(NeuronParameterLoader.get_parameters(synapse_order=synapse_order, user_order=user_order),
  9. expected_result,
  10. "Fail to retrieve 'the params' of the synapse_order from the order")
  11. # Multiple match
  12. synapse_order = "this is the {{ sentence }}"
  13. user_order = "this is the value with multiple words"
  14. expected_result = {'sentence': 'value with multiple words'}
  15. self.assertEqual(NeuronParameterLoader.get_parameters(synapse_order=synapse_order, user_order=user_order),
  16. expected_result,
  17. "Fail to retrieve the 'multiple words params' of the synapse_order from the order")
  18. # Multiple params
  19. synapse_order = "this is the {{ sentence }} with multiple {{ params }}"
  20. user_order = "this is the value with multiple words"
  21. expected_result = {'sentence': 'value',
  22. 'params':'words'}
  23. self.assertEqual(NeuronParameterLoader.get_parameters(synapse_order=synapse_order, user_order=user_order),
  24. expected_result,
  25. "Fail to retrieve the 'multiple params' of the synapse_order from the order")
  26. # Multiple params with multiple words
  27. synapse_order = "this is the {{ sentence }} with multiple {{ params }}"
  28. user_order = "this is the multiple values with multiple values as words"
  29. expected_result = {'sentence': 'multiple values',
  30. 'params': 'values as words'}
  31. self.assertEqual(NeuronParameterLoader.get_parameters(synapse_order=synapse_order, user_order=user_order),
  32. expected_result)
  33. # params at the begining of the sentence
  34. synapse_order = "{{ sentence }} this is the sentence"
  35. user_order = "hello world this is the multiple values with multiple values as words"
  36. expected_result = {'sentence': 'hello world'}
  37. self.assertEqual(NeuronParameterLoader.get_parameters(synapse_order=synapse_order, user_order=user_order),
  38. expected_result)
  39. # all of the sentence is a variable
  40. synapse_order = "{{ sentence }}"
  41. user_order = "this is the all sentence is a variable"
  42. expected_result = {'sentence': 'this is the all sentence is a variable'}
  43. self.assertEqual(NeuronParameterLoader.get_parameters(synapse_order=synapse_order, user_order=user_order),
  44. expected_result)
  45. def test_associate_order_params_to_values(self):
  46. ##
  47. # Testing the brackets position behaviour
  48. ##
  49. # Success
  50. order_brain = "This is the {{ variable }}"
  51. order_user = "This is the value"
  52. expected_result = {'variable': 'value'}
  53. self.assertEqual(NeuronParameterLoader._associate_order_params_to_values(order_user, order_brain),
  54. expected_result)
  55. # Success
  56. order_brain = "This is the {{variable }}"
  57. order_user = "This is the value"
  58. expected_result = {'variable': 'value'}
  59. self.assertEqual(NeuronParameterLoader._associate_order_params_to_values(order_user, order_brain),
  60. expected_result)
  61. # Success
  62. order_brain = "This is the {{ variable}}"
  63. order_user = "This is the value"
  64. expected_result = {'variable': 'value'}
  65. self.assertEqual(NeuronParameterLoader._associate_order_params_to_values(order_user, order_brain),
  66. expected_result)
  67. # Success
  68. order_brain = "This is the {{variable}}"
  69. order_user = "This is the value"
  70. expected_result = {'variable': 'value'}
  71. self.assertEqual(NeuronParameterLoader._associate_order_params_to_values(order_user, order_brain),
  72. expected_result)
  73. # Fail
  74. order_brain = "This is the {variable}"
  75. order_user = "This is the value"
  76. expected_result = {'variable': 'value'}
  77. self.assertNotEqual(NeuronParameterLoader._associate_order_params_to_values(order_user, order_brain),
  78. expected_result)
  79. # Fail
  80. order_brain = "This is the { variable}}"
  81. order_user = "This is the value"
  82. expected_result = {'variable': 'value'}
  83. self.assertNotEqual(NeuronParameterLoader._associate_order_params_to_values(order_user, order_brain),
  84. expected_result)
  85. ##
  86. # Testing the brackets position in the sentence
  87. ##
  88. # Success
  89. order_brain = "{{ variable }} This is the"
  90. order_user = "value This is the"
  91. expected_result = {'variable': 'value'}
  92. self.assertEqual(NeuronParameterLoader._associate_order_params_to_values(order_user, order_brain),
  93. expected_result)
  94. # Success
  95. order_brain = "This is {{ variable }} the"
  96. order_user = " This is value the"
  97. expected_result = {'variable': 'value'}
  98. self.assertEqual(NeuronParameterLoader._associate_order_params_to_values(order_user, order_brain),
  99. expected_result)
  100. ##
  101. # Testing multi variables
  102. ##
  103. # Success
  104. order_brain = "This is {{ variable }} the {{ variable2 }}"
  105. order_user = "This is value the value2"
  106. expected_result = {'variable': 'value',
  107. 'variable2': 'value2'}
  108. self.assertEqual(NeuronParameterLoader._associate_order_params_to_values(order_user, order_brain),
  109. expected_result)
  110. ##
  111. # Testing multi words in variable
  112. ##
  113. # Success
  114. order_brain = "This is the {{ variable }}"
  115. order_user = "This is the value with multiple words"
  116. expected_result = {'variable': 'value with multiple words'}
  117. self.assertEqual(NeuronParameterLoader._associate_order_params_to_values(order_user, order_brain),
  118. expected_result)
  119. # Success
  120. order_brain = "This is the {{ variable }} and {{ variable2 }}"
  121. order_user = "This is the value with multiple words and second value multiple"
  122. expected_result = {'variable': 'value with multiple words',
  123. 'variable2': 'second value multiple'}
  124. self.assertEqual(NeuronParameterLoader._associate_order_params_to_values(order_user, order_brain),
  125. expected_result)
  126. ##
  127. # Specific Behaviour
  128. ##
  129. # Upper/Lower case
  130. order_brain = "This Is The {{ variable }}"
  131. order_user = "ThiS is tHe VAlue"
  132. expected_result = {'variable': 'VAlue'}
  133. self.assertEqual(NeuronParameterLoader._associate_order_params_to_values(order_user, order_brain),
  134. expected_result)
  135. # Upper/Lower case between multiple variables
  136. order_brain = "This Is The {{ variable }} And The {{ variable2 }}"
  137. order_user = "ThiS is tHe VAlue aND tHE vAlUe2"
  138. expected_result = {'variable': 'VAlue',
  139. 'variable2':'vAlUe2'}
  140. self.assertEqual(NeuronParameterLoader._associate_order_params_to_values(order_user, order_brain),
  141. expected_result)
  142. # Upper/Lower case between multiple variables and at the End
  143. order_brain = "This Is The {{ variable }} And The {{ variable2 }} And Again"
  144. order_user = "ThiS is tHe VAlue aND tHE vAlUe2 and aGAIN"
  145. expected_result = {'variable': 'VAlue',
  146. 'variable2': 'vAlUe2'}
  147. self.assertEqual(NeuronParameterLoader._associate_order_params_to_values(order_user, order_brain),
  148. expected_result)
  149. # integers variables
  150. order_brain = "This Is The {{ variable }} And The {{ variable2 }}"
  151. order_user = "ThiS is tHe 1 aND tHE 2"
  152. expected_result = {'variable': '1',
  153. 'variable2': '2'}
  154. self.assertEqual(NeuronParameterLoader._associate_order_params_to_values(order_user, order_brain),
  155. expected_result)
  156. if __name__ == '__main__':
  157. unittest.main()