]> git.parisson.com Git - timeside.git/commitdiff
Improve Yaafe analyzer and corresponding test function.
authorThomas Fillon <thomas@parisson.com>
Mon, 30 Sep 2013 11:17:52 +0000 (13:17 +0200)
committerThomas Fillon <thomas@parisson.com>
Mon, 30 Sep 2013 11:36:00 +0000 (13:36 +0200)
* Yaafe analyzer will raise an error when yaafe-engine does not return any features.
* test_yaafe now check the number of result in the result container.

tests/test_yaafe.py
timeside/analyzer/yaafe.py

index daaa0a3e87c884562fb6eec4d181c7a65bd3d1b5..71dc50bb66470c9b787ae599c5329de422521546 100755 (executable)
@@ -26,6 +26,9 @@ class TestYaafe(TestCase):
         # from FeaturePlan
         self.analyzer = Yaafe(fp)
 
+        # Expected Results
+        self.result_length = 3
+
     def testOnGuitarWithFeaturePlanFromFile(self):
         "runs on guitar and load Yaafe feature plan from file"
         self.source = os.path.join (os.path.dirname(__file__),  "samples", "guitar.wav")
@@ -39,6 +42,9 @@ class TestYaafe(TestCase):
         # from FeaturePlan
         self.analyzer = Yaafe(fp)
 
+        # Expected Results
+        self.result_length = 3
+
     def testOnGuitarWithDataFlow(self):
         "runs on guitar and load Yaafe dataflow from file"
         self.source = os.path.join (os.path.dirname(__file__),  "samples", "guitar.wav")
@@ -52,11 +58,15 @@ class TestYaafe(TestCase):
         # from DataFlow
         self.analyzer = Yaafe(df)
 
+        # Expected Results
+        self.result_length = 5
+
     def tearDown(self):
         decoder = FileDecoder(self.source)
         decoder.output_samplerate = self.sample_rate
         (decoder | self.analyzer).run()
         results = self.analyzer.results()
+        self.assertEquals(self.result_length, len(results))
         #print results
         #print results.to_yaml()
         #print results.to_json()
index b9787f6876661e925dfd90418ef04ed5d235d1a7..1ae8b7e18d8bf832c3e99e25d0f1970f5c2285a2 100644 (file)
@@ -85,6 +85,8 @@ class Yaafe(Processor):
         container = AnalyzerResultContainer()
         # Get feature extraction results from yaafe
         featNames = self.yaafe_engine.getOutputs().keys()
+        if len(featNames) == 0:
+            raise KeyError('Yaafe engine did not return any feature')
         for featName in featNames:
             # Define ID fields
             id = 'yaafe_' + featName
@@ -93,14 +95,14 @@ class Yaafe(Processor):
 
             # Get results from Yaafe engine
             result = AnalyzerResult()
-            result.metadata = AnalyzerMetadata(id = id,
-                                      name = name,
-                                      unit = unit,
-                                      samplerate = self.samplerate,
-                                      blocksize = self.blocksize,
-                                      stepsize = None)
-
-            result.data = self.yaafe_engine.readOutput(featName)  # Read Yaafe Results
+            result.metadata = AnalyzerMetadata(id=id,
+                                      name=name,
+                                      unit=unit,
+                                      samplerate=self.samplerate,
+                                      blocksize=self.blocksize,
+                                      stepsize=None)
+            # Read Yaafe Results
+            result.data = self.yaafe_engine.readOutput(featName)
             # Store results in Container
             if len(result.data):
                 container.add_result(result)