#NEWLINE# @ contextlib . contextmanager #NEWLINE# def mock_signal_receiver( signal , wraps = None , **kwargs ) : #NEWLINE# #INDENT# "\n    Temporarily attaches a receiver to the provided ``signal`` within the scope\n    of the context manager.\n\n    The mocked receiver is returned as the ``as`` target of the ``with``\n    statement.\n\n    To have the mocked receiver wrap a callable, pass the callable as the\n    ``wraps`` keyword argument. All other keyword arguments provided are passed\n    through to the signal's ``connect`` method.\n\n    >>> with mock_signal_receiver(post_save, sender=Model) as receiver:\n    >>>     Model.objects.create()\n    >>>     assert receiver.call_count = 1\n    " #NEWLINE# if ( wraps is None ) : #NEWLINE# #INDENT# def wraps( * args , **kwrags ) : #NEWLINE# #INDENT# return None #NEWLINE# #UNINDENT# #UNINDENT# receiver = mock . Mock ( wraps = wraps ) #NEWLINE# signal . connect ( receiver , ** kwargs ) #NEWLINE# ( yield receiver ) #NEWLINE# signal . disconnect ( receiver )