Giter Site home page Giter Site logo

momsfriendlyrobotcompany / fake_rpi Goto Github PK

View Code? Open in Web Editor NEW
76.0 10.0 20.0 106 KB

fake interface for raspberry pi development and unit testing

Home Page: https://pypi.org/project/fake-rpi/

License: MIT License

Python 100.00%
raspberry-pi smbus rpi-gpio i2c spi testing-framework serial-ports

fake_rpi's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

fake_rpi's Issues

Import errors on Python 3.6 and 3.7

importlib_metadata needs to be installed when using Python 3.6 and 3.7

It would be helpful to list that as a dependency or insert $ pip install importlib-metadata as a part of the installation.

GPIO.setmode(io.BCM) Error name 'io' not defined

Hi
Thanks for providing this helpful module.
Unfortunatly ...

The line GPIO.setmode(io.BCM)
Causes the pyton error ;- name 'io' not defined

( background ...tested using either python 2.7 or python 3.7, in Microsoft Visual Studio Community 2019, Version 16.7.4
using fake_rpi version 0.6.2 )

Error when calling RPi.GPIO.cleanup without arguments

I got an IndexError when calling RPi.GPIO.cleanup without arguments.

int.setmode()
int.setup(1,)
int.setup(0,)
int.output(True,)
int.output(False,)
int.input(): 1
1
Traceback (most recent call last):
  File "test.py", line 26, in <module>
    GPIO.cleanup()
  File "/usr/local/lib/python3.5/dist-packages/fake_rpi/wrappers.py", line 19, in wrapped
    c = str(args[0].__class__).split('\'')
IndexError: tuple index out of range
# 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)

from RPi import GPIO
import random, time


GPIO.setmode(GPIO.BOARD)

GPIO.setup(1, GPIO.IN)
GPIO.setup(2, GPIO.OUT)

GPIO.output(2, True)
GPIO.output(2, False)

input1 = GPIO.input(1)

print(input1)

GPIO.cleanup()

IC2 bytes have 8 bits, therefore returned values from fake generators shouldn't be greater than 255.

IC2 bytes have 8 bits, therefore returned values from fake generators shouldn't be greater than 255.

The following example shows the issue when converting potentially generated bytes to integer:

In [1]: int.from_bytes([1, 256], byteorder='big')                                                                                                                                                                                                                                         
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-1-724da94e3d44> in <module>
----> 1 int.from_bytes([1, 256], byteorder='big')

ValueError: bytes must be in range(0, 256)

Does this support gpiozero?

Great project, guys.

Should this also be working with gpiozero or only RPi.GPIO?
I'm trying to set up travis-ci and am having the test fail.

If I´m using gpiozero the error I get is:
gpiozero.exc.PinUnknownPi: unable to locate Pi revision in /proc/device-tree or /proc/cpuinfo
and with RPi.GPIO,
travis doesn't seem to be able to find and install the library in the first place.

Running it locally on a RaspberryPi 2 Model B everything seems to be working well with both gpiozero and RPi.GPIO. (without fake_rpi)

I was hoping that you might have some pointers, since it seems like this was one of the intended uses of the project.

Transparent faking

Hi,

I could make it work with fake RPi.GPIO and smbus in my application.

But I can't change all the imports (from from RPi.GPIO import GPIO to from fake_rpi import GPIO) in my project and all dependencies.

So I found a solution inspired by this stackoverflow answer something that replace the modules by this fake one:

import sys
import fake_rpi

sys.modules['RPi'] = fake_rpi
sys.modules['smbus'] = fake_rpi

# Then everywhere...
import RPi.GPIO as GPIO
import smbus

Then, I don't need to change my project and dependencies imports, I just have to replace modules once in my main file.

It could work if inside the folder fake_rpi, there were another modules that reflect the RPi, smbus... modules

Do you think this way of using fake_rpi is relevent ?

Wrong return type read_word_data()

Environment

  • Raspberry pi 4
  • raspian buster
  • python 3.7
  • latest fake_rpi

Description

Function returns wrong type. List of integer instead of an integer. Maybe there are more mismatches.

@printf
def read_word_data(self, i2c_addr, register):
return [randint(0, 2**8-1)]*2

Observed

value
[185, 185]
type
<class 'list'>

Expected

value
65535
type
<class 'int'>

Testcode

import sys
import fake_rpi

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

import smbus

if __name__ == "__main__":
    bus = smbus.SMBus(1)

    value = bus.read_word_data(0x01, 1 << 1)
    print("value")
    print(value)
    print("type")
    print(type(value))

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.