MCPcopy Create free account
hub / github.com/RT-Thread/env-windows / _patch

Class _patch

tools/python-3.11.9-amd64/Lib/unittest/mock.py:1275–1607  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1273
1274
1275class _patch(object):
1276
1277 attribute_name = None
1278 _active_patches = []
1279
1280 def __init__(
1281 self, getter, attribute, new, spec, create,
1282 spec_set, autospec, new_callable, kwargs, *, unsafe=False
1283 ):
1284 if new_callable is not None:
1285 if new is not DEFAULT:
1286 raise ValueError(
1287 "Cannot use 'new' and 'new_callable' together"
1288 )
1289 if autospec is not None:
1290 raise ValueError(
1291 "Cannot use 'autospec' and 'new_callable' together"
1292 )
1293 if not unsafe:
1294 _check_spec_arg_typos(kwargs)
1295 if _is_instance_mock(spec):
1296 raise InvalidSpecError(
1297 f'Cannot spec attr {attribute!r} as the spec '
1298 f'has already been mocked out. [spec={spec!r}]')
1299 if _is_instance_mock(spec_set):
1300 raise InvalidSpecError(
1301 f'Cannot spec attr {attribute!r} as the spec_set '
1302 f'target has already been mocked out. [spec_set={spec_set!r}]')
1303
1304 self.getter = getter
1305 self.attribute = attribute
1306 self.new = new
1307 self.new_callable = new_callable
1308 self.spec = spec
1309 self.create = create
1310 self.has_local = False
1311 self.spec_set = spec_set
1312 self.autospec = autospec
1313 self.kwargs = kwargs
1314 self.additional_patchers = []
1315
1316
1317 def copy(self):
1318 patcher = _patch(
1319 self.getter, self.attribute, self.new, self.spec,
1320 self.create, self.spec_set,
1321 self.autospec, self.new_callable, self.kwargs
1322 )
1323 patcher.attribute_name = self.attribute_name
1324 patcher.additional_patchers = [
1325 p.copy() for p in self.additional_patchers
1326 ]
1327 return patcher
1328
1329
1330 def __call__(self, func):
1331 if isinstance(func, type):
1332 return self.decorate_class(func)

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