0

Testing CircuitPython libraries in CI
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Testing CircuitPython libraries in CI

by alexanderhagerman on Wed Jun 12, 2019 11:52 am

Hi, I recently started working on my first CircuitPython library for interacting with Roomba OI devices from CircuitPython boards.

https://gitlab.com/AlexanderHagerman/circuitroomba
https://pypi.org/project/circuitroomba/

One of the things I was curious about is how others are setting up CI around CircuitPython libraries? For this project I wrote test with the Python stdlib unittest and relied on the documentation here while writing, but because I'm developing on a non CircuitPython/blinka system that leaves room for error. It also leads to quite a bit of mocking and patching in tests.

Is there a way to run blinka in a docker container maybe by patching the board detection here so that dev and ci could happen in the blinka context which should better align when the code lands on a CircuitPython board?

Enjoying CircuitPython, thank you to the team and community.

alexanderhagerman
 
Posts: 12
Joined: Sun Feb 17, 2019 9:43 pm

Re: Testing CircuitPython libraries in CI

by tannewt2 on Wed Jun 12, 2019 3:36 pm

Sounds like you are way ahead of us! Our CIs are mostly just lint checks. The few that have tests are limited to not needing hardware.

Let us know what you end up with! We'd definitely like to have more than just manual testing.

tannewt2
 
Posts: 1256
Joined: Thu Oct 06, 2016 8:48 pm

Re: Testing CircuitPython libraries in CI

by kevinjwalters on Wed Jun 12, 2019 6:26 pm

I've done a bit of testing and you can see an old discussion on this on Good example of unit tests including i2c operations? For that I ended up mocking the i2c bus and using mock_calls to verify what I wanted to happen was happening. I had never used that Python test library before so don't expect any textbook use there! The other approach I wanted to take but never made enough progress on was mocking the i2c peripheral (a Pimoroni bear badge) in the form of a simulator that reproduced fully its behaviour.

Somewhere in there I did have a minor bug #2 which thorough unit testing could have found but I first spotted it from a logic analyser when looking at i2c comms.

I've done a bit more testing since for Adafruit_CircuitPython_MIDI library, see tests. During that development I tripped over micropython/micropython: py: bytes() won't call obj.__bytes__() #3158 which is one example of the obvious frailness of using "Python 3 on any old host" as a substitute for CircuitPython.

kevinjwalters
 
Posts: 429
Joined: Sun Oct 01, 2017 3:15 pm

Re: Testing CircuitPython libraries in CI

by alexanderhagerman on Thu Jun 13, 2019 7:42 am

Thank you for the information. Look forward to digging into what you shared. I'll report back on any progress.

alexanderhagerman
 
Posts: 12
Joined: Sun Feb 17, 2019 9:43 pm

Re: Testing CircuitPython libraries in CI

by kevinjwalters on Fri Jun 14, 2019 6:41 am

I forgot to mention there's a discussion on the aforementioned bug on step 6 at the end of Instructables: CircuitPython and Bearables Badge: Simple Example.

kevinjwalters
 
Posts: 429
Joined: Sun Oct 01, 2017 3:15 pm

Please be positive and constructive with your questions and comments.