A bunch of fake interfaces for development when not using the RPi or unit testing
Project description
Fake Raspberry Pi
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.
2017 Apr 2: Beta Quality
2017 Apr 8: Initial python3 support … this is a pain
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) |
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 and do development:
git clone cd fake_rpi pip install -e .
Usage
To fake RPi.GPIO or smbus, this following code must be executed before your application:
# Replace libraries by fake ones
import sys
import fake_rpi
sys.modules['RPi'] = fake_rpi.RPi # Fake RPi (GPIO)
sys.modules['smbus'] = fake_rpi.smbus # Fake smbus (I2C)
Then you can keep your usual imports in your application:
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:
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:
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
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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
File details
Details for the file fake_rpi-0.5.1.tar.gz
.
File metadata
- Download URL: fake_rpi-0.5.1.tar.gz
- Upload date:
- Size: 6.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ddd87be4c877db41ba59c1fbda26d017d3bee883a115374af16462a7cbb90734 |
|
MD5 | b039a6e5e15110ee471f47319d68e714 |
|
BLAKE2b-256 | de4e901ce3d5b8888791f21e3a4a6acf0ba969113b75107d8ad3dbab9e6c5127 |
File details
Details for the file fake_rpi-0.5.1-py3-none-any.whl
.
File metadata
- Download URL: fake_rpi-0.5.1-py3-none-any.whl
- Upload date:
- Size: 11.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | cb9614fc14f25433d3dde488a787242321ff00e70adcd728304b1c742b23f27f |
|
MD5 | 28ab32c56535929f534306ab1bafe2c3 |
|
BLAKE2b-256 | dc30981c3f1c888212cbec2a122ffe24e180cd89d0f217d47830a73ed315b906 |
File details
Details for the file fake_rpi-0.5.1-py2-none-any.whl
.
File metadata
- Download URL: fake_rpi-0.5.1-py2-none-any.whl
- Upload date:
- Size: 11.7 kB
- Tags: Python 2
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0f4419692077a6504de50c99162c4bc1d735143dee6781e8727658af7d5f6459 |
|
MD5 | c75383d96dc0d1956ba353f7059dfd5b |
|
BLAKE2b-256 | 0eebe05cdbaa969dfb02830db1e771c1e1a2f06d3c61a104245a38a0523f0ce2 |