[Scipy-svn] r4494 - trunk/scipy/sandbox/mkufunc
scipy-svn at scipy.org
scipy-svn at scipy.org
Sat Jun 28 17:17:59 EDT 2008
Author: ilan
Date: 2008-06-28 16:17:58 -0500 (Sat, 28 Jun 2008)
New Revision: 4494
Modified:
trunk/scipy/sandbox/mkufunc/mkufunc.py
trunk/scipy/sandbox/mkufunc/test_mkufunc.py
Log:
Improved type checking and added tests to see if TypeError was raised
Modified: trunk/scipy/sandbox/mkufunc/mkufunc.py
===================================================================
--- trunk/scipy/sandbox/mkufunc/mkufunc.py 2008-06-28 20:37:04 UTC (rev 4493)
+++ trunk/scipy/sandbox/mkufunc/mkufunc.py 2008-06-28 21:17:58 UTC (rev 4494)
@@ -6,7 +6,7 @@
import sys
import re
import cStringIO
-from types import *
+from types import FunctionType
import numpy
import scipy.weave as weave
@@ -280,13 +280,13 @@
nin = f.func_code.co_argcount
nout = 1
for i, sig in enumerate(signatures):
- if sig in typedict.keys():
+ if isinstance(sig, tuple):
+ pass
+ elif sig in typedict.keys():
signatures[i] = (nin + nout) * (sig,)
- elif isinstance(sig, tuple):
- pass
else:
- raise TypeError
-
+ raise TypeError("no match for %r" % sig)
+
for sig in signatures:
assert isinstance(sig, tuple)
if len(sig) != nin + nout:
@@ -295,7 +295,7 @@
(sig, f.__name__))
for t in sig:
if t not in typedict.keys():
- raise TypeError
+ raise TypeError("no match for %r" % t)
self.ufunc = genufunc(f, signatures)
@@ -307,7 +307,7 @@
signatures = [float]
return Compile(f)
- elif isinstance(arg0, ListType):
+ elif isinstance(arg0, list):
signatures = arg0
return Compile
Modified: trunk/scipy/sandbox/mkufunc/test_mkufunc.py
===================================================================
--- trunk/scipy/sandbox/mkufunc/test_mkufunc.py 2008-06-28 20:37:04 UTC (rev 4493)
+++ trunk/scipy/sandbox/mkufunc/test_mkufunc.py 2008-06-28 21:17:58 UTC (rev 4494)
@@ -85,7 +85,17 @@
y = f(2.0, 3.9)
self.assert_(abs(y - 17.21) < 1E-10)
self.assert_(isinstance(y, float))
+
+ def test_exceptions(self):
+ def f(x):
+ return x
+ self.assertRaises(TypeError, mkufunc, {})
+ self.assertRaises(TypeError, mkufunc([(float,)]), f)
+ self.assertRaises(TypeError, mkufunc([3*(float,)]), f)
+ self.assertRaises(TypeError, mkufunc([{}]), f)
+ self.assertRaises(TypeError, mkufunc([(int, {})]), f)
+
class Math_Tests(unittest.TestCase):
More information about the Scipy-svn
mailing list