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

Method configure_mock

Lib/unittest/mock.py:669–688  ·  view source on GitHub ↗

Set attributes on the mock through keyword arguments. Attributes plus return values and side effects can be set on child mocks using standard dot notation and unpacking a dictionary in the method call: >>> attrs = {'method.return_value': 3, 'other.side_effect': KeyE

(self, /, **kwargs)

Source from the content-addressed store, hash-verified

667
668
669 def configure_mock(self, /, **kwargs):
670 """Set attributes on the mock through keyword arguments.
671
672 Attributes plus return values and side effects can be set on child
673 mocks using standard dot notation and unpacking a dictionary in the
674 method call:
675
676 >>> attrs = {'method.return_value': 3, 'other.side_effect': KeyError}
677 >>> mock.configure_mock(**attrs)"""
678 for arg, val in sorted(kwargs.items(),
679 # we sort on the number of dots so that
680 # attributes are set before we set attributes on
681 # attributes
682 key=lambda entry: entry[0].count('.')):
683 args = arg.split('.')
684 final = args.pop()
685 obj = self
686 for entry in args:
687 obj = getattr(obj, entry)
688 setattr(obj, final, val)
689
690
691 def __getattr__(self, name):

Callers 5

__init__Method · 0.95
create_autospecFunction · 0.80
test_configure_mockMethod · 0.80

Calls 7

sortedFunction · 0.85
getattrFunction · 0.85
setattrFunction · 0.85
itemsMethod · 0.45
countMethod · 0.45
splitMethod · 0.45
popMethod · 0.45