1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
|
from types import *
def renumerate(collection):
for index in range(len(collection) - 1, -1, -1):
yield (index, collection[index])
### object predicates
def is_bound_method(obj):
return isinstance(obj, MethodType) and obj.__self__ is not None
def is_function(obj):
return isinstance(obj, FunctionType) or isinstance(obj, BuiltinFunctionType)
def is_class(obj):
return isinstance(obj, type)
def is_class_method(obj):
if not is_bound_method(obj):
return False
return is_class(obj.__self__)
### some useful shortcuts
class EXPECTING(object):
def __init__(self, mock):
self.mock = mock
def __setattr__(self, attr, value):
if attr == 'mock':
super(EXPECTING, self).__setattr__(attr, value)
else:
self.mock.__forge__.expect_setattr(attr, value)
|