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

Class MagicMock

Lib/unittest/mock.py:2218–2248  ·  view source on GitHub ↗

MagicMock is a subclass of Mock with default implementations of most of the magic methods. You can use MagicMock without having to configure the magic methods yourself. If you use the `spec` or `spec_set` arguments then *only* magic methods that exist in the spec will be create

Source from the content-addressed store, hash-verified

2216
2217
2218class MagicMock(MagicMixin, Mock):
2219 """
2220 MagicMock is a subclass of Mock with default implementations
2221 of most of the magic methods. You can use MagicMock without having to
2222 configure the magic methods yourself.
2223
2224 If you use the `spec` or `spec_set` arguments then *only* magic
2225 methods that exist in the spec will be created.
2226
2227 Attributes and the return value of a `MagicMock` will also be `MagicMocks`.
2228 """
2229 def mock_add_spec(self, spec, spec_set=False):
2230 """Add a spec to a mock. `spec` can either be an object or a
2231 list of strings. Only attributes on the `spec` can be fetched as
2232 attributes from the mock.
2233
2234 If `spec_set` is True then only attributes on the spec can be set."""
2235 self._mock_add_spec(spec, spec_set)
2236 self._mock_set_magics()
2237
2238 def reset_mock(self, /, *args, return_value: bool = False, **kwargs):
2239 if (
2240 return_value
2241 and self._mock_name
2242 and _is_magic(self._mock_name)
2243 ):
2244 # Don't reset return values for magic methods,
2245 # otherwise `m.__str__` will start
2246 # to return `MagicMock` instances, instead of `str` instances.
2247 return_value = False
2248 super().reset_mock(*args, return_value=return_value, **kwargs)
2249
2250
2251class MagicProxy(Base):

Calls

no outgoing calls