1.1 --- a/tests/methods_unbound.py Thu Nov 24 23:42:19 2016 +0100
1.2 +++ b/tests/methods_unbound.py Fri Nov 25 00:53:22 2016 +0100
1.3 @@ -1,15 +1,39 @@
1.4 class C:
1.5 + def __init__(self):
1.6 + self.a = 1
1.7 def m(self, x):
1.8 return x
1.9
1.10 def f(obj, i):
1.11 if i:
1.12 - return obj.m(i)
1.13 + return obj.m(i) # should cause access to an unbound method
1.14 + else:
1.15 + return obj.m
1.16 +
1.17 +def g(obj, i):
1.18 + obj.a # only provided by instances of C
1.19 + if i:
1.20 + return obj.m(i) # should use the method directly since obj is an instance
1.21 else:
1.22 return obj.m
1.23
1.24 c = C()
1.25 -#print f(C, 1) # NOTE: Need to raise and handle error.
1.26 +
1.27 +try:
1.28 + print f(C, 1) # fails
1.29 +except UnboundMethodInvocation:
1.30 + print "f(C, 1): Unbound method is not callable."
1.31 +
1.32 fn = f(C, 0)
1.33 -print get_using(fn, c)(2) # 2
1.34 -print get_using(f(C, 0), c)(2) # 2
1.35 +
1.36 +try:
1.37 + print fn(2) # fails
1.38 +except UnboundMethodInvocation:
1.39 + print "fn(2): Unbound method is not callable."
1.40 +
1.41 +print get_using(fn, c)(2) # 2
1.42 +print get_using(f(C, 0), c)(2) # 2
1.43 +
1.44 +#print g(C, 1) # should fail with an error caused by a guard
1.45 +print g(c, 1) # 1
1.46 +print g(c, 0)(3) # 3