[pypy-svn] rev 2379 - pypy/trunk/src/pypy/objspace/std/test

arigo at codespeak.net arigo at codespeak.net
Tue Dec 16 15:40:32 CET 2003


Author: arigo
Date: Tue Dec 16 15:40:31 2003
New Revision: 2379

Modified:
   pypy/trunk/src/pypy/objspace/std/test/test_typeobject.py
   pypy/trunk/src/pypy/objspace/std/test/test_userobject.py
Log:
Added tests, two of which are known to fail.

Modified: pypy/trunk/src/pypy/objspace/std/test/test_typeobject.py
==============================================================================
--- pypy/trunk/src/pypy/objspace/std/test/test_typeobject.py	(original)
+++ pypy/trunk/src/pypy/objspace/std/test/test_typeobject.py	Tue Dec 16 15:40:31 2003
@@ -1,59 +1,84 @@
 import autopath
 from pypy.tool import test
-from pypy.objspace.std.typeobject import SpecialMultimethodCode
 
-class TestSpecialMultimethodCode(test.TestCase):
+##class TestSpecialMultimethodCode(test.TestCase):
 
-    def setUp(self):
-        self.space = test.objspace('std')
+##    def setUp(self):
+##        self.space = test.objspace('std')
+
+##    def tearDown(self):
+##        pass
 
-    def tearDown(self):
-        pass
+##    def test_int_sub(self):
+##        w = self.space.wrap
+##        for i in range(2):
+##            meth = SpecialMultimethodCode(self.space.sub.multimethod, 
+##                                          self.space.w_int.__class__, i)
+##            self.assertEqual(meth.slice().is_empty(), False)
+##            # test int.__sub__ and int.__rsub__
+##            self.assertEqual_w(meth.eval_code(self.space, None,
+##                                              w({'x1': 5, 'x2': 7})),
+##                               w(-2))
+##            self.assertEqual_w(meth.eval_code(self.space, None,
+##                                              w({'x1': 5, 'x2': 7.1})),
+##                               self.space.w_NotImplemented)
+##            self.assertEqual_w(meth.eval_code(self.space, None,
+##                                              w({'x1': 5.5, 'x2': 7})),
+##                               self.space.w_NotImplemented)
+
+##    def test_empty_inplace_add(self):
+##        for i in range(2):
+##            meth = SpecialMultimethodCode(self.space.inplace_add.multimethod,
+##                                          self.space.w_int.__class__, i)
+##            self.assertEqual(meth.slice().is_empty(), True)
+
+##    def test_float_sub(self):
+##        w = self.space.wrap
+##        w(1.5)   # force floatobject imported
+##        for i in range(2):
+##            meth = SpecialMultimethodCode(self.space.sub.multimethod,
+##                                          self.space.w_float.__class__, i)
+##            self.assertEqual(meth.slice().is_empty(), False)
+##            # test float.__sub__ and float.__rsub__
+
+##            # some of these tests are pointless for Python because
+##            # float.__(r)sub__ should not accept an int as first argument
+##            self.assertEqual_w(meth.eval_code(self.space, None,
+##                                              w({'x1': 5, 'x2': 7})),
+##                               w(-2.0))
+##            self.assertEqual_w(meth.eval_code(self.space, None,
+##                                              w({'x1': 5, 'x2': 7.5})),
+##                               w(-2.5))
+##            self.assertEqual_w(meth.eval_code(self.space, None,
+##                                              w({'x1': 5.5, 'x2': 7})),
+##                               w(-1.5))
 
-    def test_int_sub(self):
-        w = self.space.wrap
-        for i in range(2):
-            meth = SpecialMultimethodCode(self.space.sub.multimethod, 
-                                          self.space.w_int.__class__, i)
-            self.assertEqual(meth.slice().is_empty(), False)
-            # test int.__sub__ and int.__rsub__
-            self.assertEqual_w(meth.eval_code(self.space, None,
-                                              w({'x1': 5, 'x2': 7})),
-                               w(-2))
-            self.assertEqual_w(meth.eval_code(self.space, None,
-                                              w({'x1': 5, 'x2': 7.1})),
-                               self.space.w_NotImplemented)
-            self.assertEqual_w(meth.eval_code(self.space, None,
-                                              w({'x1': 5.5, 'x2': 7})),
-                               self.space.w_NotImplemented)
-
-    def test_empty_inplace_add(self):
-        for i in range(2):
-            meth = SpecialMultimethodCode(self.space.inplace_add.multimethod,
-                                          self.space.w_int.__class__, i)
-            self.assertEqual(meth.slice().is_empty(), True)
-
-    def test_float_sub(self):
-        w = self.space.wrap
-        w(1.5)   # force floatobject imported
-        for i in range(2):
-            meth = SpecialMultimethodCode(self.space.sub.multimethod,
-                                          self.space.w_float.__class__, i)
-            self.assertEqual(meth.slice().is_empty(), False)
-            # test float.__sub__ and float.__rsub__
-
-            # some of these tests are pointless for Python because
-            # float.__(r)sub__ should not accept an int as first argument
-            self.assertEqual_w(meth.eval_code(self.space, None,
-                                              w({'x1': 5, 'x2': 7})),
-                               w(-2.0))
-            self.assertEqual_w(meth.eval_code(self.space, None,
-                                              w({'x1': 5, 'x2': 7.5})),
-                               w(-2.5))
-            self.assertEqual_w(meth.eval_code(self.space, None,
-                                              w({'x1': 5.5, 'x2': 7})),
-                               w(-1.5))
+class TestTypeObject(test.AppTestCase):
+    def setUp(self):
+        self.space = test.objspace('std')
 
+    def test_builtin_add(self):
+        x = 5
+        self.assertEquals(x.__add__(6), 11)
+        x = 3.5
+        self.assertEquals(x.__add__(2), 5.5)
+        self.assertEquals(x.__add__(2.0), 5.5)
+
+    def test_builtin_call(self):
+        def f(*args):
+            return args
+        self.assertEquals(f.__call__(), ())
+        self.assertEquals(f.__call__(5), (5,))
+        self.assertEquals(f.__call__("hello", "world"), ("hello", "world"))
+
+    def test_builtin_call_kwds(self):
+        def f(*args, **kwds):
+            return args, kwds
+        self.assertEquals(f.__call__(), ((), {}))
+        self.assertEquals(f.__call__("hello", "world"), (("hello", "world"), {}))
+        self.assertEquals(f.__call__(5, bla=6), ((5,), {"bla": 6}))
+        self.assertEquals(f.__call__(a=1, b=2, c=3), ((), {"a": 1, "b": 2,
+                                                           "c": 3}))
 
 if __name__ == '__main__':
     test.main()

Modified: pypy/trunk/src/pypy/objspace/std/test/test_userobject.py
==============================================================================
--- pypy/trunk/src/pypy/objspace/std/test/test_userobject.py	(original)
+++ pypy/trunk/src/pypy/objspace/std/test/test_userobject.py	Tue Dec 16 15:40:31 2003
@@ -81,5 +81,21 @@
         self.assert_(hasattr(C, 'a'))
         self.assertEquals(C.a, 1)
 
+    def test_add(self):
+        class C:
+            def __add__(self, other):
+                return self, other
+        c1 = C()
+        self.assertEquals(c1+3, (c1, 3))
+
+    def test_call(self):
+        class C:
+            def __call__(self, *args):
+                return args
+        c1 = C()
+        self.assertEquals(c1(), ())
+        self.assertEquals(c1(5), (5,))
+        self.assertEquals(c1("hello", "world"), ("hello", "world"))
+
 if __name__ == '__main__':
     test.main()


More information about the Pypy-commit mailing list