Tested on:Python 2.7; Python 3
Prerequisites:Software testing: mock edge values or physical interactions
0

Test complex GPIO interactions easily with call_args_list

Lets assume the Raspberry Pi is connected to a relays board which could switch a lamp. light.turn_on() triggers pin 13 to power the relays board and pin 11 to activate the relay of a lamp. After two seconds, both pins need to be disabled to turn the lamp off again.

This complex behaviour could be tested quite easily with

Mocking light.trigger_pin() prevents physically executing the switching.
Then, the function for turning on the light is called and the test asserts that trigger_pin would have been called with the right order and values using the marvelous .call_args_list.

Links
Software testen mit Mock: http://www.knight-of-pi.org/software-testing-mock-edge-values-or-physical-interactions

Knight of Pi

Johannes Bergs aka Knight of Pi. Diploma in Bioinformatics, some Webdesign and Python coding then. Living in the beautiful city of Vienna.

Comment

Time limit is exhausted. Please reload CAPTCHA.