Debian Codegraph @

rpython/tool/test/test_descriptor.py

raw symbols SCIP
1 from rpython.tool.descriptor import InstanceMethod
2
3 class X(object):
4 def f(self, *args, **kwds):
5 return args, kwds
6
7 def test_bound():
8 obj = X()
9 obj.x = 12
10 meth = InstanceMethod(X.f.im_func, obj, X)
11 assert meth(1, z=2) == ((1,), {'z': 2})
12
13 def test_unbound():
14 obj = X()
15 obj.x = 12
16 meth = InstanceMethod(X.f.im_func, None, X)
17 assert meth(obj, 1, z=2) == ((1,), {'z': 2})
18
19 def test_eq_hash():
20 obj1 = X()
21 obj1.x = 12
22 meth1 = InstanceMethod(X.f.im_func, obj1, X)
23 meth1bis = InstanceMethod(X.f.im_func, obj1, X)
24 obj2 = X()
25 obj2.x = 12
26 meth2 = InstanceMethod(X.f.im_func, obj2, X)
27 d = {meth1: 123, meth2: 456}
28 assert len(d) == 2
29 assert d[meth1bis] == 123