{"id":13502037,"url":"https://github.com/nivbend/mock-open","last_synced_at":"2025-04-16T07:55:54.469Z","repository":{"id":36446742,"uuid":"40751792","full_name":"nivbend/mock-open","owner":"nivbend","description":"A better mock for file I/O","archived":false,"fork":false,"pushed_at":"2020-10-10T17:50:24.000Z","size":62,"stargazers_count":7,"open_issues_count":0,"forks_count":4,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-25T11:17:05.408Z","etag":null,"topics":["filesystem","mock","mocks","python","python2","python3","testing","unit-testing"],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nivbend.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-08-15T08:17:29.000Z","updated_at":"2022-08-08T02:46:03.000Z","dependencies_parsed_at":"2022-08-08T15:00:27.500Z","dependency_job_id":null,"html_url":"https://github.com/nivbend/mock-open","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nivbend%2Fmock-open","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nivbend%2Fmock-open/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nivbend%2Fmock-open/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nivbend%2Fmock-open/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nivbend","download_url":"https://codeload.github.com/nivbend/mock-open/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249215818,"owners_count":21231482,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["filesystem","mock","mocks","python","python2","python3","testing","unit-testing"],"created_at":"2024-07-31T22:01:59.409Z","updated_at":"2025-04-16T07:55:54.449Z","avatar_url":"https://github.com/nivbend.png","language":"Python","funding_links":[],"categories":["Python"],"sub_categories":[],"readme":"mock-open\n=========\n[![PyPI version](https://badge.fury.io/py/mock-open.svg)](https://pypi.python.org/pypi/mock-open/)\n[![Build Status](https://travis-ci.org/nivbend/mock-open.svg?branch=master)](https://travis-ci.org/nivbend/mock-open)\n[![GitHub license](https://img.shields.io/github/license/nivbend/mock-open.svg)](https://github.com/nivbend/mock-open/blob/master/LICENSE)\n[![Maintenance](https://img.shields.io/badge/Maintained%3F-yes-green.svg)](https://GitHub.com/nivbend/mock-open/graphs/commit-activity)\n[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](http://makeapullrequest.com)\n\nA better mock for file I/O.\n\nInstall\n-------\n```\n$ pip install mock-open\n```\n\nclass `MockOpen`\n----------------\nThe `MockOpen` class should work as a stand-in replacement for [`mock.mock_open`][mock-open] with\nsome added features (though it tries to conform to how the builtin `open` works where the two\ndiffer):\n * Multiple file support, including a mapping-like access to file mocks by path:\n   ```python\n   from mock_open import MockOpen\n   mock_open = MockOpen()\n   mock_open[\"/path/to/file\"].read_data = \"Data from a fake file-like object\"\n   mock_open[\"/path/to/bad_file\"].side_effect = IOError()\n   ```\n\n   You can also configure behavior via the regular `mock` library API:\n   ```python\n   mock_open = MockOpen()\n   mock_open.return_value.write.side_effect = IOError()\n   ```\n\n * Persistent file contents between calls to `open`:\n   ```python\n   with patch(\"builtins.open\", MockOpen()):\n       with open(\"/path/to/file\", \"w\") as handle:\n           handle.write(\"Some text\")\n\n       with open(\"/path/to/file\", \"r\") as handle:\n           assert \"Some text\" == handle.read()\n   ```\n\n * All the regular file operations: `read`, `readline`, `readlines`, `write`, `writelines`, `seek`,\n   `tell`.\n\nAcknowledgements\n----------------\nThis library uses modified versions of tests from the [CPython source code][CPython] as part of its\ntest suite. The original tests are licensed under the [PSF license agreement][PSF License] and are\ncopyright of the Python Software Foundation.\n\n[mock-open]: http://docs.python.org/library/unittest.mock.html#mock-open\n[CPython]: https://github.com/python/cpython\n[PSF License]: https://docs.python.org/license.html#terms-and-conditions-for-accessing-or-otherwise-using-python\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnivbend%2Fmock-open","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnivbend%2Fmock-open","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnivbend%2Fmock-open/lists"}