Browse Source

Merged branch dev into audio_api

nico 8 years ago
parent
commit
11a144408a
3 changed files with 25 additions and 10 deletions
  1. 1 0
      Docs/neuron_list.md
  2. 15 7
      Tests/test_utils.py
  3. 9 3
      kalliope/core/Utils/Utils.py

+ 1 - 0
Docs/neuron_list.md

@@ -23,6 +23,7 @@ A neuron is a module that will perform some actions attached to an order. You ca
 | [facebook](https://github.com/kalliope-project/kalliope_neuron_facebook)             | Post and Read message on Facebook                                                        |
 | [gmail_checker](https://github.com/kalliope-project/kalliope_neuron_gmail)           | Get the number of unread email and their subjects from a gmail account             |
 | [google agenda](https://github.com/bacardi55/kalliope-google-calendar)               | Get your next meetings on google calendar                                               |
+| [google maps](https://github.com/bacardi55/kalliope-gmaps)                           | Get address / distance / time / directions from Google maps |
 | [hue](https://github.com/kalliope-project/kalliope_neuron_hue)                       | Control the Philips Hue lighting system  |
 | [list available orders](https://github.com/bacardi55/kalliope-list-available-orders) | Let kalliope tell you what she how she can help                                         |
 | [MPD](https://github.com/bacardi55/kalliope-mpd)                                     | Play music via an MPD server                                                            |

+ 15 - 7
Tests/test_utils.py

@@ -1,15 +1,14 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
 import unittest
 import os
-import mock
 
 from kalliope.core.Models.Neuron import Neuron
-from kalliope.core.Models.Order import Order
-from kalliope.core.Models.Synapse import Synapse
 from kalliope.neurons.say.say import Say
 from kalliope.core.Utils.Utils import Utils
 
 from kalliope.core.ConfigurationManager import SettingLoader
-from kalliope.core.ConfigurationManager import BrainLoader
 
 
 class TestUtils(unittest.TestCase):
@@ -138,7 +137,6 @@ class TestUtils(unittest.TestCase):
                                    Say),
                         "Fail instantiate a class")
 
-
     def test_is_containing_bracket(self):
         #  Success
         order_to_test = "This test contains {{ bracket }}"
@@ -157,16 +155,26 @@ class TestUtils(unittest.TestCase):
         self.assertTrue(Utils.is_containing_bracket(order_to_test),
                         "Fail returning True when order contains no spaced bracket")
 
-        #  Failure
+        # Failure
         order_to_test = "This test does not contain bracket"
         self.assertFalse(Utils.is_containing_bracket(order_to_test),
                          "Fail returning False when order has no brackets")
 
-        #  Behaviour
+        # Behaviour
         order_to_test = ""
         self.assertFalse(Utils.is_containing_bracket(order_to_test),
                          "Fail returning False when no order")
 
+        # Behaviour int
+        order_to_test = 6
+        self.assertFalse(Utils.is_containing_bracket(order_to_test),
+                         "Fail returning False when an int")
+
+        # Behaviour unicode
+        order_to_test = "j'aime les goûters l'été"
+        self.assertFalse(Utils.is_containing_bracket(order_to_test),
+                         "Fail returning False when an int")
+
     def test_get_next_value_list(self):
         # Success
         list_to_test = {1, 2, 3}

+ 9 - 3
kalliope/core/Utils/Utils.py

@@ -232,7 +232,9 @@ class Utils(object):
         # print "sentence to test %s" % sentence
         pattern = r"{{|}}"
         # prog = re.compile(pattern)
-        check_bool = re.search(pattern, str(sentence))
+        if not isinstance(sentence, unicode):
+            sentence = str(sentence)
+        check_bool = re.search(pattern, sentence)
         if check_bool is not None:
             return True
         return False
@@ -247,7 +249,9 @@ class Utils(object):
 
         pattern = r"((?:{{\s*)[\w\.]+(?:\s*}}))"
         # find everything like {{ word }}
-        return re.findall(pattern, str(sentence))
+        if not isinstance(sentence, unicode):
+            sentence = str(sentence)
+        return re.findall(pattern, sentence)
 
     @staticmethod
     def remove_spaces_in_brackets(sentence):
@@ -259,7 +263,9 @@ class Utils(object):
 
         pattern = '\s+(?=[^\{\{\}\}]*\}\})'
         # Remove white spaces (if any) between the variable and the double brace then split
-        return re.sub(pattern, '', str(sentence))
+        if not isinstance(sentence, unicode):
+            sentence = str(sentence)
+        return re.sub(pattern, '', sentence)
 
     ##################
     #