diff options
author | Michael Foord <michael@voidspace.org.uk> | 2012-03-25 18:07:33 (GMT) |
---|---|---|
committer | Michael Foord <michael@voidspace.org.uk> | 2012-03-25 18:07:33 (GMT) |
commit | 99254730b28100c26575c1bd32459fcb52f5bdb3 (patch) | |
tree | 23f2d946a136473f51eb6a2a77dc5c8a508eab83 /Lib/unittest/mock.py | |
parent | a74561a56d58187ebfdad25104486bbcd08e1de6 (diff) | |
download | cpython-99254730b28100c26575c1bd32459fcb52f5bdb3.zip cpython-99254730b28100c26575c1bd32459fcb52f5bdb3.tar.gz cpython-99254730b28100c26575c1bd32459fcb52f5bdb3.tar.bz2 |
Addition of docstrings to unittest.mock helpers
Diffstat (limited to 'Lib/unittest/mock.py')
-rw-r--r-- | Lib/unittest/mock.py | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/Lib/unittest/mock.py b/Lib/unittest/mock.py index 6ecc4c7..a0b7fb0 100644 --- a/Lib/unittest/mock.py +++ b/Lib/unittest/mock.py @@ -1205,7 +1205,7 @@ class _patch(object): "autospec and new." ) if original is DEFAULT: - raise TypeError("Can't use 'spec' with create=True") + raise TypeError("Can't use 'autospec' with create=True") spec_set = bool(spec_set) if autospec is True: autospec = original @@ -2142,6 +2142,17 @@ FunctionAttributes = set([ file_spec = None def mock_open(mock=None, read_data=None): + """ + A helper function to create a mock to replace the use of `open`. It works + for `open` called directly or used as a context manager. + + The `mock` argument is the mock object to configure. If `None` (the + default) then a `MagicMock` will be created for you, with the API limited + to methods or attributes available on standard file handles. + + `read_data` is a string for the `read` method of the file handle to return. + This is an empty string by default. + """ global file_spec if file_spec is None: import _io @@ -2162,7 +2173,14 @@ def mock_open(mock=None, read_data=None): class PropertyMock(Mock): - """A Mock variant with __get__ and __set__ methods to act as a property""" + """ + A mock intended to be used as a property, or other descriptor, on a class. + `PropertyMock` provides `__get__` and `__set__` methods so you can specify + a return value when it is fetched. + + Fetching a `PropertyMock` instance from an object calls the mock, with + no args. Setting it calls the mock with the value being set. + """ def __get__(self, obj, obj_type): return self() def __set__(self, obj, val): |