diff options
author | Michael Foord <michael@voidspace.org.uk> | 2012-03-17 18:00:29 -0700 |
---|---|---|
committer | Michael Foord <michael@voidspace.org.uk> | 2012-03-17 18:00:29 -0700 |
commit | 980ce10d9736f3a814681ea67f39797776eff48e (patch) | |
tree | c08d056691ab60ae79ae691253c86bb23cec6ca2 /mock.py | |
parent | 98475ec3a4084e31007102fd6f5a7f28263fd00f (diff) | |
download | mock-980ce10d9736f3a814681ea67f39797776eff48e.tar.gz |
Documentation updates
Diffstat (limited to 'mock.py')
-rw-r--r-- | mock.py | 15 |
1 files changed, 13 insertions, 2 deletions
@@ -2230,9 +2230,20 @@ else: file_spec = file -def mock_open(mock=None, read_data=None): +def mock_open(mock=None, read_data=''): + """ + 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. + """ if mock is None: - mock = MagicMock(spec=file_spec) + mock = MagicMock(name='open', spec=open) handle = MagicMock(spec=file_spec) handle.write.return_value = None |