diff options
author | Jay Bourque <jay.bourque@continuum.io> | 2012-12-17 11:42:36 -0600 |
---|---|---|
committer | Ondřej Čertík <ondrej.certik@gmail.com> | 2012-12-26 09:18:40 -0800 |
commit | 83de7cd1810f38a845d7e281943d46c5e225633b (patch) | |
tree | 74d7dee10226237b59cf0497e5f1e15f04f63808 | |
parent | 18e73ab359968875e7df6a0b45e788feee8fd716 (diff) | |
download | numpy-83de7cd1810f38a845d7e281943d46c5e225633b.tar.gz |
Refactor unit tests and add DECREF
- Refactor unit tests for invalid dtypes so that each test is on a separate line. This will make it easier to figure out which typestring is failing the unit test.
- Add Py_DECREF for temp variable
-rw-r--r-- | numpy/core/src/multiarray/conversion_utils.c | 1 | ||||
-rw-r--r-- | numpy/core/tests/test_dtype.py | 17 |
2 files changed, 11 insertions, 7 deletions
diff --git a/numpy/core/src/multiarray/conversion_utils.c b/numpy/core/src/multiarray/conversion_utils.c index e27cd4ffd..b05314a0a 100644 --- a/numpy/core/src/multiarray/conversion_utils.c +++ b/numpy/core/src/multiarray/conversion_utils.c @@ -1121,6 +1121,7 @@ PyArray_TypestrConvert(int itemsize, int gentype) if (temp != NULL) { if (temp->elsize != itemsize) { if (DEPRECATE(msg) < 0) { + Py_DECREF(temp); return -1; } diff --git a/numpy/core/tests/test_dtype.py b/numpy/core/tests/test_dtype.py index 542add3a2..ad8e5a8b3 100644 --- a/numpy/core/tests/test_dtype.py +++ b/numpy/core/tests/test_dtype.py @@ -47,15 +47,20 @@ class TestBuiltin(TestCase): self.assertTrue(hash(left) == hash(right)) def test_invalid_types(self): - # Make sure invalid type strings raise exceptions. + # Make sure invalid type strings raise a warning. # For now, display a deprecation warning for invalid # type sizes. In the future this should be changed # to an exception. - for typestr in ['O3', 'O5', 'O7', 'b3', 'h4', 'I5', - 'e3', 'f5', 'g12']: - #print typestr - assert_warns(DeprecationWarning, np.dtype, typestr) + assert_warns(DeprecationWarning, np.dtype, 'O3') + assert_warns(DeprecationWarning, np.dtype, 'O5') + assert_warns(DeprecationWarning, np.dtype, 'O7') + assert_warns(DeprecationWarning, np.dtype, 'b3') + assert_warns(DeprecationWarning, np.dtype, 'h4') + assert_warns(DeprecationWarning, np.dtype, 'I5') + assert_warns(DeprecationWarning, np.dtype, 'e3') + assert_warns(DeprecationWarning, np.dtype, 'f5') + assert_warns(DeprecationWarning, np.dtype, 'g12') if np.dtype('l').itemsize == 8: assert_warns(DeprecationWarning, np.dtype, 'l4') @@ -71,8 +76,6 @@ class TestBuiltin(TestCase): assert_warns(DeprecationWarning, np.dtype, 'q8') assert_warns(DeprecationWarning, np.dtype, 'Q8') - assert_raises(TypeError, np.dtype, 't8', 'NA[u4,0xffffffff]') - def test_bad_param(self): # Can't give a size that's too small assert_raises(ValueError, np.dtype, |