Browse Source

[Test] replace ffmpeg to libav-tools and start refactoring test

In progress
ThiBuff 7 years ago
parent
commit
dec1438350

+ 0 - 1
.travis.yml

@@ -14,7 +14,6 @@ before_install:
 - sudo add-apt-repository "deb http://archive.ubuntu.com/ubuntu trusty main restricted universe multiverse"
 - sudo add-apt-repository "deb http://archive.ubuntu.com/ubuntu trusty-updates main restricted universe multiverse"
 - sudo add-apt-repository "deb http://archive.ubuntu.com/ubuntu trusty-backports main restricted universe multiverse"
-- sudo add-apt-repository ppa:mc3man/trusty-media -y
 - sudo apt-get update
 - sudo apt-get install $(cat install/files/deb-packages_requirements.txt)
 - sudo apt-get install libstdc++6

+ 12 - 3
Tests/test_models.py

@@ -16,7 +16,7 @@ from kalliope.core.Models.Dna import Dna
 from kalliope.core import LIFOBuffer
 from kalliope.core.Models.Settings import Settings
 
-from kalliope.core.Models import Neuron, Order, Synapse, Brain, Event, Resources
+from kalliope.core.Models import Neuron, Order, Synapse, Brain, Event, Resources, Singleton
 
 from kalliope.core.Models.APIResponse import APIResponse
 from kalliope.core.Models.MatchedSynapse import MatchedSynapse
@@ -25,6 +25,9 @@ from kalliope.core.Models.MatchedSynapse import MatchedSynapse
 class TestModels(unittest.TestCase):
 
     def setUp(self):
+        # Kill the singleton
+        Singleton._instances = dict()
+
         # Init
         neuron1 = Neuron(name='neurone1', parameters={'var1': 'val1'})
         neuron2 = Neuron(name='neurone2', parameters={'var2': 'val2'})
@@ -275,7 +278,10 @@ class TestModels(unittest.TestCase):
 
     def test_Settings(self):
         with mock.patch('platform.machine', return_value='pumpkins'):
-            rest_api1 = RestAPI(password_protected=True, login="admin", password="password", active=True,
+            rest_api1 = RestAPI(password_protected=True,
+                                login="admin",
+                                password="password",
+                                active=True,
                                 port=5000, allowed_cors_origin="*")
 
             setting1 = Settings(default_tts_name="pico2wav",
@@ -296,6 +302,7 @@ class TestModels(unittest.TestCase):
                                 default_synapse="default_synapse",
                                 resources=None,
                                 variables={"key1": "val1"})
+            setting1.kalliope_version = "0.4.5"
 
             setting2 = Settings(default_tts_name="accapela",
                                 default_stt_name="bing",
@@ -314,6 +321,7 @@ class TestModels(unittest.TestCase):
                                 default_synapse="my_default_synapse",
                                 resources=None,
                                 variables={"key1": "val1"})
+            setting2.kalliope_version = "0.4.5"
 
             setting3 = Settings(default_tts_name="pico2wav",
                                 default_stt_name="google",
@@ -333,6 +341,7 @@ class TestModels(unittest.TestCase):
                                 default_synapse="default_synapse",
                                 resources=None,
                                 variables={"key1": "val1"})
+            setting3.kalliope_version = "0.4.5"
 
             expected_result_serialize = {
                 'default_synapse': 'default_synapse',
@@ -348,7 +357,7 @@ class TestModels(unittest.TestCase):
                     },
                 'play_on_ready_notification': False,
                 'default_stt_name': 'google',
-                'kalliope_version': '0.4.4b',
+                'kalliope_version': '0.4.5',
                 'random_wake_up_sounds': None,
                 'on_ready_answers': None,
                 'default_trigger_name': 'swoyboy',

+ 10 - 1
Tests/test_neuron_module.py

@@ -1,6 +1,8 @@
 import os
 import unittest
 import mock
+
+from kalliope.core.Models import Singleton
 from kalliope.core.Models.Tts import Tts
 
 from kalliope import SettingLoader
@@ -10,6 +12,9 @@ from kalliope.core.NeuronModule import NeuronModule, TemplateFileNotFoundExcepti
 class TestNeuronModule(unittest.TestCase):
 
     def setUp(self):
+        # kill singleton
+        Singleton._instances = dict()
+
         self.expected_result = "hello, this is a replaced word"
         # this allow us to run the test from an IDE and from the root with python -m unittest tests.TestNeuronModule
         if "/Tests" in os.getcwd():
@@ -22,7 +27,11 @@ class TestNeuronModule(unittest.TestCase):
         }
         self.neuron_module_test = NeuronModule()
 
-        self.settings = SettingLoader(file_path="settings_test.yml").settings
+        if "/Tests" in os.getcwd():
+            self.file_settings = "settings/settings_test.yml"
+        else:
+            self.file_settings = "Tests/settings/settings_test.yml"
+        self.settings = SettingLoader(file_path=self.file_settings).settings
 
     def tearDown(self):
         del self.neuron_module_test

+ 1 - 1
install/files/deb-packages_requirements.txt

@@ -20,4 +20,4 @@ build-essential
 sox
 libatlas3-base
 mplayer
-ffmpeg
+libav-tools

+ 1 - 1
kalliope/PlayerModule.py → kalliope/core/PlayerModule.py

@@ -33,7 +33,7 @@ class PlayerModule(object):
         # temp file
         tmp_file_wav = file_path_mp3 + ".wav"
         # Convert mp3 to wave
-        subprocess.call(['ffmpeg', '-y', '-i', file_path_mp3, tmp_file_wav],
+        subprocess.call(['avconv', '-y', '-i', file_path_mp3, tmp_file_wav],
                         stdout=fnull, stderr=fnull)
         # remove the original file
         FileManager.remove_file(file_path_mp3)

+ 1 - 0
kalliope/core/__init__.py

@@ -9,5 +9,6 @@ from kalliope.core.SynapseLauncher import SynapseLauncher
 from kalliope.core.LIFOBuffer import LIFOBuffer
 from kalliope.core.NeuronParameterLoader import NeuronParameterLoader
 from kalliope.core.NeuronModule import NeuronModule
+from kalliope.core.PlayerModule import PlayerModule
 from kalliope.core.MainController import MainController
 from kalliope.core.EventManager import EventManager

+ 1 - 1
kalliope/players/pyalsaaudio/pyalsaaudio.py

@@ -3,7 +3,7 @@ import alsaaudio
 import logging
 import wave
 
-from kalliope.PlayerModule import PlayerModule
+from kalliope.core.PlayerModule import PlayerModule
 
 logging.basicConfig()
 logger = logging.getLogger("kalliope")

+ 1 - 1
kalliope/players/pyaudioplayer/pyaudioplayer.py

@@ -4,7 +4,7 @@ import wave
 
 import pyaudio
 
-from kalliope.PlayerModule import PlayerModule
+from kalliope.core.PlayerModule import PlayerModule
 
 logging.basicConfig()
 logger = logging.getLogger("kalliope")

+ 3 - 2
kalliope/players/sounddeviceplayer/sounddeviceplayer.py

@@ -1,9 +1,10 @@
 # -*- coding: utf-8 -*-
+import logging
+
 import sounddevice as sd
 import soundfile as sf
-import logging
 
-from kalliope.PlayerModule import PlayerModule
+from kalliope.core.PlayerModule import PlayerModule
 
 logging.basicConfig()
 logger = logging.getLogger("kalliope")