[pypy-svn] r54851 - pypy/django/django/dispatch
fijal at codespeak.net
fijal at codespeak.net
Sat May 17 17:43:30 CEST 2008
Author: fijal
Date: Sat May 17 17:43:29 2008
New Revision: 54851
Added:
pypy/django/django/dispatch/test_robustapply.py (contents, props changed)
Log:
(pedronis, fijal) write a decent test suite for robust apply
Added: pypy/django/django/dispatch/test_robustapply.py
==============================================================================
--- (empty file)
+++ pypy/django/django/dispatch/test_robustapply.py Sat May 17 17:43:29 2008
@@ -0,0 +1,78 @@
+
+import py
+from robustapply import function
+
+def test_function():
+ def f():
+ pass
+ assert function(f) == (f, f.func_code, 0)
+
+def test_method():
+ class A:
+ def m(self, stuff):
+ pass
+
+ obj = A()
+ assert function(obj.m) == (obj.m, A.m.im_func.func_code, 1)
+
+def test_method_unbound():
+ class A:
+ def m(self, stuff):
+ pass
+ assert function(A.m) == (A.m, A.m.im_func.func_code, 1)
+
+def test_method_newstyle():
+ class A(object):
+ def m(self, stuff):
+ pass
+
+ obj = A()
+ assert function(obj.m) == (obj.m, A.m.im_func.func_code, 1)
+
+def test_method_unbound_newstyle():
+ class A(object):
+ def m(self, stuff):
+ pass
+ assert function(A.m) == (A.m, A.m.im_func.func_code, 1)
+
+def test_class():
+ class A:
+ def __init__(self):
+ pass
+ py.test.raises(ValueError, function, A)
+
+def test_newstyle_class():
+ class A(object):
+ def __init__(self):
+ pass
+ py.test.raises(ValueError, function, A)
+
+def test_class_instance():
+ class A:
+ def __call__(self):
+ pass
+
+ obj = A()
+ assert function(obj) == (obj.__call__, obj.__call__.im_func.func_code, 1)
+
+def test_newclass_instance():
+ class A(object):
+ def __call__(self):
+ pass
+
+ obj = A()
+ assert function(obj) == (obj.__call__, obj.__call__.im_func.func_code, 1)
+
+def test_static_class_methods():
+ class A(object):
+ @staticmethod
+ def a():
+ pass
+
+ @classmethod
+ def b(cls):
+ pass
+
+ obj = A()
+ assert function(obj.a) == (obj.a, obj.a.func_code, 0)
+ assert function(obj.b) == (obj.b, obj.b.im_func.func_code, 1)
More information about the Pypy-commit
mailing list