# spec_mock
Create Mocks which completely mimic the real deal!
spec_mock act just like the rea deal!
* spec_mock won't let you use the mock in ways a real instance wouldn't allow.
* When the class changes so will your mock!
For example:
```python
from spec_mock import spec_mock
class Person:
def __init__(self, name: str, age: int):
self.name = name
self.age = age
def talk(self):
pass
person = spec_mock(Person)
_ = person.age # Valid
_ = person.name # Valid
_ = person.talk.side_effect = lambda: print("hi") # Valid
_ = person.gender # Invalid!
```
How is this different from MagicMock?
`MagicMock(spec=)` and `create_autospec` don't mock the attributes:
```python
person = MagicMock(spec=Person)
_ = person.age # AttributeError: Mock object has no attribute 'age'
```
Raw data
{
"_id": null,
"home_page": "https://github.com/AharonSambol/spec_mock",
"name": "spec-mock",
"maintainer": null,
"docs_url": null,
"requires_python": null,
"maintainer_email": null,
"keywords": "mock, spec, test",
"author": "Aharon Sambol",
"author_email": "aharon.sambol@gmail.com",
"download_url": null,
"platform": null,
"description": "# spec_mock\nCreate Mocks which completely mimic the real deal!\n\nspec_mock act just like the rea deal!\n* spec_mock won't let you use the mock in ways a real instance wouldn't allow.\n* When the class changes so will your mock!\n\nFor example:\n```python\nfrom spec_mock import spec_mock\n\nclass Person:\n def __init__(self, name: str, age: int):\n self.name = name\n self.age = age\n \n def talk(self):\n pass\n\nperson = spec_mock(Person)\n_ = person.age # Valid\n_ = person.name # Valid\n_ = person.talk.side_effect = lambda: print(\"hi\") # Valid\n_ = person.gender # Invalid!\n```\n\nHow is this different from MagicMock?\n\n`MagicMock(spec=)` and `create_autospec` don't mock the attributes: \n```python\nperson = MagicMock(spec=Person)\n_ = person.age # AttributeError: Mock object has no attribute 'age'\n```\n \n",
"bugtrack_url": null,
"license": "MIT License",
"summary": "Powerful mocks with complete specs",
"version": "1.0.1",
"project_urls": {
"Homepage": "https://github.com/AharonSambol/spec_mock"
},
"split_keywords": [
"mock",
" spec",
" test"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "c1fa237471756b5baf21b165e3a308afa7d45de9ae8cb07a1ffeec4e6e585287",
"md5": "c1e66fcf8c5cec9ddd7d9312686858cb",
"sha256": "538be6237be1a220d2614409e03b8de07d3c3907c30fe0106fcf882aca5a0d4e"
},
"downloads": -1,
"filename": "spec_mock-1.0.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "c1e66fcf8c5cec9ddd7d9312686858cb",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 4817,
"upload_time": "2024-09-29T20:55:10",
"upload_time_iso_8601": "2024-09-29T20:55:10.531761Z",
"url": "https://files.pythonhosted.org/packages/c1/fa/237471756b5baf21b165e3a308afa7d45de9ae8cb07a1ffeec4e6e585287/spec_mock-1.0.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-09-29 20:55:10",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "AharonSambol",
"github_project": "spec_mock",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "spec-mock"
}