Skip to content

v1.4.0

Latest
Compare
Choose a tag to compare
@nivbend nivbend released this 15 Apr 15:37
· 1 commit to master since this release

Changed

  • Moved library code under the src/ directory.
  • Copied over the original CPython's unittest.mock.mock_open tests (with some modifications) as part of the library's test suite. This brought up a few differences in the API and usage to light which were fixed as part of this release.

Fixed

  • Allow to omit the mode argument, since the builtin open will understand this as 'r'.
  • Reset position in the file-like mock in consecutive calls to a patched open (either a direct call or when used as a context manager).
  • Define FileLikeMock as an iterator, which was an API of the builtin open it was missing:
    with patch('builtins.open', new_callable=MockOpen) as mock_open:
        mock_open.return_value.read_data = 'SOME DATA'
        with open('/some/path') as f:
            assert 'SOME DATA' == next(f)