MCPcopy Index your code
hub / github.com/RustPython/RustPython / _patch_multiple

Function _patch_multiple

Lib/unittest/mock.py:1715–1761  ·  view source on GitHub ↗

Perform multiple patches in a single call. It takes the object to be patched (either as an object or a string to fetch the object by importing) and keyword arguments for the patches:: with patch.multiple(settings, FIRST_PATCH='one', SECOND_PATCH='two'): ... Use `DEF

(target, spec=None, create=False, spec_set=None,
                    autospec=None, new_callable=None, **kwargs)

Source from the content-addressed store, hash-verified

1713
1714
1715def _patch_multiple(target, spec=None, create=False, spec_set=None,
1716 autospec=None, new_callable=None, **kwargs):
1717 """Perform multiple patches in a single call. It takes the object to be
1718 patched (either as an object or a string to fetch the object by importing)
1719 and keyword arguments for the patches::
1720
1721 with patch.multiple(settings, FIRST_PATCH='one', SECOND_PATCH='two'):
1722 ...
1723
1724 Use `DEFAULT` as the value if you want `patch.multiple` to create
1725 mocks for you. In this case the created mocks are passed into a decorated
1726 function by keyword, and a dictionary is returned when `patch.multiple` is
1727 used as a context manager.
1728
1729 `patch.multiple` can be used as a decorator, class decorator or a context
1730 manager. The arguments `spec`, `spec_set`, `create`,
1731 `autospec` and `new_callable` have the same meaning as for `patch`. These
1732 arguments will be applied to *all* patches done by `patch.multiple`.
1733
1734 When used as a class decorator `patch.multiple` honours `patch.TEST_PREFIX`
1735 for choosing which methods to wrap.
1736 """
1737 if type(target) is str:
1738 getter = partial(pkgutil.resolve_name, target)
1739 else:
1740 getter = lambda: target
1741
1742 if not kwargs:
1743 raise ValueError(
1744 'Must supply at least one keyword argument with patch.multiple'
1745 )
1746 # need to wrap in a list for python 3, where items is a view
1747 items = list(kwargs.items())
1748 attribute, new = items[0]
1749 patcher = _patch(
1750 getter, attribute, new, spec, create, spec_set,
1751 autospec, new_callable, {}
1752 )
1753 patcher.attribute_name = attribute
1754 for attribute, new in items[1:]:
1755 this_patcher = _patch(
1756 getter, attribute, new, spec, create, spec_set,
1757 autospec, new_callable, {}
1758 )
1759 this_patcher.attribute_name = attribute
1760 patcher.additional_patchers.append(this_patcher)
1761 return patcher
1762
1763
1764def patch(

Callers

nothing calls this directly

Calls 5

partialClass · 0.90
listClass · 0.85
_patchClass · 0.70
itemsMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected