| 1326 | |
| 1327 | |
| 1328 | class _patch(object): |
| 1329 | |
| 1330 | attribute_name = None |
| 1331 | _active_patches = [] |
| 1332 | |
| 1333 | def __init__( |
| 1334 | self, getter, attribute, new, spec, create, |
| 1335 | spec_set, autospec, new_callable, kwargs, *, unsafe=False |
| 1336 | ): |
| 1337 | if new_callable is not None: |
| 1338 | if new is not DEFAULT: |
| 1339 | raise ValueError( |
| 1340 | "Cannot use 'new' and 'new_callable' together" |
| 1341 | ) |
| 1342 | if autospec is not None: |
| 1343 | raise ValueError( |
| 1344 | "Cannot use 'autospec' and 'new_callable' together" |
| 1345 | ) |
| 1346 | if not unsafe: |
| 1347 | _check_spec_arg_typos(kwargs) |
| 1348 | if _is_instance_mock(spec): |
| 1349 | raise InvalidSpecError( |
| 1350 | f'Cannot spec attr {attribute!r} as the spec ' |
| 1351 | f'has already been mocked out. [spec={spec!r}]') |
| 1352 | if _is_instance_mock(spec_set): |
| 1353 | raise InvalidSpecError( |
| 1354 | f'Cannot spec attr {attribute!r} as the spec_set ' |
| 1355 | f'target has already been mocked out. [spec_set={spec_set!r}]') |
| 1356 | |
| 1357 | self.getter = getter |
| 1358 | self.attribute = attribute |
| 1359 | self.new = new |
| 1360 | self.new_callable = new_callable |
| 1361 | self.spec = spec |
| 1362 | self.create = create |
| 1363 | self.has_local = False |
| 1364 | self.spec_set = spec_set |
| 1365 | self.autospec = autospec |
| 1366 | self.kwargs = kwargs |
| 1367 | self.additional_patchers = [] |
| 1368 | self.is_started = False |
| 1369 | |
| 1370 | |
| 1371 | def copy(self): |
| 1372 | patcher = _patch( |
| 1373 | self.getter, self.attribute, self.new, self.spec, |
| 1374 | self.create, self.spec_set, |
| 1375 | self.autospec, self.new_callable, self.kwargs |
| 1376 | ) |
| 1377 | patcher.attribute_name = self.attribute_name |
| 1378 | patcher.additional_patchers = [ |
| 1379 | p.copy() for p in self.additional_patchers |
| 1380 | ] |
| 1381 | return patcher |
| 1382 | |
| 1383 | |
| 1384 | def __call__(self, func): |
| 1385 | if isinstance(func, type): |
no outgoing calls
no test coverage detected