123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298 |
- import unittest
- from kalliope.core.NeuronParameterLoader import NeuronParameterLoader
- class TestNeuronParameterLoader(unittest.TestCase):
- def test_get_parameters(self):
- synapse_order = "this is the {{ sentence }}"
- user_order = "this is the value"
- expected_result = {'sentence': 'value'}
- self.assertEqual(NeuronParameterLoader.get_parameters(synapse_order=synapse_order, user_order=user_order),
- expected_result,
- "Fail to retrieve 'the params' of the synapse_order from the order")
-
- synapse_order = "this is the {{ sentence }}"
- user_order = "this is the value with multiple words"
- expected_result = {'sentence': 'value with multiple words'}
- self.assertEqual(NeuronParameterLoader.get_parameters(synapse_order=synapse_order, user_order=user_order),
- expected_result,
- "Fail to retrieve the 'multiple words params' of the synapse_order from the order")
-
- synapse_order = "this is the {{ sentence }} with multiple {{ params }}"
- user_order = "this is the value with multiple words"
- expected_result = {'sentence': 'value',
- 'params': 'words'}
- self.assertEqual(NeuronParameterLoader.get_parameters(synapse_order=synapse_order, user_order=user_order),
- expected_result,
- "Fail to retrieve the 'multiple params' of the synapse_order from the order")
-
- synapse_order = "this is the {{ sentence }} with multiple {{ params }}"
- user_order = "this is the multiple values with multiple values as words"
- expected_result = {'sentence': 'multiple values',
- 'params': 'values as words'}
- self.assertEqual(NeuronParameterLoader.get_parameters(synapse_order=synapse_order, user_order=user_order),
- expected_result)
-
- synapse_order = "{{ sentence }} this is the sentence"
- user_order = "hello world this is the multiple values with multiple values as words"
- expected_result = {'sentence': 'hello world'}
- self.assertEqual(NeuronParameterLoader.get_parameters(synapse_order=synapse_order, user_order=user_order),
- expected_result)
-
- synapse_order = "{{ sentence }}"
- user_order = "this is the all sentence is a variable"
- expected_result = {'sentence': 'this is the all sentence is a variable'}
- self.assertEqual(NeuronParameterLoader.get_parameters(synapse_order=synapse_order, user_order=user_order),
- expected_result)
- def test_associate_order_params_to_values(self):
-
-
-
-
- order_brain = "This is the {{ variable }}"
- order_user = "This is the value"
- expected_result = {'variable': 'value'}
- self.assertEqual(NeuronParameterLoader._associate_order_params_to_values(order_user, order_brain),
- expected_result)
-
- order_brain = "This is the {{variable }}"
- order_user = "This is the value"
- expected_result = {'variable': 'value'}
- self.assertEqual(NeuronParameterLoader._associate_order_params_to_values(order_user, order_brain),
- expected_result)
-
- order_brain = "This is the {{ variable}}"
- order_user = "This is the value"
- expected_result = {'variable': 'value'}
- self.assertEqual(NeuronParameterLoader._associate_order_params_to_values(order_user, order_brain),
- expected_result)
-
- order_brain = "This is the {{variable}}"
- order_user = "This is the value"
- expected_result = {'variable': 'value'}
- self.assertEqual(NeuronParameterLoader._associate_order_params_to_values(order_user, order_brain),
- expected_result)
-
- order_brain = "This is the {variable}"
- order_user = "This is the value"
- expected_result = {'variable': 'value'}
- self.assertNotEqual(NeuronParameterLoader._associate_order_params_to_values(order_user, order_brain),
- expected_result)
-
- order_brain = "This is the { variable}}"
- order_user = "This is the value"
- expected_result = {'variable': 'value'}
- self.assertNotEqual(NeuronParameterLoader._associate_order_params_to_values(order_user, order_brain),
- expected_result)
-
-
-
-
- order_brain = "{{ variable }} This is the"
- order_user = "value This is the"
- expected_result = {'variable': 'value'}
- self.assertEqual(NeuronParameterLoader._associate_order_params_to_values(order_user, order_brain),
- expected_result)
-
- order_brain = "This is {{ variable }} the"
- order_user = " This is value the"
- expected_result = {'variable': 'value'}
- self.assertEqual(NeuronParameterLoader._associate_order_params_to_values(order_user, order_brain),
- expected_result)
-
-
-
-
- order_brain = "This is {{ variable }} the {{ variable2 }}"
- order_user = "This is value the value2"
- expected_result = {'variable': 'value',
- 'variable2': 'value2'}
- self.assertEqual(NeuronParameterLoader._associate_order_params_to_values(order_user, order_brain),
- expected_result)
-
-
-
-
- order_brain = "This is the {{ variable }}"
- order_user = "This is the value with multiple words"
- expected_result = {'variable': 'value with multiple words'}
- self.assertEqual(NeuronParameterLoader._associate_order_params_to_values(order_user, order_brain),
- expected_result)
-
- order_brain = "This is the {{ variable }} and {{ variable2 }}"
- order_user = "This is the value with multiple words and second value multiple"
- expected_result = {'variable': 'value with multiple words',
- 'variable2': 'second value multiple'}
- self.assertEqual(NeuronParameterLoader._associate_order_params_to_values(order_user, order_brain),
- expected_result)
-
-
-
-
- order_brain = "This Is The {{ variable }}"
- order_user = "ThiS is tHe VAlue"
- expected_result = {'variable': 'VAlue'}
- self.assertEqual(NeuronParameterLoader._associate_order_params_to_values(order_user, order_brain),
- expected_result)
-
- order_brain = "This Is The {{ variable }} And The {{ variable2 }}"
- order_user = "ThiS is tHe VAlue aND tHE vAlUe2"
- expected_result = {'variable': 'VAlue',
- 'variable2': 'vAlUe2'}
- self.assertEqual(NeuronParameterLoader._associate_order_params_to_values(order_user, order_brain),
- expected_result)
-
- order_brain = "This Is The {{ variable }} And The {{ variable2 }} And Again"
- order_user = "ThiS is tHe VAlue aND tHE vAlUe2 and aGAIN"
- expected_result = {'variable': 'VAlue',
- 'variable2': 'vAlUe2'}
- self.assertEqual(NeuronParameterLoader._associate_order_params_to_values(order_user, order_brain),
- expected_result)
-
- order_brain = "This Is The {{ variable }} And The {{ variable2 }}"
- order_user = "ThiS is tHe 1 aND tHE 2"
- expected_result = {'variable': '1',
- 'variable2': '2'}
- self.assertEqual(NeuronParameterLoader._associate_order_params_to_values(order_user, order_brain),
- expected_result)
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- order_brain = "this the {{ variable }} and the {{ variable2 }}"
- order_user = "this is the foo and the bar"
- expected_result = {'variable': 'foo',
- 'variable2': 'bar'}
- self.assertEqual(NeuronParameterLoader._associate_order_params_to_values(order_user, order_brain),
- expected_result)
-
- order_brain = "this the {{ variable }} and the {{ variable2 }}"
- order_user = "this is Fake the foo and the bar"
- expected_result = {'variable': 'foo',
- 'variable2': 'bar'}
- self.assertEqual(NeuronParameterLoader._associate_order_params_to_values(order_user, order_brain),
- expected_result)
-
- order_brain = "this the {{ variable }} and the {{ variable2 }}"
- order_user = "Oops this is the foo and the bar"
- expected_result = {'variable': 'foo',
- 'variable2': 'bar'}
- self.assertEqual(NeuronParameterLoader._associate_order_params_to_values(order_user, order_brain),
- expected_result)
-
- order_brain = "this the {{ variable }} and the {{ variable2 }}"
- order_user = "Oops Oops this is BlaBla the foo and the bar"
- expected_result = {'variable': 'foo',
- 'variable2': 'bar'}
- self.assertEqual(NeuronParameterLoader._associate_order_params_to_values(order_user, order_brain),
- expected_result)
-
- order_brain = "this the {{ variable }} and the {{ variable2 }}"
- order_user = "Oops Oops this is BlaBla the foo and ploup ploup the bar"
- expected_result = {'variable': 'foo',
- 'variable2': 'bar'}
- self.assertEqual(NeuronParameterLoader._associate_order_params_to_values(order_user, order_brain),
- expected_result)
-
- order_brain = "this the {{ variable }} and the {{ variable2 }} hello"
- order_user = "Oops Oops this is BlaBla the foo and ploup ploup the bar hello test"
- expected_result = {'variable': 'foo',
- 'variable2': 'bar'}
- self.assertEqual(NeuronParameterLoader._associate_order_params_to_values(order_user, order_brain),
- expected_result)
- if __name__ == '__main__':
- unittest.main()
|