fake-rpi


Namefake-rpi JSON
Version 0.7.1 PyPI version JSON
download
home_pagehttps://pypi.org/project/fake_rpi/
SummaryA bunch of fake interfaces for development when not using the RPi or unit testing
upload_time2020-05-26 22:10:55
maintainer
docs_urlNone
authorwalchko
requires_python>=3.6
licenseMIT
keywords raspberry pi fake fake_rpi i2c spi gpio serial
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            ![image](https://raw.githubusercontent.com/MomsFriendlyRobotCompany/fake_rpi/master/pics/pi-python.jpg)

# Fake Raspberry Pi

[![Actions Status](https://github.com/MomsFriendlyRobotCompany/fake_rpi/workflows/CheckPackage/badge.svg)](https://github.com/MomsFriendlyRobotCompany/fake_rpi/actions)
![GitHub](https://img.shields.io/github/license/MomsFriendlyRobotCompany/fake_rpi)
![PyPI - Python Version](https://img.shields.io/pypi/pyversions/fake_rpi)
![PyPI](https://img.shields.io/pypi/v/fake_rpi)
[![Downloads](https://img.shields.io/pypi/dm/fake_rpi.svg)](https://img.shields.io/pypi/dm/fake_rpi.svg)

**Why??**

I do a lot of development on my Powerbook and I got tired of constantly
creating a fake interface for dev on my laptop and testing on Travis.ci or github workflows.

-   2017 Apr 2: **Beta Quality**
-   2017 Apr 8: **Initial** python3 support

So, does this simulate everything on a Raspberry Pi? **No!** Right now
it simulates what I use and need. Over time, more will be added. You are
also welcome to submit pull requests for things I haven\'t added yet.

|          |                       |
| -------- | --------------------- |
| Adafruit | LSM303(accelerometer) |
| nxp_imu  | adafruit accelerometer|
| GPIO     | gpio pins             |
| picamera | camera                |
| RPi      | PWM                   |
| smbus    | i2c                   |
| serial   | not done yet          |

## Install

The preferred way to install this is:

```
pip install fake_rpi
```

## Development

To submit pull requests for new sensors or fixes, just do:

```
git clone https://github.com/MomsFriendlyRobotCompany/fake_rpi.git
cd fake_rpi
poetry install
```

Then do a pull request.

## Usage

To fake RPi.GPIO or smbus, this following
code must be executed before your application:

```python
# Replace libraries by fake ones
import sys
import fake_rpi

sys.modules['RPi'] = fake_rpi.RPi     # Fake RPi
sys.modules['RPi.GPIO'] = fake_rpi.RPi.GPIO # Fake GPIO
sys.modules['smbus'] = fake_rpi.smbus # Fake smbus (I2C)
```

Then you can keep your usual imports in your application:

```python
import RPi.GPIO as GPIO
import smbus

GPIO.setmode(io.BCM) # now use the fake GPIO
b = GPIO.input(21)

sm = smbus.SMBus(1) # now use the fake smbus
b = sm.read_byte_data(0x21, 0x32)  # read in a byte
```

Turning on/off fake calls logging:

```python
from fake_rpi import toggle_print

# by default it prints everything to std.error
toggle_print(False)  # turn on/off printing
```

But I need `smbus` to return a specific byte for unit testing! Ok, then
create a child of my `smbus` like below and modify *only* the methods
you need changed:

```python
from fake_rpi import smbus
from fake_rpi import printf

class MyBus(smbus.SMBus):
    @printf
    def read_byte_data(self, i2c_addr, register):
        ret = 0xff
        if i2c_addr == 0x21:
            ret = 0x55
        elif i2c_addr == 0x25:
            ret = 0x11
        return ret

sm = MyBus()
b = sm.read_byte_data(0x21, 0x32)  # read in a byte
```

### Printing On or Off

Here is the output from `example.py` in the `git` repo when the printing
is toggled on or off:

```
kevin@Logan fake_rpi $ ./example.py
<<< WARNING: using fake raspberry pi interfaces >>>

kevin@Logan fake_rpi $ ./example.py
<<< WARNING: using fake raspberry pi interfaces >>>
fake_rpi.RPi.PWM.__init__()
fake_rpi.RPi.PWM.start(5,)
fake_rpi.smbus.SMBus.__init__(1,)
fake_rpi.smbus.SMBus.write_byte_data(1, 2, 3)
fake_rpi.smbus.SMBus.read_byte_data(1, 2): 21
fake_rpi.smbus.SMBus.close()
__main__.MyBus.__init__()
__main__.MyBus.read_byte_data(1, 2): 72
__main__.MyBus.read_i2c_block_data(1, 2, 3): [90, 90, 90]
```

# Change Log

|  Date      | Ver.  | Notes                                         |
| ---------- | ----- | --------------------------------------------- |
| 2020-04-03 | 0.7.0 | additions to gpio and camera                  |
| 2020-02-03 | 0.6.3 | moved to toml and github workflows            |
| 2019-10-19 | 0.6.2 | fixes from scivision and Rotzbua              |
| 2019-03-29 | 0.6.1 | bug fix with randint range                    |
| 2017-11-30 | 0.6.0 | bug fix with printing                         |
| 2017-10-23 | 0.5.3 | bug fix with randint                          |
| 2017-09-05 | 0.5.1 | flushing out interfaces                       |
| 2017-07-07 | 0.3.0 | fixed bugs, print statement, and reduced dups |
| 2017-04-08 | 0.1.0 | initial python3 setup and support             |
| 2017-04-02 | 0.0.2 | pushed to pypi with landscape.io fixes        |
| 2017-04-01 | 0.0.1 | created                                       |

# MIT License

**Copyright (c) 2017 Kevin J. Walchko**

Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

            

Raw data

            {
    "_id": null,
    "home_page": "https://pypi.org/project/fake_rpi/",
    "name": "fake-rpi",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.6",
    "maintainer_email": "",
    "keywords": "raspberry,pi,fake,fake_rpi,i2c,spi,gpio,serial",
    "author": "walchko",
    "author_email": "walchko@users.noreply.github.com",
    "download_url": "https://files.pythonhosted.org/packages/6b/a0/4613cce35cc9683f3366c226b3525f8352f977e34afb13505ec85e704cfe/fake_rpi-0.7.1.tar.gz",
    "platform": "",
    "description": "![image](https://raw.githubusercontent.com/MomsFriendlyRobotCompany/fake_rpi/master/pics/pi-python.jpg)\n\n# Fake Raspberry Pi\n\n[![Actions Status](https://github.com/MomsFriendlyRobotCompany/fake_rpi/workflows/CheckPackage/badge.svg)](https://github.com/MomsFriendlyRobotCompany/fake_rpi/actions)\n![GitHub](https://img.shields.io/github/license/MomsFriendlyRobotCompany/fake_rpi)\n![PyPI - Python Version](https://img.shields.io/pypi/pyversions/fake_rpi)\n![PyPI](https://img.shields.io/pypi/v/fake_rpi)\n[![Downloads](https://img.shields.io/pypi/dm/fake_rpi.svg)](https://img.shields.io/pypi/dm/fake_rpi.svg)\n\n**Why??**\n\nI do a lot of development on my Powerbook and I got tired of constantly\ncreating a fake interface for dev on my laptop and testing on Travis.ci or github workflows.\n\n-   2017 Apr 2: **Beta Quality**\n-   2017 Apr 8: **Initial** python3 support\n\nSo, does this simulate everything on a Raspberry Pi? **No!** Right now\nit simulates what I use and need. Over time, more will be added. You are\nalso welcome to submit pull requests for things I haven\\'t added yet.\n\n|          |                       |\n| -------- | --------------------- |\n| Adafruit | LSM303(accelerometer) |\n| nxp_imu  | adafruit accelerometer|\n| GPIO     | gpio pins             |\n| picamera | camera                |\n| RPi      | PWM                   |\n| smbus    | i2c                   |\n| serial   | not done yet          |\n\n## Install\n\nThe preferred way to install this is:\n\n```\npip install fake_rpi\n```\n\n## Development\n\nTo submit pull requests for new sensors or fixes, just do:\n\n```\ngit clone https://github.com/MomsFriendlyRobotCompany/fake_rpi.git\ncd fake_rpi\npoetry install\n```\n\nThen do a pull request.\n\n## Usage\n\nTo fake RPi.GPIO or smbus, this following\ncode must be executed before your application:\n\n```python\n# Replace libraries by fake ones\nimport sys\nimport fake_rpi\n\nsys.modules['RPi'] = fake_rpi.RPi     # Fake RPi\nsys.modules['RPi.GPIO'] = fake_rpi.RPi.GPIO # Fake GPIO\nsys.modules['smbus'] = fake_rpi.smbus # Fake smbus (I2C)\n```\n\nThen you can keep your usual imports in your application:\n\n```python\nimport RPi.GPIO as GPIO\nimport smbus\n\nGPIO.setmode(io.BCM) # now use the fake GPIO\nb = GPIO.input(21)\n\nsm = smbus.SMBus(1) # now use the fake smbus\nb = sm.read_byte_data(0x21, 0x32)  # read in a byte\n```\n\nTurning on/off fake calls logging:\n\n```python\nfrom fake_rpi import toggle_print\n\n# by default it prints everything to std.error\ntoggle_print(False)  # turn on/off printing\n```\n\nBut I need `smbus` to return a specific byte for unit testing! Ok, then\ncreate a child of my `smbus` like below and modify *only* the methods\nyou need changed:\n\n```python\nfrom fake_rpi import smbus\nfrom fake_rpi import printf\n\nclass MyBus(smbus.SMBus):\n    @printf\n    def read_byte_data(self, i2c_addr, register):\n        ret = 0xff\n        if i2c_addr == 0x21:\n            ret = 0x55\n        elif i2c_addr == 0x25:\n            ret = 0x11\n        return ret\n\nsm = MyBus()\nb = sm.read_byte_data(0x21, 0x32)  # read in a byte\n```\n\n### Printing On or Off\n\nHere is the output from `example.py` in the `git` repo when the printing\nis toggled on or off:\n\n```\nkevin@Logan fake_rpi $ ./example.py\n<<< WARNING: using fake raspberry pi interfaces >>>\n\nkevin@Logan fake_rpi $ ./example.py\n<<< WARNING: using fake raspberry pi interfaces >>>\nfake_rpi.RPi.PWM.__init__()\nfake_rpi.RPi.PWM.start(5,)\nfake_rpi.smbus.SMBus.__init__(1,)\nfake_rpi.smbus.SMBus.write_byte_data(1, 2, 3)\nfake_rpi.smbus.SMBus.read_byte_data(1, 2): 21\nfake_rpi.smbus.SMBus.close()\n__main__.MyBus.__init__()\n__main__.MyBus.read_byte_data(1, 2): 72\n__main__.MyBus.read_i2c_block_data(1, 2, 3): [90, 90, 90]\n```\n\n# Change Log\n\n|  Date      | Ver.  | Notes                                         |\n| ---------- | ----- | --------------------------------------------- |\n| 2020-04-03 | 0.7.0 | additions to gpio and camera                  |\n| 2020-02-03 | 0.6.3 | moved to toml and github workflows            |\n| 2019-10-19 | 0.6.2 | fixes from scivision and Rotzbua              |\n| 2019-03-29 | 0.6.1 | bug fix with randint range                    |\n| 2017-11-30 | 0.6.0 | bug fix with printing                         |\n| 2017-10-23 | 0.5.3 | bug fix with randint                          |\n| 2017-09-05 | 0.5.1 | flushing out interfaces                       |\n| 2017-07-07 | 0.3.0 | fixed bugs, print statement, and reduced dups |\n| 2017-04-08 | 0.1.0 | initial python3 setup and support             |\n| 2017-04-02 | 0.0.2 | pushed to pypi with landscape.io fixes        |\n| 2017-04-01 | 0.0.1 | created                                       |\n\n# MIT License\n\n**Copyright (c) 2017 Kevin J. Walchko**\n\nPermission is hereby granted, free of charge, to any person obtaining a\ncopy of this software and associated documentation files (the\n\"Software\"), to deal in the Software without restriction, including\nwithout limitation the rights to use, copy, modify, merge, publish,\ndistribute, sublicense, and/or sell copies of the Software, and to\npermit persons to whom the Software is furnished to do so, subject to\nthe following conditions:\n\nThe above copyright notice and this permission notice shall be included\nin all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND,\nEXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\nMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.\nIN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY\nCLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,\nTORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE\nSOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A bunch of fake interfaces for development when not using the RPi or unit testing",
    "version": "0.7.1",
    "project_urls": {
        "Homepage": "https://pypi.org/project/fake_rpi/",
        "Repository": "https://github.com/MomsFriendlyRobotCompany/fake_rpi"
    },
    "split_keywords": [
        "raspberry",
        "pi",
        "fake",
        "fake_rpi",
        "i2c",
        "spi",
        "gpio",
        "serial"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "0cc78b32c5a2e94445dfdcaf16a35776d68335a7dfd315a6614956286d88276f",
                "md5": "8d3ba1b98bddfe9d4efa4a47bec37601",
                "sha256": "2ca5af521c095fcfd1d368a4e96d6b4445b3ad673470d63f0867d3411ac38ceb"
            },
            "downloads": -1,
            "filename": "fake_rpi-0.7.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "8d3ba1b98bddfe9d4efa4a47bec37601",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.6",
            "size": 9522,
            "upload_time": "2020-05-26T22:10:54",
            "upload_time_iso_8601": "2020-05-26T22:10:54.993842Z",
            "url": "https://files.pythonhosted.org/packages/0c/c7/8b32c5a2e94445dfdcaf16a35776d68335a7dfd315a6614956286d88276f/fake_rpi-0.7.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "6ba04613cce35cc9683f3366c226b3525f8352f977e34afb13505ec85e704cfe",
                "md5": "09c4876a7a7b13dd266fc6a8a0c96af1",
                "sha256": "9194842c49ad17afa5b492c52172d7e15790563e36a01fc5f525b606416e00ee"
            },
            "downloads": -1,
            "filename": "fake_rpi-0.7.1.tar.gz",
            "has_sig": false,
            "md5_digest": "09c4876a7a7b13dd266fc6a8a0c96af1",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6",
            "size": 7719,
            "upload_time": "2020-05-26T22:10:55",
            "upload_time_iso_8601": "2020-05-26T22:10:55.961294Z",
            "url": "https://files.pythonhosted.org/packages/6b/a0/4613cce35cc9683f3366c226b3525f8352f977e34afb13505ec85e704cfe/fake_rpi-0.7.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2020-05-26 22:10:55",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "MomsFriendlyRobotCompany",
    "github_project": "fake_rpi",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "fake-rpi"
}
        
Elapsed time: 0.22915s