From 1c98faecc5d05e36121593cbe5cc7e62dbdf4a20 Mon Sep 17 00:00:00 2001 From: Xavier Robin <xavier.robin@unibas.ch> Date: Thu, 23 May 2019 15:08:33 +0200 Subject: [PATCH] fix: properly test for input array types --- modules/gfx/pymod/export_primlist.cc | 8 ++++---- modules/gfx/tests/test_gfx.py | 22 ++++++++++++++++++++++ 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/modules/gfx/pymod/export_primlist.cc b/modules/gfx/pymod/export_primlist.cc index f4c7fddd8..5dd3a5b7d 100644 --- a/modules/gfx/pymod/export_primlist.cc +++ b/modules/gfx/pymod/export_primlist.cc @@ -41,7 +41,7 @@ namespace { if(!PyArray_ISCONTIGUOUS(va)) { throw Error("expected vertex array to be contiguous"); } - if(!PyArray_TYPE(va)==NPY_FLOAT) { + if(PyArray_TYPE(va)!=NPY_FLOAT) { throw Error("expected vertex array to be of dtype=float32"); } size_t v_size=PyArray_SIZE(va); @@ -60,7 +60,7 @@ namespace { if(!PyArray_ISCONTIGUOUS(na)) { throw Error("expected normal array to be contiguous"); } - if(!PyArray_TYPE(na)==NPY_FLOAT) { + if(PyArray_TYPE(na)!=NPY_FLOAT) { throw Error("expected normal array to be of dtype=float32"); } if((size_t)PyArray_SIZE(na)!=v_size) { @@ -76,7 +76,7 @@ namespace { if(!PyArray_ISCONTIGUOUS(ca)) { throw Error("expected color array to be contiguous"); } - if(!PyArray_TYPE(ca)==NPY_FLOAT) { + if(PyArray_TYPE(ca)!=NPY_FLOAT) { throw Error("expected color array to be of dtype=float32"); } if((size_t)PyArray_SIZE(ca)!=v_count*4) { @@ -91,7 +91,7 @@ namespace { if(!PyArray_ISCONTIGUOUS(ia)) { throw Error("expected vertex array to be contiguous"); } - if(!PyArray_TYPE(ia)==NPY_UINT) { + if(PyArray_TYPE(ia)!=NPY_UINT) { throw Error("expected vertex array to be of dtype=uint32"); } size_t i_size=PyArray_SIZE(ia); diff --git a/modules/gfx/tests/test_gfx.py b/modules/gfx/tests/test_gfx.py index ffca3b507..fcd0f8510 100644 --- a/modules/gfx/tests/test_gfx.py +++ b/modules/gfx/tests/test_gfx.py @@ -129,6 +129,28 @@ class TestGfx(unittest.TestCase): None, None, numpy.zeros((4,3),dtype=numpy.uint32)) + + # Passing wrong data type should fail + with self.assertRaises(Exception): + pl.AddMesh(numpy.zeros((5, 3), dtype=numpy.uint32), + numpy.zeros((5, 3), dtype=numpy.float32), + numpy.zeros((5, 4), dtype=numpy.float32), + numpy.zeros((2, 3), dtype=numpy.uint32)) + with self.assertRaises(Exception): + pl.AddMesh(numpy.zeros((5, 3), dtype=numpy.float32), + numpy.zeros((5, 3), dtype=numpy.uint32), + numpy.zeros((5, 4), dtype=numpy.float32), + numpy.zeros((2, 3), dtype=numpy.uint32)) + with self.assertRaises(Exception): + pl.AddMesh(numpy.zeros((5, 3), dtype=numpy.float32), + numpy.zeros((5, 3), dtype=numpy.float32), + numpy.zeros((5, 4), dtype=numpy.uint32), + numpy.zeros((2, 3), dtype=numpy.uint32)) + with self.assertRaises(Exception): + pl.AddMesh(numpy.zeros((5, 3), dtype=numpy.float32), + numpy.zeros((5, 3), dtype=numpy.float32), + numpy.zeros((5, 4), dtype=numpy.float32), + numpy.zeros((2, 3), dtype=numpy.float32)) if __name__== '__main__': -- GitLab