diff options
author | Mathieu Lamarre <mlamarre@ea.com> | 2020-03-13 13:12:04 -0400 |
---|---|---|
committer | Mathieu Lamarre <mlamarre@ea.com> | 2020-03-13 13:12:04 -0400 |
commit | 8aad05e63d3efba35f24ace2061b68188fe79b45 (patch) | |
tree | 770f1ee8e3fd118e92253cc539a1309e16bcabc7 | |
parent | 33351f646e0b523139fbba4986eba54a3bfe55a7 (diff) | |
download | numpy-8aad05e63d3efba35f24ace2061b68188fe79b45.tar.gz |
Fix swig tests
resize typemap issue
python 3 bytes vs str issue
-rw-r--r-- | .gitignore | 14 | ||||
-rw-r--r-- | tools/swig/test/Array2.cxx | 5 | ||||
-rw-r--r-- | tools/swig/test/Array2.h | 7 | ||||
-rwxr-xr-x | tools/swig/test/testArray.py | 92 | ||||
-rwxr-xr-x | tools/swig/test/testFlat.py | 8 |
5 files changed, 73 insertions, 53 deletions
diff --git a/.gitignore b/.gitignore index 2ad02b560..c865d4845 100644 --- a/.gitignore +++ b/.gitignore @@ -178,3 +178,17 @@ numpy/random/legacy/*.c numpy/random/_mtrand/randint_helpers.pxi numpy/random/bounded_integers.pyx numpy/random/bounded_integers.pxd +tools/swig/test/Array_wrap.cxx +tools/swig/test/Farray_wrap.cxx +tools/swig/test/Farray.py +tools/swig/test/Flat_wrap.cxx +tools/swig/test/Flat.py +tools/swig/test/Fortran_wrap.cxx +tools/swig/test/Fortran.py +tools/swig/test/Matrix_wrap.cxx +tools/swig/test/Matrix.py +tools/swig/test/Tensor_wrap.cxx +tools/swig/test/Tensor.py +tools/swig/test/Vector.py +tools/swig/test/Vector_wrap.cxx +tools/swig/test/Array.py diff --git a/tools/swig/test/Array2.cxx b/tools/swig/test/Array2.cxx index e3558f786..2da61f728 100644 --- a/tools/swig/test/Array2.cxx +++ b/tools/swig/test/Array2.cxx @@ -90,6 +90,11 @@ void Array2::resize(int nrows, int ncols, long* data) } } +void Array2::resize(int nrows, int ncols) +{ + resize(nrows, ncols, nullptr); +} + // Set item accessor Array1 & Array2::operator[](int i) { diff --git a/tools/swig/test/Array2.h b/tools/swig/test/Array2.h index 7f8d4ca65..7ab68827b 100644 --- a/tools/swig/test/Array2.h +++ b/tools/swig/test/Array2.h @@ -31,9 +31,10 @@ public: int nrows() const; int ncols() const; - // Resize array - void resize(int nrows, int ncols, long* data=0); - + // Resize array + void resize(int nrows, int ncols, long* data); + void resize(int nrows, int ncols); + // Set item accessor Array1 & operator[](int i); diff --git a/tools/swig/test/testArray.py b/tools/swig/test/testArray.py index 627257622..49011bb13 100755 --- a/tools/swig/test/testArray.py +++ b/tools/swig/test/testArray.py @@ -24,24 +24,24 @@ class Array1TestCase(unittest.TestCase): def testConstructor0(self): "Test Array1 default constructor" a = Array.Array1() - self.failUnless(isinstance(a, Array.Array1)) - self.failUnless(len(a) == 0) + self.assertTrue(isinstance(a, Array.Array1)) + self.assertTrue(len(a) == 0) def testConstructor1(self): "Test Array1 length constructor" - self.failUnless(isinstance(self.array1, Array.Array1)) + self.assertTrue(isinstance(self.array1, Array.Array1)) def testConstructor2(self): "Test Array1 array constructor" na = np.arange(self.length) aa = Array.Array1(na) - self.failUnless(isinstance(aa, Array.Array1)) + self.assertTrue(isinstance(aa, Array.Array1)) def testConstructor3(self): "Test Array1 copy constructor" for i in range(self.array1.length()): self.array1[i] = i arrayCopy = Array.Array1(self.array1) - self.failUnless(arrayCopy == self.array1) + self.assertTrue(arrayCopy == self.array1) def testConstructorBad(self): "Test Array1 length constructor, negative" @@ -49,23 +49,23 @@ class Array1TestCase(unittest.TestCase): def testLength(self): "Test Array1 length method" - self.failUnless(self.array1.length() == self.length) + self.assertTrue(self.array1.length() == self.length) def testLen(self): "Test Array1 __len__ method" - self.failUnless(len(self.array1) == self.length) + self.assertTrue(len(self.array1) == self.length) def testResize0(self): "Test Array1 resize method, length" newLen = 2 * self.length self.array1.resize(newLen) - self.failUnless(len(self.array1) == newLen) + self.assertTrue(len(self.array1) == newLen) def testResize1(self): "Test Array1 resize method, array" a = np.zeros((2*self.length,), dtype='l') self.array1.resize(a) - self.failUnless(len(self.array1) == a.size) + self.assertTrue(len(self.array1) == a.size) def testResizeBad(self): "Test Array1 resize method, negative length" @@ -77,7 +77,7 @@ class Array1TestCase(unittest.TestCase): for i in range(n): self.array1[i] = i*i for i in range(n): - self.failUnless(self.array1[i] == i*i) + self.assertTrue(self.array1[i] == i*i) def testSetBad1(self): "Test Array1 __setitem__ method, negative index" @@ -98,20 +98,20 @@ class Array1TestCase(unittest.TestCase): def testAsString(self): "Test Array1 asString method" for i in range(self.array1.length()): self.array1[i] = i+1 - self.failUnless(self.array1.asString() == "[ 1, 2, 3, 4, 5 ]") + self.assertTrue(self.array1.asString() == "[ 1, 2, 3, 4, 5 ]") def testStr(self): "Test Array1 __str__ method" for i in range(self.array1.length()): self.array1[i] = i-2 - self.failUnless(str(self.array1) == "[ -2, -1, 0, 1, 2 ]") + self.assertTrue(str(self.array1) == "[ -2, -1, 0, 1, 2 ]") def testView(self): "Test Array1 view method" for i in range(self.array1.length()): self.array1[i] = i+1 a = self.array1.view() - self.failUnless(isinstance(a, np.ndarray)) - self.failUnless(len(a) == self.length) - self.failUnless((a == [1, 2, 3, 4, 5]).all()) + self.assertTrue(isinstance(a, np.ndarray)) + self.assertTrue(len(a) == self.length) + self.assertTrue((a == [1, 2, 3, 4, 5]).all()) ###################################################################### @@ -125,18 +125,18 @@ class Array2TestCase(unittest.TestCase): def testConstructor0(self): "Test Array2 default constructor" a = Array.Array2() - self.failUnless(isinstance(a, Array.Array2)) - self.failUnless(len(a) == 0) + self.assertTrue(isinstance(a, Array.Array2)) + self.assertTrue(len(a) == 0) def testConstructor1(self): "Test Array2 nrows, ncols constructor" - self.failUnless(isinstance(self.array2, Array.Array2)) + self.assertTrue(isinstance(self.array2, Array.Array2)) def testConstructor2(self): "Test Array2 array constructor" na = np.zeros((3, 4), dtype="l") aa = Array.Array2(na) - self.failUnless(isinstance(aa, Array.Array2)) + self.assertTrue(isinstance(aa, Array.Array2)) def testConstructor3(self): "Test Array2 copy constructor" @@ -144,7 +144,7 @@ class Array2TestCase(unittest.TestCase): for j in range(self.ncols): self.array2[i][j] = i * j arrayCopy = Array.Array2(self.array2) - self.failUnless(arrayCopy == self.array2) + self.assertTrue(arrayCopy == self.array2) def testConstructorBad1(self): "Test Array2 nrows, ncols constructor, negative nrows" @@ -156,28 +156,28 @@ class Array2TestCase(unittest.TestCase): def testNrows(self): "Test Array2 nrows method" - self.failUnless(self.array2.nrows() == self.nrows) + self.assertTrue(self.array2.nrows() == self.nrows) def testNcols(self): "Test Array2 ncols method" - self.failUnless(self.array2.ncols() == self.ncols) + self.assertTrue(self.array2.ncols() == self.ncols) def testLen(self): "Test Array2 __len__ method" - self.failUnless(len(self.array2) == self.nrows*self.ncols) + self.assertTrue(len(self.array2) == self.nrows*self.ncols) def testResize0(self): "Test Array2 resize method, size" newRows = 2 * self.nrows newCols = 2 * self.ncols self.array2.resize(newRows, newCols) - self.failUnless(len(self.array2) == newRows * newCols) + self.assertTrue(len(self.array2) == newRows * newCols) def testResize1(self): "Test Array2 resize method, array" a = np.zeros((2*self.nrows, 2*self.ncols), dtype='l') self.array2.resize(a) - self.failUnless(len(self.array2) == a.size) + self.assertTrue(len(self.array2) == a.size) def testResizeBad1(self): "Test Array2 resize method, negative nrows" @@ -198,7 +198,7 @@ class Array2TestCase(unittest.TestCase): for i in range(m): self.array2[i] = array1[i] for i in range(m): - self.failUnless(self.array2[i] == array1[i]) + self.assertTrue(self.array2[i] == array1[i]) def testSetGet2(self): "Test Array2 chained __setitem__, __getitem__ methods" @@ -209,7 +209,7 @@ class Array2TestCase(unittest.TestCase): self.array2[i][j] = i*j for i in range(m): for j in range(n): - self.failUnless(self.array2[i][j] == i*j) + self.assertTrue(self.array2[i][j] == i*j) def testSetBad1(self): "Test Array2 __setitem__ method, negative index" @@ -241,7 +241,7 @@ class Array2TestCase(unittest.TestCase): for i in range(self.nrows): for j in range(self.ncols): self.array2[i][j] = i+j - self.failUnless(self.array2.asString() == result) + self.assertTrue(self.array2.asString() == result) def testStr(self): "Test Array2 __str__ method" @@ -255,13 +255,13 @@ class Array2TestCase(unittest.TestCase): for i in range(self.nrows): for j in range(self.ncols): self.array2[i][j] = i-j - self.failUnless(str(self.array2) == result) + self.assertTrue(str(self.array2) == result) def testView(self): "Test Array2 view method" a = self.array2.view() - self.failUnless(isinstance(a, np.ndarray)) - self.failUnless(len(a) == self.nrows) + self.assertTrue(isinstance(a, np.ndarray)) + self.assertTrue(len(a) == self.nrows) ###################################################################### @@ -274,24 +274,24 @@ class ArrayZTestCase(unittest.TestCase): def testConstructor0(self): "Test ArrayZ default constructor" a = Array.ArrayZ() - self.failUnless(isinstance(a, Array.ArrayZ)) - self.failUnless(len(a) == 0) + self.assertTrue(isinstance(a, Array.ArrayZ)) + self.assertTrue(len(a) == 0) def testConstructor1(self): "Test ArrayZ length constructor" - self.failUnless(isinstance(self.array3, Array.ArrayZ)) + self.assertTrue(isinstance(self.array3, Array.ArrayZ)) def testConstructor2(self): "Test ArrayZ array constructor" na = np.arange(self.length, dtype=np.complex128) aa = Array.ArrayZ(na) - self.failUnless(isinstance(aa, Array.ArrayZ)) + self.assertTrue(isinstance(aa, Array.ArrayZ)) def testConstructor3(self): "Test ArrayZ copy constructor" for i in range(self.array3.length()): self.array3[i] = complex(i,-i) arrayCopy = Array.ArrayZ(self.array3) - self.failUnless(arrayCopy == self.array3) + self.assertTrue(arrayCopy == self.array3) def testConstructorBad(self): "Test ArrayZ length constructor, negative" @@ -299,23 +299,23 @@ class ArrayZTestCase(unittest.TestCase): def testLength(self): "Test ArrayZ length method" - self.failUnless(self.array3.length() == self.length) + self.assertTrue(self.array3.length() == self.length) def testLen(self): "Test ArrayZ __len__ method" - self.failUnless(len(self.array3) == self.length) + self.assertTrue(len(self.array3) == self.length) def testResize0(self): "Test ArrayZ resize method, length" newLen = 2 * self.length self.array3.resize(newLen) - self.failUnless(len(self.array3) == newLen) + self.assertTrue(len(self.array3) == newLen) def testResize1(self): "Test ArrayZ resize method, array" a = np.zeros((2*self.length,), dtype=np.complex128) self.array3.resize(a) - self.failUnless(len(self.array3) == a.size) + self.assertTrue(len(self.array3) == a.size) def testResizeBad(self): "Test ArrayZ resize method, negative length" @@ -327,7 +327,7 @@ class ArrayZTestCase(unittest.TestCase): for i in range(n): self.array3[i] = i*i for i in range(n): - self.failUnless(self.array3[i] == i*i) + self.assertTrue(self.array3[i] == i*i) def testSetBad1(self): "Test ArrayZ __setitem__ method, negative index" @@ -348,20 +348,20 @@ class ArrayZTestCase(unittest.TestCase): def testAsString(self): "Test ArrayZ asString method" for i in range(self.array3.length()): self.array3[i] = complex(i+1,-i-1) - self.failUnless(self.array3.asString() == "[ (1,-1), (2,-2), (3,-3), (4,-4), (5,-5) ]") + self.assertTrue(self.array3.asString() == "[ (1,-1), (2,-2), (3,-3), (4,-4), (5,-5) ]") def testStr(self): "Test ArrayZ __str__ method" for i in range(self.array3.length()): self.array3[i] = complex(i-2,(i-2)*2) - self.failUnless(str(self.array3) == "[ (-2,-4), (-1,-2), (0,0), (1,2), (2,4) ]") + self.assertTrue(str(self.array3) == "[ (-2,-4), (-1,-2), (0,0), (1,2), (2,4) ]") def testView(self): "Test ArrayZ view method" for i in range(self.array3.length()): self.array3[i] = complex(i+1,i+2) a = self.array3.view() - self.failUnless(isinstance(a, np.ndarray)) - self.failUnless(len(a) == self.length) - self.failUnless((a == [1+2j, 2+3j, 3+4j, 4+5j, 5+6j]).all()) + self.assertTrue(isinstance(a, np.ndarray)) + self.assertTrue(len(a) == self.length) + self.assertTrue((a == [1+2j, 2+3j, 3+4j, 4+5j, 5+6j]).all()) ###################################################################### diff --git a/tools/swig/test/testFlat.py b/tools/swig/test/testFlat.py index 26e3332d3..e3e456a56 100755 --- a/tools/swig/test/testFlat.py +++ b/tools/swig/test/testFlat.py @@ -27,7 +27,7 @@ class FlatTestCase(unittest.TestCase): "Test Process function 1D array" print(self.typeStr, "... ", end=' ', file=sys.stderr) process = Flat.__dict__[self.typeStr + "Process"] - pack_output = '' + pack_output = b'' for i in range(10): pack_output += struct.pack(self.typeCode,i) x = np.frombuffer(pack_output, dtype=self.typeCode) @@ -39,7 +39,7 @@ class FlatTestCase(unittest.TestCase): "Test Process function 3D array" print(self.typeStr, "... ", end=' ', file=sys.stderr) process = Flat.__dict__[self.typeStr + "Process"] - pack_output = '' + pack_output = b'' for i in range(24): pack_output += struct.pack(self.typeCode,i) x = np.frombuffer(pack_output, dtype=self.typeCode) @@ -52,7 +52,7 @@ class FlatTestCase(unittest.TestCase): "Test Process function 3D array, FORTRAN order" print(self.typeStr, "... ", end=' ', file=sys.stderr) process = Flat.__dict__[self.typeStr + "Process"] - pack_output = '' + pack_output = b'' for i in range(24): pack_output += struct.pack(self.typeCode,i) x = np.frombuffer(pack_output, dtype=self.typeCode) @@ -65,7 +65,7 @@ class FlatTestCase(unittest.TestCase): "Test Process function with non-contiguous array, which should raise an error" print(self.typeStr, "... ", end=' ', file=sys.stderr) process = Flat.__dict__[self.typeStr + "Process"] - pack_output = '' + pack_output = b'' for i in range(24): pack_output += struct.pack(self.typeCode,i) x = np.frombuffer(pack_output, dtype=self.typeCode) |