Browse Source

Merge pull request #250 from jschueller/py3k-dev

Python 3 support
Monf 7 years ago
parent
commit
d1c8a88612
64 changed files with 208 additions and 225 deletions
  1. 2 0
      .travis.yml
  2. 10 10
      Tests/__init__.py
  3. 24 24
      Tests/test_brain_loader.py
  4. 1 1
      Tests/test_dynamic_loading.py
  5. 3 3
      Tests/test_file_manager.py
  6. 17 59
      Tests/test_models.py
  7. 6 6
      Tests/test_neuron_parameter_loader.py
  8. 3 3
      Tests/test_order_listener.py
  9. 9 8
      Tests/test_rest_api.py
  10. 1 1
      Tests/test_settings_loader.py
  11. 3 3
      Tests/test_singleton.py
  12. 6 6
      Tests/test_tts_module.py
  13. 15 15
      Tests/test_utils.py
  14. 1 1
      install/files/python_requirements.txt
  15. 2 2
      kalliope/__init__.py
  16. 6 5
      kalliope/core/ConfigurationManager/BrainLoader.py
  17. 1 1
      kalliope/core/ConfigurationManager/ConfigurationChecker.py
  18. 11 11
      kalliope/core/ConfigurationManager/SettingLoader.py
  19. 4 2
      kalliope/core/ConfigurationManager/YAMLLoader.py
  20. 3 3
      kalliope/core/ConfigurationManager/__init__.py
  21. 1 1
      kalliope/core/Models/Neuron.py
  22. 7 7
      kalliope/core/Models/__init__.py
  23. 2 2
      kalliope/core/NeuronLauncher.py
  24. 8 6
      kalliope/core/NeuronModule.py
  25. 3 1
      kalliope/core/OrderAnalyser.py
  26. 1 1
      kalliope/core/Players/__init__.py
  27. 1 1
      kalliope/core/ShellGui.py
  28. 3 1
      kalliope/core/TTS/TTSModule.py
  29. 1 1
      kalliope/core/TTS/__init__.py
  30. 1 1
      kalliope/core/Utils/FileManager.py
  31. 8 4
      kalliope/core/Utils/Utils.py
  32. 1 1
      kalliope/neurons/ansible_playbook/__init__.py
  33. 1 1
      kalliope/neurons/kill_switch/__init__.py
  34. 1 1
      kalliope/neurons/neurotransmitter/__init__.py
  35. 1 1
      kalliope/neurons/say/__init__.py
  36. 1 1
      kalliope/neurons/script/__init__.py
  37. 1 1
      kalliope/neurons/script/script.py
  38. 2 2
      kalliope/neurons/script/tests/test_script.py
  39. 1 1
      kalliope/neurons/shell/__init__.py
  40. 1 1
      kalliope/neurons/shell/shell.py
  41. 1 1
      kalliope/neurons/sleep/__init__.py
  42. 2 1
      kalliope/neurons/sleep/sleep.py
  43. 1 1
      kalliope/neurons/systemdate/__init__.py
  44. 3 3
      kalliope/neurons/uri/tests/test_uri_neuron.py
  45. 3 3
      kalliope/neurons/uri/uri.py
  46. 1 1
      kalliope/stt/apiai/__init__.py
  47. 1 1
      kalliope/stt/bing/__init__.py
  48. 1 1
      kalliope/stt/cmusphinx/__init__.py
  49. 1 1
      kalliope/stt/google/__init__.py
  50. 1 1
      kalliope/stt/houndify/__init__.py
  51. 1 1
      kalliope/stt/wit/__init__.py
  52. 1 1
      kalliope/trigger/snowboy/__init__.py
  53. 0 0
      kalliope/trigger/snowboy/armv7l/python27/_snowboydetect.so
  54. 1 1
      kalliope/trigger/snowboy/snowboydecoder.py
  55. 1 1
      kalliope/trigger/snowboy/snowboydetect.py
  56. 0 0
      kalliope/trigger/snowboy/x86_64/python27/_snowboydetect.so
  57. BIN
      kalliope/trigger/snowboy/x86_64/python34/_snowboydetect.so
  58. BIN
      kalliope/trigger/snowboy/x86_64/python35/_snowboydetect.so
  59. BIN
      kalliope/trigger/snowboy/x86_64/python36/_snowboydetect.so
  60. 1 1
      kalliope/tts/acapela/__init__.py
  61. 1 1
      kalliope/tts/googletts/__init__.py
  62. 1 1
      kalliope/tts/pico2wave/__init__.py
  63. 1 1
      kalliope/tts/voicerss/__init__.py
  64. 11 3
      setup.py

+ 2 - 0
.travis.yml

@@ -5,6 +5,7 @@ services:
 
 python:
   - "2.7"
+  - "3.4"
 
 # command to install dependencies
 before_install:
@@ -21,6 +22,7 @@ before_install:
 
 install:
   - pip install -r install/files/python_requirements.txt
+  - pip install python2-pythondialog || pip install pythondialog
   - pip install coveralls
 
 # command to run tests

+ 10 - 10
Tests/__init__.py

@@ -1,10 +1,10 @@
-from test_brain_loader import TestBrainLoader
-from test_configuration_checker import TestConfigurationChecker
-from test_dynamic_loading import TestDynamicLoading
-from test_file_manager import TestFileManager
-from test_rest_api import TestRestAPI
-from test_settings_loader import TestSettingLoader
-from test_singleton import TestSingleton
-from test_tts_module import TestTTSModule
-from test_yaml_loader import TestYAMLLoader
-from test_neuron_module import TestNeuronModule
+from .test_brain_loader import TestBrainLoader
+from .test_configuration_checker import TestConfigurationChecker
+from .test_dynamic_loading import TestDynamicLoading
+from .test_file_manager import TestFileManager
+from .test_rest_api import TestRestAPI
+from .test_settings_loader import TestSettingLoader
+from .test_singleton import TestSingleton
+from .test_tts_module import TestTTSModule
+from .test_yaml_loader import TestYAMLLoader
+from .test_neuron_module import TestNeuronModule

+ 24 - 24
Tests/test_brain_loader.py

@@ -183,10 +183,10 @@ class TestBrainLoader(unittest.TestCase):
             'var1': 'test'
         }
 
-        self.assertEquals(BrainLoader._replace_global_variables(parameter=parameters,
+        self.assertEqual(BrainLoader._replace_global_variables(parameter=parameters,
                                                                 settings=st),
-                          expected_parameters,
-                          "Fail to assign a single global variable to parameters")
+                         expected_parameters,
+                         "Fail to assign a single global variable to parameters")
 
         # 2/ global variable with string after
         parameters = {
@@ -202,10 +202,10 @@ class TestBrainLoader(unittest.TestCase):
             'var1': 'test Sispheor'
         }
 
-        self.assertEquals(BrainLoader._replace_global_variables(parameter=parameters,
+        self.assertEqual(BrainLoader._replace_global_variables(parameter=parameters,
                                                                 settings=st),
-                          expected_parameters,
-                          "Fail to assign a global variable with string after to parameters")
+                         expected_parameters,
+                         "Fail to assign a global variable with string after to parameters")
 
         # 3/ global variable with int after
         parameters = {
@@ -221,10 +221,10 @@ class TestBrainLoader(unittest.TestCase):
             'var1': '600'
         }
 
-        self.assertEquals(BrainLoader._replace_global_variables(parameter=parameters,
+        self.assertEqual(BrainLoader._replace_global_variables(parameter=parameters,
                                                                 settings=st),
-                          expected_parameters,
-                          "Fail to assign global variable with int after to parameters")
+                         expected_parameters,
+                         "Fail to assign global variable with int after to parameters")
 
         # 4/ multiple global variables
         parameters = {
@@ -240,10 +240,10 @@ class TestBrainLoader(unittest.TestCase):
             'var1': 'hello LaMonf'
         }
 
-        self.assertEquals(BrainLoader._replace_global_variables(parameter=parameters,
+        self.assertEqual(BrainLoader._replace_global_variables(parameter=parameters,
                                                                 settings=st),
-                          expected_parameters,
-                          "Fail to assign multiple global variables to parameters")
+                         expected_parameters,
+                         "Fail to assign multiple global variables to parameters")
 
         # 5/ parameter value is a list
         parameters = {
@@ -259,10 +259,10 @@ class TestBrainLoader(unittest.TestCase):
             'var1': '[hello LaMonf, bonjour LaMonf]'
         }
 
-        self.assertEquals(BrainLoader._replace_global_variables(parameter=parameters,
+        self.assertEqual(BrainLoader._replace_global_variables(parameter=parameters,
                                                                 settings=st),
-                          expected_parameters,
-                          "Fail to assign a single global when parameter value is a list to neuron")
+                         expected_parameters,
+                         "Fail to assign a single global when parameter value is a list to neuron")
 
         # 6/ parameter is a dict
         parameters = {'from_answer_link': [{'synapse': 'synapse2', 'answers': ['absolument', '{{ name }}']},
@@ -279,10 +279,10 @@ class TestBrainLoader(unittest.TestCase):
                 {'synapse': 'synapse3', 'answers': ['nico']}], 'default': 'synapse4'
         }
 
-        self.assertEquals(BrainLoader._replace_global_variables(parameter=parameters,
+        self.assertEqual(BrainLoader._replace_global_variables(parameter=parameters,
                                                                 settings=st),
-                          expected_parameters,
-                          "Fail to assign a single global when parameter value is a list to neuron")
+                         expected_parameters,
+                         "Fail to assign a single global when parameter value is a list to neuron")
 
     def test_get_global_variable(self):
         """
@@ -299,25 +299,25 @@ class TestBrainLoader(unittest.TestCase):
 
         expected_result = "i am kalliope"
 
-        self.assertEquals(BrainLoader._get_global_variable(sentence=sentence,
+        self.assertEqual(BrainLoader._get_global_variable(sentence=sentence,
                                                            settings=st),
-                          expected_result)
+                         expected_result)
 
         # test with accent
         sentence = "i am {{name3}}"
         expected_result = u"i am kalliopé"
 
-        self.assertEquals(BrainLoader._get_global_variable(sentence=sentence,
+        self.assertEqual(BrainLoader._get_global_variable(sentence=sentence,
                                                            settings=st),
-                          expected_result)
+                         expected_result)
 
         # test with int
         sentence = "i am {{name4}}"
         expected_result = "i am 1"
 
-        self.assertEquals(BrainLoader._get_global_variable(sentence=sentence,
+        self.assertEqual(BrainLoader._get_global_variable(sentence=sentence,
                                                            settings=st),
-                          expected_result)
+                         expected_result)
 
 
 if __name__ == '__main__':

+ 1 - 1
Tests/test_dynamic_loading.py

@@ -98,7 +98,7 @@ class TestDynamicLoading(unittest.TestCase):
         # we keep only package. Because we have _init_.py or other stuff in what listdir returned
         packages_in_folder = list()
         for el in el_folder:
-            if os.path.isdir(folder + os.sep + el):
+            if os.path.isdir(folder + os.sep + el) and not '__pycache__' in el:
                 packages_in_folder.append(el)
         return packages_in_folder
 

+ 3 - 3
Tests/test_file_manager.py

@@ -81,7 +81,7 @@ class TestFileManager(unittest.TestCase):
 
         # Test FileManager.file_is_empty
         with open(file_path, "wb") as file_open:
-            file_open.write("")
+            file_open.write(b"")
             file_open.close()
         self.assertTrue(FileManager.file_is_empty(file_path=file_path),
                         "Fail matching to verify that file is empty ")
@@ -107,7 +107,7 @@ class TestFileManager(unittest.TestCase):
         # Test to remove the file
         # FileManager.remove_file
         with open(file_path, "wb") as file_open:
-            file_open.write("")
+            file_open.write(b"")
             file_open.close()
         FileManager.remove_file(file_path=file_path)
         self.assertFalse(os.path.exists(file_path),
@@ -157,7 +157,7 @@ class TestFileManager(unittest.TestCase):
 
         # Test the file exist and creatable : return True
         with open(file_path, "wb") as file_open:
-            file_open.write("[Kalliope] Test Running the test_is_path_exists_or_creatable method")
+            file_open.write(b"[Kalliope] Test Running the test_is_path_exists_or_creatable method")
             file_open.close()
         self.assertTrue(FileManager.is_path_exists_or_creatable(file_path),
                         "Fail to assert the file exist ")

+ 17 - 59
Tests/test_models.py

@@ -1,5 +1,5 @@
 import unittest
-
+import ast
 import mock
 from kalliope.core.Models.Tts import Tts
 
@@ -75,12 +75,7 @@ class TestModels(unittest.TestCase):
                 'user_order': 'user order'
         }
 
-        self.assertEqual(expected_result_serialize, api_response.serialize())
-
-        expected_result_str = "{'status': None, 'matched_synapses': [{'matched_order': 'user order', " \
-                              "'neuron_module_list': [], 'synapse_name': 'Synapse1'}], 'user_order': 'user order'}"
-
-        self.assertEqual(expected_result_str, api_response.__str__())
+        self.assertDictEqual(expected_result_serialize, api_response.serialize())
 
     def test_Brain(self):
         # test get synapse by name
@@ -113,11 +108,8 @@ class TestModels(unittest.TestCase):
             'name': 'dna1',
             'author': 'kalliope'
         }
-        expected_result_str = "{'kalliope_supported_version': '0.4.4', 'tags': 'test', 'type':" \
-                              " 'neuron', 'name': 'dna1', 'author': 'kalliope'}"
 
-        self.assertEqual(expected_result_serialize, dna1.serialize())
-        self.assertEqual(expected_result_str, dna1.__str__())
+        self.assertDictEqual(expected_result_serialize, dna1.serialize())
 
         self.assertTrue(dna1.__eq__(dna3))
         self.assertFalse(dna1.__eq__(dna2))
@@ -145,11 +137,8 @@ class TestModels(unittest.TestCase):
                 'month': 12
             }
         }
-        expected_result_str = "{'event': {'week': 53, 'second': 0, 'minute': 30, 'hour': 8, " \
-                              "'year': 2017, 'day': 31, 'day_of_week': 2, 'month': 12}}"
 
-        self.assertEqual(expected_result_serialize, event1.serialize())
-        self.assertEqual(expected_result_str, event1.__str__())
+        self.assertDictEqual(expected_result_serialize, event1.serialize())
 
         self.assertTrue(event1.__eq__(event3))
         self.assertFalse(event1.__eq__(event2))
@@ -165,10 +154,8 @@ class TestModels(unittest.TestCase):
             'neuron_module_list': [],
             'synapse_name': 'Synapse1'
         }
-        expected_result_str = "{'matched_order': 'user order', 'neuron_module_list': [], 'synapse_name': 'Synapse1'}"
 
-        self.assertEqual(expected_result_serialize, matched_synapse1.serialize())
-        self.assertEqual(expected_result_str, matched_synapse1.__str__())
+        self.assertDictEqual(expected_result_serialize, matched_synapse1.serialize())
 
         self.assertTrue(matched_synapse1.__eq__(matched_synapse3))
         self.assertFalse(matched_synapse1.__eq__(matched_synapse2))
@@ -188,10 +175,8 @@ class TestModels(unittest.TestCase):
         neuron3 = Neuron(name="test", parameters={"key1": "val1", "key2": "val2"})
 
         expected_result_serialize = {'name': 'test', 'parameters': {'key2': 'val2', 'key1': 'val1'}}
-        expected_result_str = "{'name': 'test', 'parameters': {'key2': 'val2', 'key1': 'val1'}}"
 
-        self.assertEqual(expected_result_serialize, neuron1.serialize())
-        self.assertEqual(expected_result_str, neuron1.__str__())
+        self.assertDictEqual(expected_result_serialize, neuron1.serialize())
 
         self.assertTrue(neuron1.__eq__(neuron3))
         self.assertFalse(neuron1.__eq__(neuron2))
@@ -207,9 +192,9 @@ class TestModels(unittest.TestCase):
         neuron.name = neuron_name
         neuron.parameters = neuron_parameters
 
-        expected_result = "{'name': 'test', 'parameters': {'password': '*****', 'parameter': 'test'}}"
+        expected_result_str = "{'name': 'test', 'parameters': {'password': '*****', 'parameter': 'test'}}"
 
-        self.assertEqual(neuron.__str__(), expected_result)
+        self.assertDictEqual(ast.literal_eval(neuron.__str__()), ast.literal_eval(expected_result_str))
 
         neuron_name = "test"
         neuron_parameters = {
@@ -221,9 +206,9 @@ class TestModels(unittest.TestCase):
         neuron.name = neuron_name
         neuron.parameters = neuron_parameters
 
-        expected_result = "{'name': 'test', 'parameters': {'parameter': 'test', 'password_parameter': '*****'}}"
+        expected_result_str = "{'name': 'test', 'parameters': {'parameter': 'test', 'password_parameter': '*****'}}"
 
-        self.assertEqual(neuron.__str__(), expected_result)
+        self.assertDictEqual(ast.literal_eval(neuron.__str__()), ast.literal_eval(expected_result_str))
 
     def test_Order(self):
         order1 = Order(sentence="this is an order")
@@ -255,11 +240,8 @@ class TestModels(unittest.TestCase):
             'stt_folder': '/path/stt',
             'trigger_folder': '/path/trigger'
         }
-        expected_result_str = "{'tts_folder': '/path/tts', 'neuron_folder': '/path/neuron', " \
-                              "'stt_folder': '/path/stt', 'trigger_folder': '/path/trigger'}"
 
-        self.assertEqual(expected_result_serialize, resource1.serialize())
-        self.assertEqual(expected_result_str, resource1.__str__())
+        self.assertDictEqual(expected_result_serialize, resource1.serialize())
 
         self.assertTrue(resource1.__eq__(resource3))
         self.assertFalse(resource1.__eq__(resource2))
@@ -283,11 +265,8 @@ class TestModels(unittest.TestCase):
             'password': 'password',
             'login': 'admin'
         }
-        expected_result_str = "{'password_protected': True, 'port': 5000, 'active': True, 'allowed_cors_origin': '*', " \
-                              "'password': 'password', 'login': 'admin'}"
 
-        self.assertEqual(expected_result_serialize, rest_api1.serialize())
-        self.assertEqual(expected_result_str, rest_api1.__str__())
+        self.assertDictEqual(expected_result_serialize, rest_api1.serialize())
 
         self.assertTrue(rest_api1.__eq__(rest_api3))
         self.assertFalse(rest_api1.__eq__(rest_api2))
@@ -377,17 +356,7 @@ class TestModels(unittest.TestCase):
                 'triggers': ['snowboy']
             }
 
-            expected_result_str = "{'default_synapse': 'default_synapse', 'default_tts_name': 'pico2wav', 'rest_api': " \
-                                  "{'password_protected': True, 'port': 5000, 'active': True, 'allowed_cors_origin': " \
-                                  "'*', 'password': 'password', 'login': 'admin'}, 'play_on_ready_notification': " \
-                                  "False, 'default_stt_name': 'google', 'kalliope_version': '0.4.4b', " \
-                                  "'random_wake_up_sounds': None, 'on_ready_answers': None, 'default_trigger_name': " \
-                                  "'swoyboy', 'cache_path': '/tmp/kalliope', 'stts': ['stts'], 'machine': 'pumpkins', " \
-                                  "'random_wake_up_answers': ['yes'], 'on_ready_sounds': None, 'ttss': ['ttts'], " \
-                                  "'variables': {'key1': 'val1'}, 'resources': None, 'triggers': ['snowboy']}"
-
-            self.assertEqual(expected_result_serialize, setting1.serialize())
-            self.assertEqual(expected_result_str, setting1.__str__())
+            self.assertDictEqual(expected_result_serialize, setting1.serialize())
 
             self.assertTrue(setting1.__eq__(setting3))
             self.assertFalse(setting1.__eq__(setting2))
@@ -398,10 +367,8 @@ class TestModels(unittest.TestCase):
         stt3 = Stt(name="stt1", parameters={"key1": "val1"})
 
         expected_result_serialize = {'name': 'stt1', 'parameters': {'key1': 'val1'}}
-        expected_result_str = "{'name': 'stt1', 'parameters': {'key1': 'val1'}}"
 
-        self.assertEqual(expected_result_serialize, stt1.serialize())
-        self.assertEqual(expected_result_str, stt1.__str__())
+        self.assertDictEqual(expected_result_serialize, stt1.serialize())
 
         self.assertTrue(stt1.__eq__(stt3))
         self.assertFalse(stt1.__eq__(stt2))
@@ -443,12 +410,7 @@ class TestModels(unittest.TestCase):
             'name': 'Synapse1'
         }
 
-        expected_result_str = "{'signals': [{'order': 'this is the sentence'}], 'neurons': [{'name': 'neurone1', " \
-                              "'parameters': {'var1': 'val1'}}, {'name': 'neurone2', 'parameters': {'var2': " \
-                              "'val2'}}], 'name': 'Synapse1'}"
-
-        self.assertEqual(expected_result_serialize, synapse1.serialize())
-        self.assertEqual(expected_result_str, synapse1.__str__())
+        self.assertDictEqual(expected_result_serialize, synapse1.serialize())
 
         self.assertTrue(synapse1.__eq__(synapse3))
         self.assertFalse(synapse1.__eq__(synapse2))
@@ -459,10 +421,8 @@ class TestModels(unittest.TestCase):
         trigger3 = Trigger(name="trigger1", parameters={"key1": "val1"})
 
         expected_result_serialize = {'name': 'trigger1', 'parameters': {'key1': 'val1'}}
-        expected_result_str = "{'name': 'trigger1', 'parameters': {'key1': 'val1'}}"
 
-        self.assertEqual(expected_result_serialize, trigger1.serialize())
-        self.assertEqual(expected_result_str, trigger1.__str__())
+        self.assertDictEqual(expected_result_serialize, trigger1.serialize())
 
         self.assertTrue(trigger1.__eq__(trigger3))
         self.assertFalse(trigger1.__eq__(trigger2))
@@ -473,10 +433,8 @@ class TestModels(unittest.TestCase):
         tts3 = Tts(name="tts1", parameters={"key1": "val1"})
 
         expected_result_serialize = {'name': 'tts1', 'parameters': {'key1': 'val1'}}
-        expected_result_str = "{'name': 'tts1', 'parameters': {'key1': 'val1'}}"
 
-        self.assertEqual(expected_result_serialize, tts1.serialize())
-        self.assertEqual(expected_result_str, tts1.__str__())
+        self.assertDictEqual(expected_result_serialize, tts1.serialize())
 
         self.assertTrue(tts1.__eq__(tts3))
         self.assertFalse(tts1.__eq__(tts2))

+ 6 - 6
Tests/test_neuron_parameter_loader.py

@@ -11,9 +11,9 @@ class TestNeuronParameterLoader(unittest.TestCase):
         user_order = "this is the value"
         expected_result = {'sentence': 'value'}
 
-        self.assertEquals(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")
+        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")
 
         # Multiple match
         synapse_order = "this is the {{ sentence }}"
@@ -30,7 +30,7 @@ class TestNeuronParameterLoader(unittest.TestCase):
 
         user_order = "this is the value with multiple words"
         expected_result = {'sentence': 'value',
-                            'params':'words'}
+                           'params':'words'}
 
         self.assertEqual(NeuronParameterLoader.get_parameters(synapse_order=synapse_order, user_order=user_order),
                          expected_result,
@@ -101,14 +101,14 @@ class TestNeuronParameterLoader(unittest.TestCase):
         order_brain = "This is the {variable}"
         order_user = "This is the value"
         expected_result = {'variable': 'value'}
-        self.assertNotEquals(NeuronParameterLoader._associate_order_params_to_values(order_user, order_brain),
+        self.assertNotEqual(NeuronParameterLoader._associate_order_params_to_values(order_user, order_brain),
                              expected_result)
 
         # Fail
         order_brain = "This is the { variable}}"
         order_user = "This is the value"
         expected_result = {'variable': 'value'}
-        self.assertNotEquals(NeuronParameterLoader._associate_order_params_to_values(order_user, order_brain),
+        self.assertNotEqual(NeuronParameterLoader._associate_order_params_to_values(order_user, order_brain),
                              expected_result)
 
         ##

+ 3 - 3
Tests/test_order_listener.py

@@ -39,9 +39,9 @@ class TestOrderListener(unittest.TestCase):
 
         with mock.patch("kalliope.core.Utils.get_dynamic_class_instantiation") as mock_get_dynamic_class_instantiation:
             mock_get_dynamic_class_instantiation.return_value = 'class_instance'
-            self.assertEquals(ol.load_stt_plugin(),
-                              "class_instance",
-                              "Fail getting the proper value")
+            self.assertEqual(ol.load_stt_plugin(),
+                             "class_instance",
+                             "Fail getting the proper value")
 
             mock_get_dynamic_class_instantiation.assert_called_once_with(package_name= "stt",
                                                                          module_name= "Default-stt",

+ 9 - 8
Tests/test_rest_api.py

@@ -1,6 +1,7 @@
 import json
 import os
 import unittest
+import ast
 
 from flask import Flask
 from flask_testing import LiveServerTestCase
@@ -64,7 +65,7 @@ class TestRestAPI(LiveServerTestCase):
         expected_content = {
             "Kalliope version": "%s" % version_str
         }
-        self.assertEqual(json.dumps(expected_content), json.dumps(json.loads(response.get_data())))
+        self.assertEqual(json.dumps(expected_content, sort_keys=True), json.dumps(json.loads(response.get_data().decode('utf-8')), sort_keys=True))
 
     def test_get_all_synapses(self):
         url = self.get_server_url()+"/synapses"
@@ -131,7 +132,7 @@ class TestRestAPI(LiveServerTestCase):
         # a lot of char ti process
         self.maxDiff = None
         self.assertEqual(response.status_code, 200)
-        self.assertEqual(json.dumps(expected_content), json.dumps(json.loads(response.get_data())))
+        self.assertEqual(json.dumps(expected_content, sort_keys=True), json.dumps(json.loads(response.get_data().decode('utf-8')), sort_keys=True))
 
     def test_get_one_synapse(self):
         url = self.get_server_url() + "/synapses/test"
@@ -157,7 +158,7 @@ class TestRestAPI(LiveServerTestCase):
                 ]
             }
         }
-        self.assertEqual(json.dumps(expected_content), json.dumps(json.loads(response.get_data())))
+        self.assertEqual(json.dumps(expected_content, sort_keys=True), json.dumps(json.loads(response.get_data().decode('utf-8')), sort_keys=True))
 
     def test_get_synapse_not_found(self):
         url = self.get_server_url() + "/synapses/test-none"
@@ -169,7 +170,7 @@ class TestRestAPI(LiveServerTestCase):
             }
         }
 
-        self.assertEqual(expected_content, json.loads(result.get_data()))
+        self.assertEqual(expected_content, json.loads(result.get_data().decode('utf-8')))
         self.assertEqual(result.status_code, 404)
 
     def test_run_synapse_by_name(self):
@@ -184,7 +185,7 @@ class TestRestAPI(LiveServerTestCase):
                                   'synapse_name': 'test'}],
                             'user_order': None
                             }
-        self.assertEqual(json.dumps(expected_content), json.dumps(json.loads(result.get_data())))
+        self.assertEqual(json.dumps(expected_content, sort_keys=True), json.dumps(json.loads(result.get_data().decode('utf-8')), sort_keys=True))
         self.assertEqual(result.status_code, 201)
 
     def test_post_synapse_not_found(self):
@@ -197,7 +198,7 @@ class TestRestAPI(LiveServerTestCase):
             }
         }
 
-        self.assertEqual(json.dumps(expected_content), json.dumps(json.loads(result.get_data())))
+        self.assertEqual(json.dumps(expected_content, sort_keys=True), json.dumps(json.loads(result.get_data().decode('utf-8')), sort_keys=True))
         self.assertEqual(result.status_code, 404)
 
     def test_run_synapse_with_order(self):
@@ -222,7 +223,7 @@ class TestRestAPI(LiveServerTestCase):
                                 ],
                             'user_order': "test_order"
                             }
-        self.assertEqual(json.dumps(expected_content), json.dumps(json.loads(result.get_data())))
+        self.assertEqual(json.dumps(expected_content, sort_keys=True), json.dumps(json.loads(result.get_data().decode('utf-8')), sort_keys=True))
         self.assertEqual(result.status_code, 201)
 
     def test_post_synapse_by_order_not_found(self):
@@ -235,7 +236,7 @@ class TestRestAPI(LiveServerTestCase):
 
         expected_content = {'status': None, 'matched_synapses': [], 'user_order': u'non existing order'}
 
-        self.assertEqual(json.dumps(expected_content), json.dumps(json.loads(result.get_data())))
+        self.assertEqual(json.dumps(expected_content, sort_keys=True), json.dumps(json.loads(result.get_data().decode('utf-8')), sort_keys=True))
         self.assertEqual(result.status_code, 201)
 
         # TODO this doesn't work on travis but works locally with python -m unittest discover

+ 1 - 1
Tests/test_settings_loader.py

@@ -191,7 +191,7 @@ class TestSettingLoader(unittest.TestCase):
                               trigger_folder="/tmp/kalliope/tests/kalliope_resources_dir/trigger")
         expected_resource = resources
         sl = SettingLoader(file_path=self.settings_file_to_test)
-        self.assertEquals(expected_resource, sl._get_resources(self.settings_dict))
+        self.assertEqual(expected_resource, sl._get_resources(self.settings_dict))
 
     def test_get_variables(self):
         expected_result = {

+ 3 - 3
Tests/test_singleton.py

@@ -1,15 +1,15 @@
 import unittest
+import sys
+from six import with_metaclass
 
 from kalliope.core.Models import Singleton
 
 
-class MyClass(object):
-    __metaclass__ = Singleton
+class MyClass(with_metaclass(Singleton, object)):
 
     def __init__(self):
         self.value = "test"
 
-
 class TestSingleton(unittest.TestCase):
 
     def setUp(self):

+ 6 - 6
Tests/test_tts_module.py

@@ -25,9 +25,9 @@ class TestTTSModule(unittest.TestCase):
         word = "kalliope"
         expected_result = "5c186d1e123be2667fb5fd54640e4fd0"
 
-        self.assertEquals(TTSModule.generate_md5_from_words(words=word),
-                          expected_result,
-                          "Fail md5")
+        self.assertEqual(TTSModule.generate_md5_from_words(words=word),
+                         expected_result,
+                         "Fail md5")
 
     def test_get_path_to_store_audio(self):
         """
@@ -40,9 +40,9 @@ class TestTTSModule(unittest.TestCase):
 
         expected_result = "/tmp/kalliope/tests/TTSModule/tests/default/5c186d1e123be2667fb5fd54640e4fd0.tts"
 
-        self.assertEquals(self.TTSMod._get_path_to_store_audio(),
-                          expected_result,
-                          "fail test_get_path_to_store_audio, expected path not corresponding to result")
+        self.assertEqual(self.TTSMod._get_path_to_store_audio(),
+                         expected_result,
+                         "fail test_get_path_to_store_audio, expected path not corresponding to result")
 
     def test_generate_and_play(self):
         """

+ 15 - 15
Tests/test_utils.py

@@ -26,9 +26,9 @@ class TestUtils(unittest.TestCase):
         path_to_test = "../kalliope/core/Utils"
         expected_result = os.path.normpath("../kalliope/core")
 
-        self.assertEquals(Utils.get_current_file_parent_path(path_to_test),
-                          expected_result,
-                          "fail getting the parent parent path from the given path")
+        self.assertEqual(Utils.get_current_file_parent_path(path_to_test),
+                         expected_result,
+                         "fail getting the parent parent path from the given path")
 
     def test_get_current_file_parent_parent_path(self):
         """
@@ -37,9 +37,9 @@ class TestUtils(unittest.TestCase):
         path_to_test = "../kalliope/core/Utils"
         expected_result = os.path.normpath("../kalliope")
 
-        self.assertEquals(Utils.get_current_file_parent_parent_path(path_to_test),
-                          expected_result,
-                          "fail getting the parent parent path from the given path")
+        self.assertEqual(Utils.get_current_file_parent_parent_path(path_to_test),
+                         expected_result,
+                         "fail getting the parent parent path from the given path")
 
     def test_get_real_file_path(self):
         """
@@ -61,9 +61,9 @@ class TestUtils(unittest.TestCase):
         # touch the file
         open(absolute_path_to_test, 'a').close()
 
-        self.assertEquals(Utils.get_real_file_path(absolute_path_to_test),
-                          expected_result,
-                          "Fail to match the given absolute path ")
+        self.assertEqual(Utils.get_real_file_path(absolute_path_to_test),
+                         expected_result,
+                         "Fail to match the given absolute path ")
         # Clean up
         if os.path.exists(absolute_path_to_test):
             os.remove(absolute_path_to_test)
@@ -76,9 +76,9 @@ class TestUtils(unittest.TestCase):
         # touch the file
         open(file_name, 'a').close()
 
-        self.assertEquals(Utils.get_real_file_path(file_name),
-                          expected_result,
-                          "Fail to match the Current path ")
+        self.assertEqual(Utils.get_real_file_path(file_name),
+                         expected_result,
+                         "Fail to match the Current path ")
         # Clean up
         if os.path.exists(file_name):
             os.remove(file_name)
@@ -115,9 +115,9 @@ class TestUtils(unittest.TestCase):
         # touch the file
         open(path_to_test, 'a').close()
 
-        self.assertEquals(Utils.get_real_file_path(file_name),
-                          expected_result,
-                          "Fail to match the /an/unknown/path/kalliope path")
+        self.assertEqual(Utils.get_real_file_path(file_name),
+                         expected_result,
+                         "Fail to match the /an/unknown/path/kalliope path")
         # Clean up
         if os.path.exists(expected_result):
             os.remove(expected_result)

+ 1 - 1
install/files/python_requirements.txt

@@ -4,7 +4,7 @@ markupsafe==0.23
 pyaudio==0.2.9
 pyasn1>=0.1.8
 ansible==2.2.0.0
-python2-pythondialog==3.4.0
+#python2-pythondialog==3.4.0
 jinja2==2.8
 cffi==1.9.1
 ipaddress==1.0.17

+ 2 - 2
kalliope/__init__.py

@@ -10,7 +10,7 @@ from kalliope.core.ConfigurationManager.BrainLoader import BrainLoader
 from kalliope.core.EventManager import EventManager
 from kalliope.core.MainController import MainController
 
-from _version import version_str
+from ._version import version_str
 import signal
 import sys
 
@@ -30,7 +30,7 @@ def signal_handler(signal, frame):
     :param frame: execution frame
 
     """
-    print "\n"
+    print("\n")
     Utils.print_info("Ctrl+C pressed. Killing Kalliope")
     sys.exit(0)
 

+ 6 - 5
kalliope/core/ConfigurationManager/BrainLoader.py

@@ -1,8 +1,10 @@
 import inspect
 import logging
 import os
+from six import with_metaclass
+import six
 
-from YAMLLoader import YAMLLoader
+from .YAMLLoader import YAMLLoader
 from kalliope.core.Utils import Utils
 from kalliope.core.ConfigurationManager import SettingLoader
 from kalliope.core.ConfigurationManager.ConfigurationChecker import ConfigurationChecker
@@ -23,11 +25,10 @@ class BrainNotFound(Exception):
     pass
 
 
-class BrainLoader(object):
+class BrainLoader(with_metaclass(Singleton, object)):
     """
     This Class is used to get the brain YAML and the Brain as an object
     """
-    __metaclass__ = Singleton
 
     def __init__(self, file_path=None):
         sl = SettingLoader()
@@ -252,7 +253,7 @@ class BrainLoader(object):
         """
 
         if isinstance(parameter, dict):
-            for key, value in parameter.iteritems():
+            for key, value in parameter.items():
                 parameter[key] = cls._replace_global_variables(value, settings=settings)
             return parameter
         if isinstance(parameter, list):
@@ -260,7 +261,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) or isinstance(parameter, int):
+        if isinstance(parameter, str) or isinstance(parameter, six.text_type) or isinstance(parameter, int):
             if Utils.is_containing_bracket(parameter):
                 return cls._get_global_variable(sentence=parameter, settings=settings)
             return parameter

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

@@ -288,6 +288,6 @@ class ConfigurationChecker:
             synapse_name = synapse.name.encode('utf-8')
             if synapse_name in seen:
                 raise MultipleSameSynapseName("Multiple synapse found with the same name: %s" % synapse_name)
-            seen.add(synapse.name)
+            seen.add(synapse_name)
 
         return True

+ 11 - 11
kalliope/core/ConfigurationManager/SettingLoader.py

@@ -1,7 +1,8 @@
 import logging
 import os
+from six import with_metaclass
 
-from YAMLLoader import YAMLLoader
+from .YAMLLoader import YAMLLoader
 from kalliope.core.Models.Resources import Resources
 from kalliope.core.Utils.Utils import Utils
 from kalliope.core.Models import Singleton
@@ -45,11 +46,10 @@ class SettingNotFound(Exception):
     pass
 
 
-class SettingLoader(object):
+class SettingLoader(with_metaclass(Singleton, object)):
     """
     This Class is used to get the Settings YAML and the Settings as an object
     """
-    __metaclass__ = Singleton
 
     def __init__(self, file_path=None):
         self.file_path = file_path
@@ -159,7 +159,7 @@ class SettingLoader(object):
                 raise NullSettingException("Attribute default_speech_to_text is null")
             logger.debug("Default STT: %s" % default_speech_to_text)
             return default_speech_to_text
-        except KeyError, e:
+        except KeyError as e:
             raise SettingNotFound("%s setting not found" % e)
 
     @staticmethod
@@ -187,7 +187,7 @@ class SettingLoader(object):
                 raise NullSettingException("Attribute default_text_to_speech is null")
             logger.debug("Default TTS: %s" % default_text_to_speech)
             return default_text_to_speech
-        except KeyError, e:
+        except KeyError as e:
             raise SettingNotFound("%s setting not found" % e)
 
     @staticmethod
@@ -214,7 +214,7 @@ class SettingLoader(object):
                 raise NullSettingException("Attribute default_trigger is null")
             logger.debug("Default Trigger name: %s" % default_trigger)
             return default_trigger
-        except KeyError, e:
+        except KeyError as e:
             raise SettingNotFound("%s setting not found" % e)
 
     @staticmethod
@@ -277,7 +277,7 @@ class SettingLoader(object):
 
         try:
             text_to_speech_list = settings["text_to_speech"]
-        except KeyError, e:
+        except KeyError as e:
             raise SettingNotFound("%s setting not found" % e)
 
         ttss = list()
@@ -315,7 +315,7 @@ class SettingLoader(object):
 
         try:
             triggers_list = settings["triggers"]
-        except KeyError, e:
+        except KeyError as e:
             raise SettingNotFound("%s setting not found" % e)
 
         triggers = list()
@@ -419,7 +419,7 @@ class SettingLoader(object):
 
         try:
             rest_api = settings["rest_api"]
-        except KeyError, e:
+        except KeyError as e:
             raise SettingNotFound("%s setting not found" % e)
 
         if rest_api is not None:
@@ -454,7 +454,7 @@ class SettingLoader(object):
                 if "allowed_cors_origin" in rest_api:
                      allowed_cors_origin = rest_api["allowed_cors_origin"]
 
-            except KeyError, e:
+            except KeyError as e:
                 raise SettingNotFound("%s settings not found" % e)
 
             # config ok, we can return the rest api object
@@ -485,7 +485,7 @@ class SettingLoader(object):
 
         try:
             cache_path = settings["cache_path"]
-        except KeyError, e:
+        except KeyError as e:
             raise SettingNotFound("%s setting not found" % e)
 
         if cache_path is None:

+ 4 - 2
kalliope/core/ConfigurationManager/YAMLLoader.py

@@ -72,7 +72,8 @@ class IncludeImport(object):
         parent_dir = os.path.normpath(file_path + os.sep + os.pardir)
 
         # load the yaml file
-        self.data = yaml.load(open(file_path, 'r'))
+        with open(file_path, "r") as f:
+            self.data = yaml.load(f)
 
         if self.data is None:
             raise YAMLFileEmpty("File %s is empty" % file_path)
@@ -86,7 +87,8 @@ class IncludeImport(object):
                             # logger.debug("File path %s is relative, adding the root path" % inc)
                             inc = os.path.join(parent_dir, inc)
                             # logger.debug("New path: %s" % inc)
-                        self.update(yaml.load(open(inc)))
+                        with open(inc, "r") as f:
+                            self.update(yaml.load(f))
 
     def get_data(self):
         """

+ 3 - 3
kalliope/core/ConfigurationManager/__init__.py

@@ -1,3 +1,3 @@
-from YAMLLoader import YAMLLoader
-from SettingLoader import SettingLoader
-from BrainLoader import BrainLoader
+from .YAMLLoader import YAMLLoader
+from .SettingLoader import SettingLoader
+from .BrainLoader import BrainLoader

+ 1 - 1
kalliope/core/Models/Neuron.py

@@ -33,7 +33,7 @@ class Neuron(object):
         }
 
         cleaned_parameters = dict()
-        for key, value in self.parameters.iteritems():
+        for key, value in self.parameters.items():
             if "password" in key:
                 cleaned_parameters[key] = "*****"
             else:

+ 7 - 7
kalliope/core/Models/__init__.py

@@ -1,8 +1,8 @@
-from Singleton import Singleton
-from Event import Event
-from Resources import Resources
-from Brain import Brain
-from Order import Order
-from Synapse import Synapse
-from Neuron import Neuron
+from .Singleton import Singleton
+from .Event import Event
+from .Resources import Resources
+from .Brain import Brain
+from .Order import Order
+from .Synapse import Synapse
+from .Neuron import Neuron
 

+ 2 - 2
kalliope/core/NeuronLauncher.py

@@ -1,5 +1,5 @@
 import logging
-
+import six
 import jinja2
 
 from kalliope.core.Utils.Utils import Utils
@@ -66,7 +66,7 @@ class NeuronLauncher:
         :param loaded_parameters: dict of parameters
         """
         logger.debug("[NeuronLauncher] replacing brackets from %s, using %s" % (neuron_parameters, loaded_parameters))
-        if isinstance(neuron_parameters, str) or isinstance(neuron_parameters, unicode):
+        if isinstance(neuron_parameters, str) or isinstance(neuron_parameters, six.text_type):
             # replace bracket parameter only if the str contains brackets
             if Utils.is_containing_bracket(neuron_parameters):
                 # check that the parameter to replace is available in the loaded_parameters dict

+ 8 - 6
kalliope/core/NeuronModule.py

@@ -2,6 +2,7 @@
 import logging
 import random
 import sys
+import six
 
 from jinja2 import Template
 
@@ -79,10 +80,9 @@ class NeuronModule(object):
             # we get the default TTS
             self.tts = self._get_tts_object(settings=self.settings)
         else:
-            for key, value in self.override_tts_parameters.iteritems():
+            for key, value in self.override_tts_parameters.items():
                 tts_name = key
                 tts_parameters = value
-                print tts_parameters
                 self.tts = self._get_tts_object(tts_name=tts_name,
                                                 override_parameter=tts_parameters,
                                                 settings=self.settings)
@@ -133,10 +133,11 @@ class NeuronModule(object):
 
         tts_message = None
 
-        if isinstance(message, str) or isinstance(message, unicode):
+        if isinstance(message, str) or isinstance(message, six.text_type):
             logger.debug("message is string")
             tts_message = message
 
+
         if isinstance(message, list):
             logger.debug("message is list")
             tts_message = random.choice(message)
@@ -176,8 +177,9 @@ class NeuronModule(object):
             returned_message = self._get_say_template(self.say_template, message_dict)
 
         # trick to remove unicode problem when loading jinja template with non ascii char
-        reload(sys)
-        sys.setdefaultencoding('utf-8')
+        if sys.version_info[0] == 2:
+            reload(sys)
+            sys.setdefaultencoding('utf-8')
 
         # the user chooses a file_template option
         if self.file_template is not None:  # the user choose a file_template option
@@ -279,7 +281,7 @@ class NeuronModule(object):
 
         if override_parameter is not None:  # the user want to override the default TTS configuration
             logger.debug("args for TTS plugin before update: %s" % str(tts_object.parameters))
-            for key, value in override_parameter.iteritems():
+            for key, value in override_parameter.items():
                 tts_object.parameters[key] = value
             logger.debug("args for TTS plugin after update: %s" % str(tts_object.parameters))
 

+ 3 - 1
kalliope/core/OrderAnalyser.py

@@ -1,6 +1,8 @@
 # coding: utf8
 import collections
 from collections import Counter
+import sys
+import six
 
 from kalliope.core.Models.MatchedSynapse import MatchedSynapse
 from kalliope.core.Utils.Utils import Utils
@@ -35,7 +37,7 @@ class OrderAnalyser:
         """
         cls.brain = brain
         logger.debug("[OrderAnalyser] Received order: %s" % order)
-        if isinstance(order, str):
+        if isinstance(order, six.binary_type):
             order = order.decode('utf-8')
 
         # We use a namedtuple to associate the synapse and the signal of the synapse

+ 1 - 1
kalliope/core/Players/__init__.py

@@ -1 +1 @@
-from Mplayer import Mplayer
+from .Mplayer import Mplayer

+ 1 - 1
kalliope/core/ShellGui.py

@@ -23,7 +23,7 @@ def signal_handler(signal, frame):
     :param signal: signal handler
     :param frame: execution frame
     """
-    print "\n"
+    print("\n")
     Utils.print_info("Ctrl+C pressed. Killing Kalliope")
     sys.exit(0)
 

+ 3 - 1
kalliope/core/TTS/TTSModule.py

@@ -2,6 +2,8 @@
 import hashlib
 import logging
 import os
+import sys
+import six
 
 from kalliope.core.ConfigurationManager import SettingLoader
 from kalliope.core.Players import Mplayer
@@ -132,7 +134,7 @@ class TTSModule(object):
         :param words: Text to convert into md5 hash
         :return: String md5 hash from the received words
         """
-        if isinstance(words, unicode):
+        if isinstance(words, six.text_type):
             words = words.encode('utf-8')
         return hashlib.md5(words).hexdigest()
 

+ 1 - 1
kalliope/core/TTS/__init__.py

@@ -1 +1 @@
-from TTSModule import TTSModule
+from .TTSModule import TTSModule

+ 1 - 1
kalliope/core/Utils/FileManager.py

@@ -36,7 +36,7 @@ class FileManager:
         """
         try:
             with open(file_path, "wb") as file_open:
-                file_open.write(content)
+                file_open.write(content.encode())
                 file_open.close()
             return not FileManager.file_is_empty(file_path)
         except IOError as e:

+ 8 - 4
kalliope/core/Utils/Utils.py

@@ -2,14 +2,18 @@ import logging
 import os
 import inspect
 import imp
+import sys
 import re
+import six
 
 logging.basicConfig()
 logger = logging.getLogger("kalliope")
 
 
 def pipe_print(line):
-    print(line.encode('utf-8'))
+    if sys.version_info[0] < 3:
+        line = line.encode('utf-8')
+    print(line)
 
 
 class ModuleNotFoundError(Exception):
@@ -240,7 +244,7 @@ class Utils(object):
         # print "sentence to test %s" % sentence
         pattern = r"{{|}}"
         # prog = re.compile(pattern)
-        if not isinstance(sentence, unicode):
+        if not isinstance(sentence, six.text_type):
             sentence = str(sentence)
         check_bool = re.search(pattern, sentence)
         if check_bool is not None:
@@ -257,7 +261,7 @@ class Utils(object):
 
         pattern = r"((?:{{\s*)[\w\.]+(?:\s*}}))"
         # find everything like {{ word }}
-        if not isinstance(sentence, unicode):
+        if not isinstance(sentence, six.text_type):
             sentence = str(sentence)
         return re.findall(pattern, sentence)
 
@@ -271,7 +275,7 @@ class Utils(object):
 
         pattern = '\s+(?=[^\{\{\}\}]*\}\})'
         # Remove white spaces (if any) between the variable and the double brace then split
-        if not isinstance(sentence, unicode):
+        if not isinstance(sentence, six.text_type):
             sentence = str(sentence)
         return re.sub(pattern, '', sentence)
 

+ 1 - 1
kalliope/neurons/ansible_playbook/__init__.py

@@ -1 +1 @@
-from ansible_playbook import Ansible_playbook
+from .ansible_playbook import Ansible_playbook

+ 1 - 1
kalliope/neurons/kill_switch/__init__.py

@@ -1 +1 @@
-from kill_switch import Kill_switch
+from .kill_switch import Kill_switch

+ 1 - 1
kalliope/neurons/neurotransmitter/__init__.py

@@ -1 +1 @@
-from neurotransmitter import Neurotransmitter
+from .neurotransmitter import Neurotransmitter

+ 1 - 1
kalliope/neurons/say/__init__.py

@@ -1 +1 @@
-from say import Say
+from .say import Say

+ 1 - 1
kalliope/neurons/script/__init__.py

@@ -1 +1 @@
-from script import Script
+from .script import Script

+ 1 - 1
kalliope/neurons/script/script.py

@@ -39,7 +39,7 @@ class Script(NeuronModule):
             if not self.async:
                 p = subprocess.Popen(self.path, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=False)
                 (output, err) = p.communicate()
-                self.output = output
+                self.output = output.decode()
                 self.returncode = p.returncode
                 message = {
                     "output": self.output,

+ 2 - 2
kalliope/neurons/script/tests/test_script.py

@@ -48,7 +48,7 @@ class TestScript(unittest.TestCase):
         text_to_write = "[kalliope-test] TestScript - testParameters"
         with open(tmp_file_path, 'w') as myFile:
             myFile.write(text_to_write)
-        os.chmod(tmp_file_path, 0600)
+        os.chmod(tmp_file_path, 0o600)
         # test the user does not have access
         self.path = tmp_file_path
         parameters = {
@@ -56,7 +56,7 @@ class TestScript(unittest.TestCase):
         }
         run_test_invalid_param(parameters)
         # Remove the tmp file
-        os.chmod(tmp_file_path, 0700)
+        os.chmod(tmp_file_path, 0o700)
         os.remove(tmp_file_path)
 
     def test_script_execution(self):

+ 1 - 1
kalliope/neurons/shell/__init__.py

@@ -1 +1 @@
-from shell import Shell
+from .shell import Shell

+ 1 - 1
kalliope/neurons/shell/shell.py

@@ -50,7 +50,7 @@ class Shell(NeuronModule):
             if not self.async:
                 p = subprocess.Popen(self.cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
                 (output, err) = p.communicate()
-                self.output = output
+                self.output = output.decode()
                 self.returncode = p.returncode
                 message = {
                     "output": self.output,

+ 1 - 1
kalliope/neurons/sleep/__init__.py

@@ -1 +1 @@
-from sleep import Sleep
+from .sleep import Sleep

+ 2 - 1
kalliope/neurons/sleep/sleep.py

@@ -1,4 +1,5 @@
 import time
+import six
 
 from kalliope.core.NeuronModule import NeuronModule,  MissingParameterException
 
@@ -12,7 +13,7 @@ class Sleep(NeuronModule):
         if self._is_parameters_ok():
 
             if isinstance(self.seconds, str) or \
-                    isinstance(self.seconds, unicode):
+                    isinstance(self.seconds, six.text_type):
                 self.seconds = float(self.seconds)
 
             time.sleep(self.seconds)

+ 1 - 1
kalliope/neurons/systemdate/__init__.py

@@ -1 +1 @@
-from systemdate import Systemdate
+from .systemdate import Systemdate

+ 3 - 3
kalliope/neurons/uri/tests/test_uri_neuron.py

@@ -25,7 +25,7 @@ class TestUri(unittest.TestCase):
         self.assertEqual(uri_neuron.text, expected_content)
 
     def testGetRaw(self):
-        expected_content = 'raw line'
+        expected_content = b'raw line'
         httpretty.enable()
         httpretty.register_uri(httpretty.GET, self.test_url, body=expected_content)
         parameters = {
@@ -151,7 +151,7 @@ class TestUri(unittest.TestCase):
         :return:
         """
         def request_callback(request, url, headers):
-            data = json.loads(request.body)
+            data = json.loads(request.body.decode())
             if "title" in data and "body" in data and "userId" in data:
                 return 200, headers, "all key received from URL %s" % url
 
@@ -178,7 +178,7 @@ class TestUri(unittest.TestCase):
         :return:
         """
         def request_callback(request, url, headers):
-            data = json.loads(request.body)
+            data = json.loads(request.body.decode())
             if "title" in data and "body" in data and "userId" in data:
                 return 200, headers, "all key received from URL %s" % url
 

+ 3 - 3
kalliope/neurons/uri/uri.py

@@ -127,7 +127,7 @@ class Uri(NeuronModule):
         self.content = r.content
         # we try to load into a json object the content. So Kalliope can use it to talk
         try:
-            self.content = json.loads(self.content)
+            self.content = json.loads(self.content.decode())
         except ValueError:
             logger.debug(self.neuron_name + "cannot get a valid json from returned content")
             pass
@@ -161,7 +161,7 @@ class Uri(NeuronModule):
         if self.data is not None:
             try:
                 json.loads(self.data)
-            except ValueError, e:
+            except ValueError as e:
                 raise InvalidParameterException("error in \"data\" parameter: %s" % e)
 
         # data_from_file path must exist and data inside must be loadable by json
@@ -172,7 +172,7 @@ class Uri(NeuronModule):
             # then try to load the json from the file
             try:
                 self.data_from_file = self.readfile(self.data_from_file)
-            except ValueError, e:
+            except ValueError as e:
                 raise InvalidParameterException("error in \"data\" parameter: %s" % e)
 
         # we cannot provide both data and data from file

+ 1 - 1
kalliope/stt/apiai/__init__.py

@@ -1 +1 @@
-from apiai import Apiai
+from .apiai import Apiai

+ 1 - 1
kalliope/stt/bing/__init__.py

@@ -1 +1 @@
-from bing import Bing
+from .bing import Bing

+ 1 - 1
kalliope/stt/cmusphinx/__init__.py

@@ -1 +1 @@
-from cmusphinx import Cmusphinx
+from .cmusphinx import Cmusphinx

+ 1 - 1
kalliope/stt/google/__init__.py

@@ -1 +1 @@
-from google import Google
+from .google import Google

+ 1 - 1
kalliope/stt/houndify/__init__.py

@@ -1 +1 @@
-from houndify import Houndify
+from .houndify import Houndify

+ 1 - 1
kalliope/stt/wit/__init__.py

@@ -1 +1 @@
-from wit import Wit
+from .wit import Wit

+ 1 - 1
kalliope/trigger/snowboy/__init__.py

@@ -1 +1 @@
-from snowboy import Snowboy
+from .snowboy import Snowboy

+ 0 - 0
kalliope/trigger/snowboy/armv7l/_snowboydetect.so → kalliope/trigger/snowboy/armv7l/python27/_snowboydetect.so


+ 1 - 1
kalliope/trigger/snowboy/snowboydecoder.py

@@ -4,7 +4,7 @@ import collections
 from threading import Thread
 
 import pyaudio
-import snowboydetect
+from . import snowboydetect
 import time
 import os
 import logging

+ 1 - 1
kalliope/trigger/snowboy/snowboydetect.py

@@ -8,7 +8,7 @@ from sys import version_info
 
 sl = SettingLoader()
 settings = sl.settings
-module_file_path = "%s/_snowboydetect" % settings.machine
+module_file_path = "%s/python%d%d/_snowboydetect" % (settings.machine, version_info[0], version_info[1])
 
 
 if version_info >= (2, 6, 0):

+ 0 - 0
kalliope/trigger/snowboy/x86_64/_snowboydetect.so → kalliope/trigger/snowboy/x86_64/python27/_snowboydetect.so


BIN
kalliope/trigger/snowboy/x86_64/python34/_snowboydetect.so


BIN
kalliope/trigger/snowboy/x86_64/python35/_snowboydetect.so


BIN
kalliope/trigger/snowboy/x86_64/python36/_snowboydetect.so


+ 1 - 1
kalliope/tts/acapela/__init__.py

@@ -1 +1 @@
-from acapela import Acapela
+from .acapela import Acapela

+ 1 - 1
kalliope/tts/googletts/__init__.py

@@ -1 +1 @@
-from googletts import Googletts
+from .googletts import Googletts

+ 1 - 1
kalliope/tts/pico2wave/__init__.py

@@ -1 +1 @@
-from pico2wave import Pico2wave
+from .pico2wave import Pico2wave

+ 1 - 1
kalliope/tts/voicerss/__init__.py

@@ -1 +1 @@
-from voicerss import Voicerss
+from .voicerss import Voicerss

+ 11 - 3
setup.py

@@ -1,6 +1,7 @@
 #! /usr/bin/env python
 # -*- coding: utf-8 -*-
 import re
+import sys
 from setuptools import setup, find_packages
 from codecs import open
 from os import path
@@ -27,6 +28,10 @@ def read_version_py(file_name):
 VERSION_PY_FILENAME = 'kalliope/_version.py'
 version = read_version_py(VERSION_PY_FILENAME)
 
+py2_prefix = ''
+if sys.version_info[0] < 3:
+    py2_prefix = 'python2-'
+
 setup(
     name='kalliope',
     version=version,
@@ -63,7 +68,7 @@ setup(
         'pyaudio>=0.2.10',
         'pyasn1>=0.2.3',
         'ansible>=2.2',
-        'python2-pythondialog>=3.4.0',
+        py2_prefix + 'pythondialog>=3.4.0',
         'jinja2>=2.8,<=2.9.6',
         'cffi>=1.9.1',
         'ipaddress>=1.0.17',
@@ -86,8 +91,11 @@ setup(
         'kalliope': [
             'brain.yml',
             'settings.yml',
-            'trigger/snowboy/armv7l/_snowboydetect.so',
-            'trigger/snowboy/x86_64/_snowboydetect.so',
+            'trigger/snowboy/armv7l/python27/_snowboydetect.so',
+            'trigger/snowboy/x86_64/python27/_snowboydetect.so',
+            'trigger/snowboy/x86_64/python34/_snowboydetect.so',
+            'trigger/snowboy/x86_64/python35/_snowboydetect.so',
+            'trigger/snowboy/x86_64/python36/_snowboydetect.so',
             'trigger/snowboy/resources/*',
             'sounds/*'
          ],