瀏覽代碼

[Fix] [Test] #236 Manage integer in neuron parameters when loding brain

monf 8 年之前
父節點
當前提交
0763acfeae
共有 3 個文件被更改,包括 24 次插入1 次删除
  1. 7 0
      Tests/brains/brain_test.yml
  2. 16 0
      Tests/test_brain_loader.py
  3. 1 1
      kalliope/core/ConfigurationManager/BrainLoader.py

+ 7 - 0
Tests/brains/brain_test.yml

@@ -15,5 +15,12 @@
           message:
             - "test message"
 
+  - name: "testint"
+    signals:
+      - order: "order_for_int"
+    neurons:
+      - sleep:
+          seconds: 60
+
   - includes:
     - included_brain_test.yml

+ 16 - 0
Tests/test_brain_loader.py

@@ -27,6 +27,9 @@ class TestBrainLoader(unittest.TestCase):
             {'signals': [{'order': 'test_order_2'}],
              'neurons': [{'say': {'message': ['test message']}}],
              'name': 'test2'},
+            {'signals': [{'order': 'order_for_int'}],
+             'neurons': [{'sleep': {'seconds': 60}}],
+             'name': 'testint'},
             {'includes': ['included_brain_test.yml']},
             {'signals': [{'order': 'test_order_3'}],
              'neurons': [{'say': {'message': ['test message']}}],
@@ -73,6 +76,7 @@ class TestBrainLoader(unittest.TestCase):
         scenarii:
             - 1/ get a simple neuron from the brainloader
             - 2/ get a neuron with global variables as parameters
+            - 3/ get a neuron with int as parameters
         """
         # 1/ get a simple neuron from the brainloader
         st = Settings()
@@ -102,6 +106,18 @@ class TestBrainLoader(unittest.TestCase):
 
         self.assertEqual([neuron], neurons_from_brain_loader)
 
+        # 3/ get a neuron with int as parameters
+        st = Settings()
+        neuron_list = [{'sleep': {'seconds': 60}}]
+
+        neuron = Neuron(name='sleep', parameters={'seconds': 60})
+
+        bl = BrainLoader(file_path=self.brain_to_test)
+        neurons_from_brain_loader = bl._get_neurons(neuron_list,
+                                                    settings=st)
+
+        self.assertEqual([neuron], neurons_from_brain_loader)
+
     def test_get_signals(self):
         signals = [{'order': 'test_order'}]
 

+ 1 - 1
kalliope/core/ConfigurationManager/BrainLoader.py

@@ -267,7 +267,7 @@ class BrainLoader(object):
             for el in parameter:
                 new_parameter_list.append(cls._replace_global_variables(el, settings=settings))
             return new_parameter_list
-        if isinstance(parameter, str) or isinstance(parameter, unicode):
+        if isinstance(parameter, str) or isinstance(parameter, unicode) or isinstance(parameter, int):
             # print "parameter is string %s" % parameter
             if Utils.is_containing_bracket(parameter):
                 return cls._get_global_variable(sentence=parameter, settings=settings)