# Python Fake
## 🌟 Overview
This project provides a `Fake` class that can be used to replace any object in a test, in development environment or in any other situation where you need to replace an object with a fake one.
The tries to provide a mock implementation for any usage, including properties, items, length, iterator, return value, await value, etc so that it never fails in runtime due to a missing implementation.
On the other hand, sometimes other pieces of code expect a certain implementation and the default implementation of the `Fake` class is not enough. In this case, you can use the `__Fake_...` parameters in the constructor to provide a more specific implementation.
At the moment, it doesn't provide tools for monitoring how the object was used, but it is planned to be implemented in the future.
### 🔎 Sample Usage
Fakeing the `picamera2` module of Raspberry Pi so that one can run the code on a non-Raspberry Pi development environment:
```python
from fake import Fake
sys.modules['picamera2'] = Fake(
_Fake__props={
'Picamera2': Fake(
_Fake__return_value=Fake(
_Fake__props={
'capture_array': Fake(
_Fake__return_value=np.zeros((1, 1, 3), dtype=np.uint8),
),
},
),
),
},
)
```
## ⚙️ Parameters
A `Fake` object can be created with the following parameters:
- `_Fake__props`: A dictionary that contains the properties of the object and their respective values.
- `_Fake__items`: A dictionary that contains the items of the object and their respective values.
- `_Fake__list`: A list that contains the items of the object. (in case the index is a number and not listed in the `__items` dictionary). It also sets the length of the object if `_Fake__length` is not set.
- `_Fake__return_value`: The return value of the object when it is called.
- `_Fake__await_value`: The return value of the object when it is awaited.
- `_Fake__length`: The length of the object when it is queried via the `len` function.
- `_Fake__iter`: The iterator of the object when it is queried via the `iter` function.
## 📦 Installation
### Pip
```bash
pip install python-fake
```
### Poetry
```bash
poetry add python-fake
```
Raw data
{
"_id": null,
"home_page": "https://github.com/sassanh/python-fake/",
"name": "python-fake",
"maintainer": null,
"docs_url": null,
"requires_python": "<4.0,>=3.9",
"maintainer_email": null,
"keywords": "fake, mock, stub, spy, double, dummy, testing, unittest, pytest, python",
"author": "Sassan Haradji",
"author_email": "me@sassanh.com",
"download_url": "https://files.pythonhosted.org/packages/ba/2d/8da03111d88945a95bd671731224b7d49409655c133b7c274a2cd873e3b7/python_fake-0.1.3.tar.gz",
"platform": null,
"description": "# Python Fake\n\n## \ud83c\udf1f Overview\n\nThis project provides a `Fake` class that can be used to replace any object in a test, in development environment or in any other situation where you need to replace an object with a fake one.\n\nThe tries to provide a mock implementation for any usage, including properties, items, length, iterator, return value, await value, etc so that it never fails in runtime due to a missing implementation.\n\nOn the other hand, sometimes other pieces of code expect a certain implementation and the default implementation of the `Fake` class is not enough. In this case, you can use the `__Fake_...` parameters in the constructor to provide a more specific implementation.\n\nAt the moment, it doesn't provide tools for monitoring how the object was used, but it is planned to be implemented in the future.\n\n### \ud83d\udd0e Sample Usage\n\nFakeing the `picamera2` module of Raspberry Pi so that one can run the code on a non-Raspberry Pi development environment:\n\n```python\nfrom fake import Fake\n\nsys.modules['picamera2'] = Fake(\n _Fake__props={\n 'Picamera2': Fake(\n _Fake__return_value=Fake(\n _Fake__props={\n 'capture_array': Fake(\n _Fake__return_value=np.zeros((1, 1, 3), dtype=np.uint8),\n ),\n },\n ),\n ),\n },\n)\n```\n\n## \u2699\ufe0f Parameters\n\nA `Fake` object can be created with the following parameters:\n\n- `_Fake__props`: A dictionary that contains the properties of the object and their respective values.\n- `_Fake__items`: A dictionary that contains the items of the object and their respective values.\n- `_Fake__list`: A list that contains the items of the object. (in case the index is a number and not listed in the `__items` dictionary). It also sets the length of the object if `_Fake__length` is not set.\n- `_Fake__return_value`: The return value of the object when it is called.\n- `_Fake__await_value`: The return value of the object when it is awaited.\n- `_Fake__length`: The length of the object when it is queried via the `len` function.\n- `_Fake__iter`: The iterator of the object when it is queried via the `iter` function.\n\n## \ud83d\udce6 Installation\n\n### Pip\n\n```bash\npip install python-fake\n```\n\n### Poetry\n\n```bash\npoetry add python-fake\n```\n\n",
"bugtrack_url": null,
"license": "Apache-2.0",
"summary": "A general purpose mock library for Python",
"version": "0.1.3",
"project_urls": {
"Homepage": "https://github.com/sassanh/python-fake/",
"Repository": "https://github.com/sassanh/python-fake/"
},
"split_keywords": [
"fake",
" mock",
" stub",
" spy",
" double",
" dummy",
" testing",
" unittest",
" pytest",
" python"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "f09ac030d3a892b31c6287da1227670eb051f93fe7bd1d62de6c9b909a9a8e6d",
"md5": "7e53ce6080cd6c877df3b73389e15f66",
"sha256": "178b847bde6de1b0b5cc5643373bcee9ec70fe3d4558628b6bfac686e15da74c"
},
"downloads": -1,
"filename": "python_fake-0.1.3-py3-none-any.whl",
"has_sig": false,
"md5_digest": "7e53ce6080cd6c877df3b73389e15f66",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<4.0,>=3.9",
"size": 3975,
"upload_time": "2024-09-03T00:05:46",
"upload_time_iso_8601": "2024-09-03T00:05:46.634924Z",
"url": "https://files.pythonhosted.org/packages/f0/9a/c030d3a892b31c6287da1227670eb051f93fe7bd1d62de6c9b909a9a8e6d/python_fake-0.1.3-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "ba2d8da03111d88945a95bd671731224b7d49409655c133b7c274a2cd873e3b7",
"md5": "a80cdf4f09eeca0297eac1f1cc57c582",
"sha256": "cc693137abe00bdb3f16c4f945befe5b8746630ea769635843837c399b291d49"
},
"downloads": -1,
"filename": "python_fake-0.1.3.tar.gz",
"has_sig": false,
"md5_digest": "a80cdf4f09eeca0297eac1f1cc57c582",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<4.0,>=3.9",
"size": 3997,
"upload_time": "2024-09-03T00:05:47",
"upload_time_iso_8601": "2024-09-03T00:05:47.834297Z",
"url": "https://files.pythonhosted.org/packages/ba/2d/8da03111d88945a95bd671731224b7d49409655c133b7c274a2cd873e3b7/python_fake-0.1.3.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-09-03 00:05:47",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "sassanh",
"github_project": "python-fake",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "python-fake"
}