Ticket #6857: test_robustapply.py

File test_robustapply.py, 1.8 KB (added by Maciej Fijalkowski, 16 years ago)

Test (py.test) for robustapply

Line 
1
2import py
3from robustapply import function
4
5def test_function():
6 def f():
7 pass
8 assert function(f) == (f, f.func_code, 0)
9
10def test_method():
11 class A:
12 def m(self, stuff):
13 pass
14
15 obj = A()
16 assert function(obj.m) == (obj.m, A.m.im_func.func_code, 1)
17
18def test_method_unbound():
19 class A:
20 def m(self, stuff):
21 pass
22 assert function(A.m) == (A.m, A.m.im_func.func_code, 1)
23
24def test_method_newstyle():
25 class A(object):
26 def m(self, stuff):
27 pass
28
29 obj = A()
30 assert function(obj.m) == (obj.m, A.m.im_func.func_code, 1)
31
32def test_method_unbound_newstyle():
33 class A(object):
34 def m(self, stuff):
35 pass
36 assert function(A.m) == (A.m, A.m.im_func.func_code, 1)
37
38def test_class():
39 py.test.skip("Explodes on top of pypy-c")
40 class A:
41 def __init__(self):
42 pass
43 py.test.raises(ValueError, function, A)
44
45def test_newstyle_class():
46 py.test.skip("Explode on top of pypy-c")
47 class A(object):
48 def __init__(self):
49 pass
50 py.test.raises(ValueError, function, A)
51
52def test_class_instance():
53 class A:
54 def __call__(self):
55 pass
56
57 obj = A()
58 assert function(obj) == (obj.__call__, obj.__call__.im_func.func_code, 1)
59
60def test_newclass_instance():
61 class A(object):
62 def __call__(self):
63 pass
64
65 obj = A()
66 assert function(obj) == (obj.__call__, obj.__call__.im_func.func_code, 1)
67
68def test_static_class_methods():
69 class A(object):
70 @staticmethod
71 def a():
72 pass
73
74 @classmethod
75 def b(cls):
76 pass
77
78 obj = A()
79 assert function(obj.a) == (obj.a, obj.a.func_code, 0)
80 assert function(obj.b) == (obj.b, obj.b.im_func.func_code, 1)
Back to Top