Skip to main content

A bunch of fake interfaces for development when not using the RPi or unit testing

Project description

https://raw.githubusercontent.com/walchko/fake_rpi/master/pics/pi-python.jpg Code Health Latest Version License https://travis-ci.org/walchko/fake_rpi.svg?branch=master https://img.shields.io/pypi/pyversions/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.

  • 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 use as is:

from fake_rpi import GPIO as io
from fake_rpi import smbus
from fake_rpi import toggle_print

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

io.setmode(io.BCM)
b = io.input(21)

sm = smbus.SMBus(1)
b = sm.read_byte_data(0x21, 0x32)  # read in a byte

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]

ToDo

  • add serial

  • double check interfaces and flush them out better

Change Log

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fake_rpi-0.1.2.tar.gz (5.2 kB view details)

Uploaded Source

Built Distributions

fake_rpi-0.1.2-py3-none-any.whl (9.8 kB view details)

Uploaded Python 3

fake_rpi-0.1.2-py2-none-any.whl (9.8 kB view details)

Uploaded Python 2

File details

Details for the file fake_rpi-0.1.2.tar.gz.

File metadata

  • Download URL: fake_rpi-0.1.2.tar.gz
  • Upload date:
  • Size: 5.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for fake_rpi-0.1.2.tar.gz
Algorithm Hash digest
SHA256 21b20dc2d2b983e67bf0255aa939af0ba7a35b5f78e1896564331e8d0e2bbb39
MD5 843daf2a95df69a888a0b1e874218a3e
BLAKE2b-256 85ac54d1474a215f7a476bd710cb450bfe1e4a92505d1ff1954c48e9da7ddf7b

See more details on using hashes here.

File details

Details for the file fake_rpi-0.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for fake_rpi-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 1b27e5231f20517073e148b5e225b67f4bd00a316145c55e1038e60e8b5477c7
MD5 fe9119c65257ed20b9342de02159bfd4
BLAKE2b-256 f6307485f0cb75e51180aa8336c5ef1e18bddf423cb1f376f032af385401510d

See more details on using hashes here.

File details

Details for the file fake_rpi-0.1.2-py2-none-any.whl.

File metadata

File hashes

Hashes for fake_rpi-0.1.2-py2-none-any.whl
Algorithm Hash digest
SHA256 376a28b6f807a063f706ea35b467788a424f1d895e40a1a837ac0afd221c7470
MD5 02f67a5a59524b768f59270b9284c8ca
BLAKE2b-256 cc3058d7cb58441177e48b3ee8ada87512a29ccd935ea21cde8bd5757d591d0f

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page