summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Foord <michael@voidspace.org.uk>2012-01-16 02:12:16 +0000
committerMichael Foord <michael@voidspace.org.uk>2012-01-16 02:12:16 +0000
commitd64f3427bf084dd670f39d7bf500dd1a6e114e81 (patch)
tree199760fdf1b7bd29bf495069922039782489029a
parent977ac42b3be69a2052ec7b5ad49516d1cc9a7b33 (diff)
downloadmock-d64f3427bf084dd670f39d7bf500dd1a6e114e81.tar.gz
Moc docs update
-rw-r--r--docs/mock.txt48
1 files changed, 34 insertions, 14 deletions
diff --git a/docs/mock.txt b/docs/mock.txt
index 51fdbbe..d69d6c3 100644
--- a/docs/mock.txt
+++ b/docs/mock.txt
@@ -210,23 +210,41 @@ the `new_callable` argument to `patch`.
.. method:: configure_mock(**kwargs)
- Set attributes on the mock through keyword arguments.
+ 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:
+ 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:
- .. doctest::
+ .. doctest::
- >>> mock = Mock()
- >>> attrs = {'method.return_value': 3, 'other.side_effect': KeyError}
- >>> mock.configure_mock(**attrs)
- >>> mock.method()
- 3
- >>> mock.other()
- Traceback (most recent call last):
- ...
- KeyError
+ >>> mock = Mock()
+ >>> attrs = {'method.return_value': 3, 'other.side_effect': KeyError}
+ >>> mock.configure_mock(**attrs)
+ >>> mock.method()
+ 3
+ >>> mock.other()
+ Traceback (most recent call last):
+ ...
+ KeyError
+
+ The same thing can be achieved in the constructor call to mocks:
+
+ .. doctest::
+
+ >>> attrs = {'method.return_value': 3, 'other.side_effect': KeyError}
+ >>> mock = Mock(some_attribute='eggs', **attrs)
+ >>> mock.some_attribute
+ 'eggs'
+ >>> mock.method()
+ 3
+ >>> mock.other()
+ Traceback (most recent call last):
+ ...
+ KeyError
+
+ `configure_mock` exists to make it easier to do configuration
+ after the mock has been created.
.. method:: __dir__()
@@ -520,6 +538,8 @@ methods <magic-methods>` for the full details.
+
+
.. index:: __call__
.. index:: calling