Permalink
Browse files

STY: remove plain asserts from weave module.

  • Loading branch information...
1 parent 7ac2646 commit 32432565c304e155aa34a24bd462bcb348b51420 @rgommers rgommers committed Jun 4, 2011
Showing with 22 additions and 18 deletions.
  1. +8 −7 scipy/weave/accelerate_tools.py
  2. +14 −11 scipy/weave/bytecodecompiler.py
@@ -13,14 +13,15 @@
import inspect
import scipy.weave.md5_load as md5
import scipy.weave as weave
+from numpy.testing import assert_
from bytecodecompiler import CXXCoder,Type_Descriptor,Function_Descriptor
def CStr(s):
"Hacky way to get legal C string from Python string"
if s is None:
return '""'
- assert isinstance(s, str), "only None and string allowed"
+ assert_(isinstance(s, str), msg="only None and string allowed")
r = repr('"'+s) # Better for embedded quotes
return '"'+r[2:-1]+'"'
@@ -78,7 +79,7 @@ class Basic_Number(Basic):
def literalizer(self,s):
return str(s)
def binop(self,symbol,a,b):
- assert symbol in ['+','-','*','/'],symbol
+ assert_(symbol in ['+','-','*','/'], msg=symbol)
return '%s %s %s'%(a,symbol,b),self
class Integer(Basic_Number):
@@ -133,7 +134,7 @@ def outbound(self,s):
return "%s(%s)"%(self.outbounder,s),self.owned
def getitem(self,A,v,t):
- assert self.dims == len(v),'Expect dimension %d'%self.dims
+ assert_(self.dims == len(v), msg='Expect dimension %d'%self.dims)
code = '*((%s*)(%s->data'%(self.cxxbase,A)
for i in range(self.dims):
# assert that ''t[i]'' is an integer
@@ -273,7 +274,7 @@ def lookup_type(x):
class accelerate(object):
def __init__(self, function, *args, **kw):
- assert inspect.isfunction(function)
+ assert_(inspect.isfunction(function))
self.function = function
self.module = inspect.getmodule(function)
if self.module is None:
@@ -383,12 +384,12 @@ def function_by_signature(self,signature):
def __init__(self,f,signature,name=None):
# Make sure function is a function
- assert inspect.isfunction(f)
+ assert_(inspect.isfunction(f))
# and check the input type signature
- assert reduce(lambda x,y: x and y,
+ assert_(reduce(lambda x,y: x and y,
map(lambda x: isinstance(x,Type_Descriptor),
signature),
- 1),'%s not all type objects'%signature
+ 1), msg='%s not all type objects'%signature)
self.arg_specs = []
self.customize = weave.base_info.custom_info()
@@ -10,6 +10,8 @@
import inspect
import accelerate_tools
+from numpy.testing import assert_
+
##################################################################
# CLASS __DESCRIPTOR #
##################################################################
@@ -180,7 +182,7 @@ def opcodize(s):
##################################################################
def listing(f):
"Pretty print the internals of your function"
- assert inspect.isfunction(f)
+ assert_(inspect.isfunction(f))
filename = f.func_code.co_filename
try:
lines = open(filename).readlines()
@@ -688,8 +690,9 @@ def typedef_by_value(self,v):
# MEMBER __INIT__ #
##################################################################
def __init__(self,function,signature,name=None):
- assert inspect.isfunction(function)
- assert not function.func_defaults ,"Function cannot have default args (yet)"
+ assert_(inspect.isfunction(function))
+ assert_(not function.func_defaults,
+ msg="Function cannot have default args (yet)")
if name is None: name = function.func_name
self.name = name
self.function = function
@@ -903,20 +906,20 @@ def push(self,v,t):
##################################################################
def pop(self):
v = self.stack[-1]
- assert isinstance(v, tuple)
+ assert_(isinstance(v, tuple))
del self.stack[-1]
t = self.types[-1]
- assert isinstance(t, tuple)
+ assert_(isinstance(t, tuple))
del self.types[-1]
return v,t
##################################################################
# MEMBER PUSHTUPLE #
##################################################################
def pushTuple(self,V,T):
- assert isinstance(V, tuple)
+ assert_(isinstance(V, tuple))
self.stack.append(V)
- assert isinstance(T, tuple)
+ assert_(isinstance(T, tuple))
self.types.append(T)
return
@@ -926,10 +929,10 @@ def pushTuple(self,V,T):
##################################################################
def popTuple(self):
v = self.stack[-1]
- assert isinstance(v, tuple)
+ assert_(isinstance(v, tuple))
del self.stack[-1]
t = self.types[-1]
- assert isinstance(t, tuple)
+ assert_(isinstance(t, tuple))
del self.types[-1]
return v,t
##################################################################
@@ -1054,7 +1057,7 @@ def STORE_SUBSCR(self,pc):
v0,t0 = self.pop()
rhs,rhs_type = t1.setitem(v1,v2,t2)
- assert rhs_type == t0,"Store the right thing"
+ assert_(rhs_type == t0,"Store the right thing")
self.emit('%s = %s;'%(rhs,v0))
return
@@ -1191,7 +1194,7 @@ def STORE_ATTR(self,pc,namei):
aType,aCode = t.set_attribute(attr_name)
print 'ATTR',aType
print aCode
- assert t2 is aType
+ assert_(t2 is aType)
rhs = v2
lhs = v
self.emit(aCode%locals())

0 comments on commit 3243256

Please sign in to comment.