(mock, original, instance=False)
| 183 | |
| 184 | |
| 185 | def _set_signature(mock, original, instance=False): |
| 186 | # creates a function with signature (*args, **kwargs) that delegates to a |
| 187 | # mock. It still does signature checking by calling a lambda with the same |
| 188 | # signature as the original. |
| 189 | |
| 190 | skipfirst = isinstance(original, type) |
| 191 | result = _get_signature_object(original, instance, skipfirst) |
| 192 | if result is None: |
| 193 | return mock |
| 194 | func, sig = result |
| 195 | def checksig(*args, **kwargs): |
| 196 | sig.bind(*args, **kwargs) |
| 197 | _copy_func_details(func, checksig) |
| 198 | |
| 199 | name = original.__name__ |
| 200 | if not name.isidentifier(): |
| 201 | name = 'funcopy' |
| 202 | context = {'_checksig_': checksig, 'mock': mock} |
| 203 | src = """def %s(*args, **kwargs): |
| 204 | _checksig_(*args, **kwargs) |
| 205 | return mock(*args, **kwargs)""" % name |
| 206 | exec (src, context) |
| 207 | funcopy = context[name] |
| 208 | _setup_func(funcopy, mock, sig) |
| 209 | return funcopy |
| 210 | |
| 211 | def _set_async_signature(mock, original, instance=False, is_async_mock=False): |
| 212 | # creates an async function with signature (*args, **kwargs) that delegates to a |
no test coverage detected
searching dependent graphs…