changeset 43:36cc53aad853

Test output values a bit; fix input conversion from int
author Chris Cannam
date Wed, 03 Dec 2014 08:25:05 +0000
parents 9dd449a19004
children af167d5895a3
files PyPluginObject.cpp VectorConversion.cpp test_metadata.py test_plugin_metadata.py test_process.py
diffstat 5 files changed, 38 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/PyPluginObject.cpp	Wed Nov 26 18:17:40 2014 +0000
+++ b/PyPluginObject.cpp	Wed Dec 03 08:25:05 2014 +0000
@@ -401,10 +401,10 @@
     } else {
         
         if (!PyList_Check(pyBuffer)) {
-            PyErr_SetString(PyExc_TypeError, "List of NumPy Array required for process input.");
+            PyErr_SetString(PyExc_TypeError, "List of NumPy arrays or lists of numbers required for process input");
             return data;
         }
-
+        
         if (PyList_GET_SIZE(pyBuffer) != channels) {
 //            cerr << "Wrong number of channels: got " << PyList_GET_SIZE(pyBuffer) << ", expected " << channels << endl;
             PyErr_SetString(PyExc_TypeError, "Wrong number of channels");
@@ -414,6 +414,10 @@
         for (int c = 0; c < channels; ++c) {
             PyObject *cbuf = PyList_GET_ITEM(pyBuffer, c);
             data.push_back(conv.PyValue_To_FloatVector(cbuf));
+            if (conv.error) {
+                PyErr_SetString(PyExc_TypeError, conv.getError().str().c_str());
+                return vector<vector<float> >();
+            }
         }
     }
     
--- a/VectorConversion.cpp	Wed Nov 26 18:17:40 2014 +0000
+++ b/VectorConversion.cpp	Wed Dec 03 08:25:05 2014 +0000
@@ -62,17 +62,26 @@
 VectorConversion::PyValue_To_Float(PyObject* pyValue) const
 {
     // convert float
-    if (pyValue && PyFloat_Check(pyValue)) 
-        //TODO: check for limits here (same on most systems)
+    if (pyValue && PyFloat_Check(pyValue)) {
         return (float) PyFloat_AS_DOUBLE(pyValue);
-	
-    if (pyValue == NULL)
-    {
+    }
+
+    // convert long
+    if (pyValue && PyLong_Check(pyValue)) {
+        return (float) PyLong_AsDouble(pyValue);
+    }
+
+    // convert int
+    if (pyValue && PyInt_Check(pyValue)) {
+        return (float) PyInt_AsLong(pyValue);
+    }
+
+    if (pyValue == NULL) {
         setValueError("Error while converting object " + PyValue_Get_TypeName(pyValue) + " to float. ");
         return 0.0;		
     }
 		
-    setValueError("Conversion error: object" + PyValue_Get_TypeName(pyValue) +" is not float.");
+    setValueError("Conversion error: object" + PyValue_Get_TypeName(pyValue) +" is not float, int, or long.");
     return 0.0;
 }
 
--- a/test_metadata.py	Wed Nov 26 18:17:40 2014 +0000
+++ b/test_metadata.py	Wed Dec 03 08:25:05 2014 +0000
@@ -25,9 +25,4 @@
         pass
     lib = vh.getLibraryFor("nonexistent-library:nonexistent-plugin")
     assert lib == ""
-
-def test_getoutputlist():
-    outputs = vh.getOutputsOf(testPluginKey)
-    assert len(outputs) == 8
-    assert "curve-vsr" in outputs
     
--- a/test_plugin_metadata.py	Wed Nov 26 18:17:40 2014 +0000
+++ b/test_plugin_metadata.py	Wed Dec 03 08:25:05 2014 +0000
@@ -5,6 +5,11 @@
 
 rate = 44100
 
+def test_getoutputlist():
+    outputs = vh.getOutputsOf(testPluginKey)
+    assert len(outputs) == 9
+    assert "rmss" in outputs
+
 def test_inputdomain():
     plug = vh.loadPlugin(testPluginKey, rate)
     assert plug.inputDomain == vh.TimeDomain
--- a/test_process.py	Wed Nov 26 18:17:40 2014 +0000
+++ b/test_process.py	Wed Dec 03 08:25:05 2014 +0000
@@ -58,4 +58,16 @@
     except TypeError:
         pass
 
+def test_process_output_1ch():
+    plug = vh.loadPlugin(testPluginKey, rate)
+    plug.initialise(1, 2, 2)
+    try:
+        # Too many channels
+        result = plug.process([[3,4],[5,6]], vh.RealTime(0, 0))
+        assert False
+    except TypeError:
+        pass
+    result = plug.process([[3,3]], vh.RealTime(0, 0))
+    assert result[8] == [ { "label" : "", "values" : np.array([3.0]) } ]
 
+