[Scipy-svn] r3271 - trunk/scipy/weave/tests

scipy-svn@scip... scipy-svn@scip...
Mon Aug 27 18:14:36 CDT 2007


Author: stefan
Date: 2007-08-27 18:14:25 -0500 (Mon, 27 Aug 2007)
New Revision: 3271

Modified:
   trunk/scipy/weave/tests/test_scxx_object.py
Log:
Use assert_equal instead of assert and == so we get better debugging
output on failure.  When run from the terminal, use level 5 by default.


Modified: trunk/scipy/weave/tests/test_scxx_object.py
===================================================================
--- trunk/scipy/weave/tests/test_scxx_object.py	2007-08-27 22:55:52 UTC (rev 3270)
+++ trunk/scipy/weave/tests/test_scxx_object.py	2007-08-27 23:14:25 UTC (rev 3271)
@@ -20,24 +20,24 @@
                return_val = val;
                """
         res = inline_tools.inline(code)
-        assert sys.getrefcount(res) == 2
-        assert res == 1001
+        assert_equal(sys.getrefcount(res),2)
+        assert_equal(res,1001)
     def check_float(self,level=5):
         code = """
                py::object val = (float)1.0;
                return_val = val;
                """
         res = inline_tools.inline(code)
-        assert sys.getrefcount(res) == 2
-        assert res == 1.0
+        assert_equal(sys.getrefcount(res),2)
+        assert_equal(res,1.0)
     def check_double(self,level=5):
         code = """
                py::object val = 1.0;
                return_val = val;
                """
         res = inline_tools.inline(code)
-        assert sys.getrefcount(res) == 2
-        assert res == 1.0
+        assert_equal(sys.getrefcount(res),2)
+        assert_equal(res,1.0)
     def check_complex(self,level=5):
         code = """
                std::complex<double> num = std::complex<double>(1.0,1.0);
@@ -45,16 +45,16 @@
                return_val = val;
                """
         res = inline_tools.inline(code)
-        assert sys.getrefcount(res) == 2
-        assert res == 1.0+1.0j
+        assert_equal(sys.getrefcount(res),2)
+        assert_equal(res,1.0+1.0j)
     def check_string(self,level=5):
         code = """
                py::object val = "hello";
                return_val = val;
                """
         res = inline_tools.inline(code)
-        assert sys.getrefcount(res) == 2
-        assert res == "hello"
+        assert_equal(sys.getrefcount(res),2)
+        assert_equal(res,"hello")
 
     def check_std_string(self,level=5):
         code = """
@@ -63,8 +63,8 @@
                return_val = val;
                """
         res = inline_tools.inline(code)
-        assert sys.getrefcount(res) == 2
-        assert res == "hello"
+        assert_equal(sys.getrefcount(res),2)
+        assert_equal(res,"hello")
 
 class test_object_print(NumpyTestCase):
     #------------------------------------------------------------------------
@@ -86,7 +86,7 @@
                """
         res = inline_tools.inline(code,['file_imposter'])
         print file_imposter.getvalue()
-        assert file_imposter.getvalue() == "'how now brown cow'"
+        assert_equal(file_imposter.getvalue(),"'how now brown cow'")
 
 ##    def check_failure(self,level=5):
 ##        code = """
@@ -211,10 +211,10 @@
 
         before = sys.getrefcount(a.b)
         res = inline_tools.inline(code,args)
-        assert res == a.b
+        assert_equal(res,a.b)
         del res
         after = sys.getrefcount(a.b)
-        assert after == before
+        assert_equal(after,before)
 
     def check_char(self,level=5):
         self.generic_attr('return_val = a.attr("b");')
@@ -258,8 +258,8 @@
         del res
         res = inline_tools.inline('return_val = a.attr("bar").call();',['a'])
         second = sys.getrefcount(res)
-        assert res == "bar results"
-        assert first == second
+        assert_equal(res,"bar results")
+        assert_equal(first,second)
 
 class test_object_set_attr(NumpyTestCase):
 
@@ -268,13 +268,13 @@
         a = foo()
         a.b = 12345
         res = inline_tools.inline(code,args)
-        assert a.b == desired
+        assert_equal(a.b,desired)
 
     def generic_new(self, code, desired):
         args = ['a']
         a = foo()
         res = inline_tools.inline(code,args)
-        assert a.b == desired
+        assert_equal(a.b,desired)
 
     def check_existing_char(self,level=5):
         self.generic_existing('a.set_attr("b","hello");',"hello")
@@ -352,7 +352,7 @@
     def check_equal(self,level=5):
         a,b = 1,1
         res = inline_tools.inline('return_val = (a == b);',['a','b'])
-        assert res == (a == b)
+        assert_equal(res,(a == b))
     def check_equal_objects(self,level=5):
         class foo:
             def __init__(self,x):
@@ -361,47 +361,47 @@
                 return cmp(self.x,other.x)
         a,b = foo(1),foo(2)
         res = inline_tools.inline('return_val = (a == b);',['a','b'])
-        assert res == (a == b)
+        assert_equal(res,(a == b))
     def check_lt(self,level=5):
         a,b = 1,2
         res = inline_tools.inline('return_val = (a < b);',['a','b'])
-        assert res == (a < b)
+        assert_equal(res,(a < b))
     def check_gt(self,level=5):
         a,b = 1,2
         res = inline_tools.inline('return_val = (a > b);',['a','b'])
-        assert res == (a > b)
+        assert_equal(res,(a > b))
     def check_gte(self,level=5):
         a,b = 1,2
         res = inline_tools.inline('return_val = (a >= b);',['a','b'])
-        assert res == (a >= b)
+        assert_equal(res,(a >= b))
     def check_lte(self,level=5):
         a,b = 1,2
         res = inline_tools.inline('return_val = (a <= b);',['a','b'])
-        assert res == (a <= b)
+        assert_equal(res,(a <= b))
     def check_not_equal(self,level=5):
         a,b = 1,2
         res = inline_tools.inline('return_val = (a != b);',['a','b'])
-        assert res == (a != b)
+        assert_equal(res,(a != b))
     def check_int(self,level=5):
         a = 1
         res = inline_tools.inline('return_val = (a == 1);',['a'])
-        assert res == (a == 1)
+        assert_equal(res,(a == 1))
     def check_int2(self,level=5):
         a = 1
         res = inline_tools.inline('return_val = (1 == a);',['a'])
-        assert res == (a == 1)
+        assert_equal(res,(a == 1))
     def check_unsigned_long(self,level=5):
         a = 1
         res = inline_tools.inline('return_val = (a == (unsigned long)1);',['a'])
-        assert res == (a == 1)
+        assert_equal(res,(a == 1))
     def check_double(self,level=5):
         a = 1
         res = inline_tools.inline('return_val = (a == 1.0);',['a'])
-        assert res == (a == 1.0)
+        assert_equal(res,(a == 1.0))
     def check_char(self,level=5):
         a = "hello"
         res = inline_tools.inline('return_val = (a == "hello");',['a'])
-        assert res == (a == "hello")
+        assert_equal(res,(a == "hello"))
     def check_std_string(self,level=5):
         a = "hello"
         code = """
@@ -409,7 +409,7 @@
                return_val = (a == hello);
                """
         res = inline_tools.inline(code,['a'])
-        assert res == (a == "hello")
+        assert_equal(res,(a == "hello"))
 
 class test_object_repr(NumpyTestCase):
     def check_repr(self,level=5):
@@ -424,8 +424,8 @@
         del res
         res = inline_tools.inline('return_val = a.repr();',['a'])
         second = sys.getrefcount(res)
-        assert first == second
-        assert res == "repr return"
+        assert_equal(first,second)
+        assert_equal(res,"repr return")
 
 class test_object_str(NumpyTestCase):
     def check_str(self,level=5):
@@ -440,9 +440,9 @@
         del res
         res = inline_tools.inline('return_val = a.str();',['a'])
         second = sys.getrefcount(res)
-        assert first == second
+        assert_equal(first,second)
         print res
-        assert res == "str return"
+        assert_equal(res,"str return")
 
 class test_object_unicode(NumpyTestCase):
     # This ain't going to win awards for test of the year...
@@ -458,8 +458,8 @@
         del res
         res = inline_tools.inline('return_val = a.unicode();',['a'])
         second = sys.getrefcount(res)
-        assert first == second
-        assert res == "unicode"
+        assert_equal(first,second)
+        assert_equal(res,"unicode")
 
 class test_object_is_callable(NumpyTestCase):
     def check_true(self,level=5):
@@ -481,8 +481,8 @@
         def foo():
             return (1,2,3)
         res = inline_tools.inline('return_val = foo.call();',['foo'])
-        assert res == (1,2,3)
-        assert sys.getrefcount(res) == 2
+        assert_equal(res,(1,2,3))
+        assert_equal(sys.getrefcount(res),2)
     def check_args(self,level=5):
         def foo(val1,val2):
             return (val1,val2)
@@ -493,8 +493,8 @@
                return_val = foo.call(args);
                """
         res = inline_tools.inline(code,['foo'])
-        assert res == (1,"hello")
-        assert sys.getrefcount(res) == 2
+        assert_equal(res,(1,"hello"))
+        assert_equal(sys.getrefcount(res),2)
     def check_args_kw(self,level=5):
         def foo(val1,val2,val3=1):
             return (val1,val2,val3)
@@ -507,8 +507,8 @@
                return_val = foo.call(args,kw);
                """
         res = inline_tools.inline(code,['foo'])
-        assert res == (1,"hello",3)
-        assert sys.getrefcount(res) == 2
+        assert_equal(res,(1,"hello",3))
+        assert_equal(sys.getrefcount(res),2)
     def check_noargs_with_args(self,level=5):
         # calling a function that does take args with args
         # should fail.
@@ -530,19 +530,19 @@
             except TypeError:
                 third = sys.getrefcount(foo)
         # first should == second, but the weird refcount error
-        assert second == third
+        assert_equal(second,third)
 
 class test_object_mcall(NumpyTestCase):
     def check_noargs(self,level=5):
         a = foo()
         res = inline_tools.inline('return_val = a.mcall("bar");',['a'])
-        assert res == "bar results"
+        assert_equal(res,"bar results")
         first = sys.getrefcount(res)
         del res
         res = inline_tools.inline('return_val = a.mcall("bar");',['a'])
-        assert res == "bar results"
+        assert_equal(res,"bar results")
         second = sys.getrefcount(res)
-        assert first == second
+        assert_equal(first,second)
     def check_args(self,level=5):
         a = foo()
         code = """
@@ -552,8 +552,8 @@
                return_val = a.mcall("bar2",args);
                """
         res = inline_tools.inline(code,['a'])
-        assert res == (1,"hello")
-        assert sys.getrefcount(res) == 2
+        assert_equal(res,(1,"hello"))
+        assert_equal(sys.getrefcount(res),2)
     def check_args_kw(self,level=5):
         a = foo()
         code = """
@@ -565,19 +565,19 @@
                return_val = a.mcall("bar3",args,kw);
                """
         res = inline_tools.inline(code,['a'])
-        assert res == (1,"hello",3)
-        assert sys.getrefcount(res) == 2
+        assert_equal(res,(1,"hello",3))
+        assert_equal(sys.getrefcount(res),2)
     def check_std_noargs(self,level=5):
         a = foo()
         method = "bar"
         res = inline_tools.inline('return_val = a.mcall(method);',['a','method'])
-        assert res == "bar results"
+        assert_equal(res,"bar results")
         first = sys.getrefcount(res)
         del res
         res = inline_tools.inline('return_val = a.mcall(method);',['a','method'])
-        assert res == "bar results"
+        assert_equal(res,"bar results")
         second = sys.getrefcount(res)
-        assert first == second
+        assert_equal(first,second)
     def check_std_args(self,level=5):
         a = foo()
         method = "bar2"
@@ -588,8 +588,8 @@
                return_val = a.mcall(method,args);
                """
         res = inline_tools.inline(code,['a','method'])
-        assert res == (1,"hello")
-        assert sys.getrefcount(res) == 2
+        assert_equal(res,(1,"hello"))
+        assert_equal(sys.getrefcount(res),2)
     def check_std_args_kw(self,level=5):
         a = foo()
         method = "bar3"
@@ -602,8 +602,8 @@
                return_val = a.mcall(method,args,kw);
                """
         res = inline_tools.inline(code,['a','method'])
-        assert res == (1,"hello",3)
-        assert sys.getrefcount(res) == 2
+        assert_equal(res,(1,"hello",3))
+        assert_equal(sys.getrefcount(res),2)
     def check_noargs_with_args(self,level=5):
         # calling a function that does take args with args
         # should fail.
@@ -624,7 +624,7 @@
             except TypeError:
                 third = sys.getrefcount(a)
         # first should == second, but the weird refcount error
-        assert second == third
+        assert_equal(second,third)
 
 class test_object_hash(NumpyTestCase):
     def check_hash(self,level=5):
@@ -634,7 +634,7 @@
         a= foo()
         res = inline_tools.inline('return_val = a.hash(); ',['a'])
         print 'hash:', res
-        assert res == 123
+        assert_equal(res,123)
 
 class test_object_is_true(NumpyTestCase):
     def check_true(self,level=5):
@@ -642,23 +642,23 @@
             pass
         a= foo()
         res = inline_tools.inline('return_val = a.is_true();',['a'])
-        assert res == 1
+        assert_equal(res,1)
     def check_false(self,level=5):
         a= None
         res = inline_tools.inline('return_val = a.is_true();',['a'])
-        assert res == 0
+        assert_equal(res,0)
 
 class test_object_is_true(NumpyTestCase):
     def check_false(self,level=5):
         class foo:
             pass
         a= foo()
-        res = inline_tools.inline('return_val = a.not();',['a'])
-        assert res == 0
+        res = inline_tools.inline('return_val = a.mcall("not");',['a'])
+        assert_equal(res,0)
     def check_true(self,level=5):
         a= None
-        res = inline_tools.inline('return_val = a.not();',['a'])
-        assert res == 1
+        res = inline_tools.inline('return_val = a.mcall("not");',['a'])
+        assert_equal(res,1)
 
 class test_object_type(NumpyTestCase):
     def check_type(self,level=5):
@@ -666,7 +666,7 @@
             pass
         a= foo()
         res = inline_tools.inline('return_val = a.type();',['a'])
-        assert res == type(a)
+        assert_equal(res,type(a))
 
 class test_object_size(NumpyTestCase):
     def check_size(self,level=5):
@@ -675,21 +675,21 @@
                 return 10
         a= foo()
         res = inline_tools.inline('return_val = a.size();',['a'])
-        assert res == len(a)
+        assert_equal(res,len(a))
     def check_len(self,level=5):
         class foo:
             def __len__(self):
                 return 10
         a= foo()
         res = inline_tools.inline('return_val = a.len();',['a'])
-        assert res == len(a)
+        assert_equal(res,len(a))
     def check_length(self,level=5):
         class foo:
             def __len__(self):
                 return 10
         a= foo()
         res = inline_tools.inline('return_val = a.length();',['a'])
-        assert res == len(a)
+        assert_equal(res,len(a))
 
 from UserList import UserList
 class test_object_set_item_op_index(NumpyTestCase):
@@ -699,32 +699,32 @@
         inline_tools.inline("a[1] = 1234;",['a'])
         before1 = sys.getrefcount(a)
         after1 = sys.getrefcount(a)
-        assert after1 == before1
+        assert_equal(after1,before1)
     def check_set_int(self,level=5):
         a = UserList([1,2,3])
         inline_tools.inline("a[1] = 1234;",['a'])
-        assert sys.getrefcount(a[1]) == 2
-        assert a[1] == 1234
+        assert_equal(sys.getrefcount(a[1]),2)
+        assert_equal(a[1],1234)
     def check_set_double(self,level=5):
         a = UserList([1,2,3])
         inline_tools.inline("a[1] = 123.0;",['a'])
-        assert sys.getrefcount(a[1]) == 2
-        assert a[1] == 123.0
+        assert_equal(sys.getrefcount(a[1]),2)
+        assert_equal(a[1],123.0)
     def check_set_char(self,level=5):
         a = UserList([1,2,3])
         inline_tools.inline('a[1] = "bubba";',['a'])
-        assert sys.getrefcount(a[1]) == 2
-        assert a[1] == 'bubba'
+        assert_equal(sys.getrefcount(a[1]),2)
+        assert_equal(a[1],'bubba')
     def check_set_string(self,level=5):
         a = UserList([1,2,3])
         inline_tools.inline('a[1] = std::string("sissy");',['a'])
-        assert sys.getrefcount(a[1]) == 2
-        assert a[1] == 'sissy'
+        assert_equal(sys.getrefcount(a[1]),2)
+        assert_equal(a[1],'sissy')
     def check_set_string(self,level=5):
         a = UserList([1,2,3])
         inline_tools.inline('a[1] = std::complex<double>(1,1);',['a'])
-        assert sys.getrefcount(a[1]) == 2
-        assert a[1] == 1+1j
+        assert_equal(sys.getrefcount(a[1]),2)
+        assert_equal(a[1],1+1j)
 
 from UserDict import UserDict
 class test_object_set_item_op_key(NumpyTestCase):
@@ -755,9 +755,12 @@
                 return_val = ref_counts;
                 """
         obj,key,val = inline_tools.inline(code,['a'])
-        assert obj[0] == obj[1] and obj[1] == obj[2]
-        assert key[0] + 1 == key[1] and key[1] == key[2]
-        assert val[0] + 1 == val[1] and val[1] == val[2]
+        assert_equal(obj[0],obj[1])
+        assert_equal(obj[1],obj[2])
+        assert_equal(key[0] + 1, key[1])
+        assert_equal(key[1], key[2])
+        assert_equal(val[0] + 1, val[1])
+        assert_equal(val[1], val[2])
 
     def check_set_double_exists(self,level=5):
         a = UserDict()
@@ -767,30 +770,30 @@
         first = sys.getrefcount(key)
         inline_tools.inline('a[key] = 123.0;',['a','key'])
         second = sys.getrefcount(key)
-        assert first == second
+        assert_equal(first,second)
         # !! I think the following should be 3
-        assert sys.getrefcount(key) ==  5
-        assert sys.getrefcount(a[key]) == 2
-        assert a[key] == 123.0
+        assert_equal(sys.getrefcount(key),5)
+        assert_equal(sys.getrefcount(a[key]),2)
+        assert_equal(a[key],123.0)
     def check_set_double_new(self,level=5):
         a = UserDict()
         key = 1.0
         inline_tools.inline('a[key] = 123.0;',['a','key'])
-        assert sys.getrefcount(key) == 4 # should be 3
-        assert sys.getrefcount(a[key]) == 2
-        assert a[key] == 123.0
+        assert_equal(sys.getrefcount(key),4) # should be 3
+        assert_equal(sys.getrefcount(a[key]),2)
+        assert_equal(a[key],123.0)
     def check_set_complex(self,level=5):
         a = UserDict()
         key = 1+1j
         inline_tools.inline("a[key] = 1234;",['a','key'])
-        assert sys.getrefcount(key) == 3
-        assert sys.getrefcount(a[key]) == 2
-        assert a[key] == 1234
+        assert_equal(sys.getrefcount(key),3)
+        assert_equal(sys.getrefcount(a[key]),2)
+        assert_equal(a[key],1234)
     def check_set_char(self,level=5):
         a = UserDict()
         inline_tools.inline('a["hello"] = 123.0;',['a'])
-        assert sys.getrefcount(a["hello"]) == 2
-        assert a["hello"] == 123.0
+        assert_equal(sys.getrefcount(a["hello"]),2)
+        assert_equal(a["hello"],123.0)
 
     def check_set_class(self,level=5):
         a = UserDict()
@@ -805,17 +808,20 @@
         inline_tools.inline('a[key] = "bubba";',['a','key'])
         second = sys.getrefcount(key)
         # I don't think we're leaking if this is true
-        assert first == second
+        assert_equal(first,second)
         # !! BUT -- I think this should be 3
-        assert sys.getrefcount(key) == 4
-        assert sys.getrefcount(a[key]) == 2
-        assert a[key] == 'bubba'
+        assert_equal(sys.getrefcount(key),4)
+        assert_equal(sys.getrefcount(a[key]),2)
+        assert_equal(a[key],'bubba')
     def check_set_from_member(self,level=5):
         a = UserDict()
         a['first'] = 1
         a['second'] = 2
         inline_tools.inline('a["first"] = a["second"];',['a'])
-        assert a['first'] == a['second']
+        assert_equal(a['first'],a['second'])
 
 if __name__ == "__main__":
+    import sys
+    if len(sys.argv) == 1:
+        sys.argv.extend(["--level=5"])
     NumpyTest().run()



More information about the Scipy-svn mailing list