MCPcopy Index your code
hub / github.com/python/cpython / _patch

Class _patch

Lib/unittest/mock.py:1335–1680  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers 4

copyMethod · 0.70
_patch_objectFunction · 0.70
_patch_multipleFunction · 0.70
patchFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…