[pypy-svn] rev 655 - in pypy/trunk/src/pypy/module: . test

lac at codespeak.net lac at codespeak.net
Thu May 29 13:37:33 CEST 2003


Author: lac
Date: Thu May 29 13:37:33 2003
New Revision: 655

Added:
   pypy/trunk/src/pypy/module/test/test_apply.py
Modified:
   pypy/trunk/src/pypy/module/builtin_app.py
Log:
Wrote trivial unit test for apply.  This assumes that if it ever works, it
always works, which is true because apply is just a synonym for 
return function(*args, **kwds).  However, if * or ** are broken, somebody
else will have to discover this.  This unit test is too trivial.


Modified: pypy/trunk/src/pypy/module/builtin_app.py
==============================================================================
--- pypy/trunk/src/pypy/module/builtin_app.py	(original)
+++ pypy/trunk/src/pypy/module/builtin_app.py	Thu May 29 13:37:33 2003
@@ -1,4 +1,5 @@
 def apply(function, args, kwds={}):
+    """call a function (or other callable object) and return its result"""
     return function(*args, **kwds)
 
 def map(function, *collections):

Added: pypy/trunk/src/pypy/module/test/test_apply.py
==============================================================================
--- (empty file)
+++ pypy/trunk/src/pypy/module/test/test_apply.py	Thu May 29 13:37:33 2003
@@ -0,0 +1,38 @@
+import testsupport
+from pypy.module.builtin_app import apply, min, max
+
+def myminmax(*arr, **dict):
+   # trivial function which has the signature *args, **kw
+   v = list(arr) + dict.values()
+   return min(v), max(v)
+  
+class TestApply(testsupport.TestCase):
+
+   def setUp(self):
+      pass
+  
+   def tearDown(self):
+      pass
+
+# This is a very trivial series of tests.  If apply is subtlely broken,
+# we will have to find out some other way.
+      
+   def test_trivial_listonly(self):
+      self.assertEqual(apply(myminmax,
+                             [-1,-2,-3,-4]),
+                             (-4, -1))
+
+   def test_trivial_dictonly(self):
+      self.assertEqual(apply(myminmax,
+                             [], {'null' : 0, 'one': 1, 'two' : 2}),
+                             (0, 2))
+   def test_trivial(self):
+      self.assertEqual(apply(myminmax,
+                             [-1,-2,-3,-4],
+                             {'null' : 0, 'one': 1, 'two' : 2}),
+                             (-4, 2))
+
+if __name__ == '__main__':
+    testsupport.main()
+
+


More information about the Pypy-commit mailing list