update & fix
This commit is contained in:
		@ -18,36 +18,6 @@ local_tz = tzlocal.get_localzone()
 | 
			
		||||
working_dir = os.path.join(os.path.dirname(__file__), "working_dir")
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def interface_wrap(obj, attr, value):
 | 
			
		||||
    if not isinstance(getattr(obj, "calls", None), dict):
 | 
			
		||||
        obj.calls = {}
 | 
			
		||||
    obj.calls[attr] = None
 | 
			
		||||
 | 
			
		||||
    def wrapper(*a, **kw):
 | 
			
		||||
        call = obj.calls.get(attr)
 | 
			
		||||
        if call is None:
 | 
			
		||||
            obj.calls[attr] = (a, kw)
 | 
			
		||||
        elif isinstance(call, tuple):
 | 
			
		||||
            obj.calls[attr] = [call, (a, kw)]
 | 
			
		||||
        else:
 | 
			
		||||
            call.append((a, kw))
 | 
			
		||||
        return value
 | 
			
		||||
 | 
			
		||||
    setattr(obj, attr, wrapper)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def interface(obj, funcs):
 | 
			
		||||
    """Override provided object's functions using dict of funcs, as ``{
 | 
			
		||||
    func_name: return_value}``.
 | 
			
		||||
 | 
			
		||||
    Attribute ``obj.calls`` is a dict
 | 
			
		||||
    with all call done using those methods, as
 | 
			
		||||
    ``{func_name: (args, kwargs)}``.
 | 
			
		||||
    """
 | 
			
		||||
    for attr, value in funcs.items():
 | 
			
		||||
        interface_wrap(obj, attr, value)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class FakeSocket:
 | 
			
		||||
    FAILING_ADDRESS = -1
 | 
			
		||||
    """Connect with this address fails."""
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user