| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
def test_callBound(): |
| 6 |
boundMethod = [1,2,3].__len__ |
| 7 |
assert boundMethod() == 3 |
| 8 |
raises(TypeError, boundMethod, 333) |
| 9 |
|
| 10 |
def test_callUnbound(): |
| 11 |
unboundMethod = list.__len__ |
| 12 |
assert unboundMethod([1,2,3]) == 3 |
| 13 |
raises(TypeError, unboundMethod) |
| 14 |
raises(TypeError, unboundMethod, 333) |
| 15 |
raises(TypeError, unboundMethod, [1,2,3], 333) |
| 16 |
|
| 17 |
def test_err_format(): |
| 18 |
class C(object): |
| 19 |
def m(self): pass |
| 20 |
try: |
| 21 |
C.m(1) |
| 22 |
except TypeError as e: |
| 23 |
assert str(e) == 'unbound method m() must be called with C instance as first argument (got int instance instead)' |
| 24 |
|
| 25 |
def test_getBound(): |
| 26 |
def f(l,x): return l[x+1] |
| 27 |
bound = f.__get__('abcdef') |
| 28 |
assert bound(1) == 'c' |
| 29 |
raises(TypeError, bound) |
| 30 |
raises(TypeError, bound, 2, 3) |
| 31 |
|
| 32 |
def test_getUnbound(): |
| 33 |
def f(l,x): return l[x+1] |
| 34 |
unbound = f.__get__(None, str) |
| 35 |
assert unbound('abcdef', 2) == 'd' |
| 36 |
raises(TypeError, unbound) |
| 37 |
raises(TypeError, unbound, 4) |
| 38 |
raises(TypeError, unbound, 4, 5) |