def test_set_led_out_of_range(): _mock() import keybow keybow.setup(keybow.MINI) with pytest.raises(IndexError): keybow.set_led(4, 255, 0, 0)
def test_mini(): _mock() import keybow keybow.setup(keybow.MINI) assert len(keybow.callbacks) == 3 assert len(keybow.pins) == 3 assert len(keybow.leds) == 3 assert len(keybow.buf) == 3 assert len(keybow.states) == 3
def test_show(): _mock() class SpiDev(): def __init__(self): self.captured = None def xfer2(self, data): self.captured = data import keybow spi = SpiDev() keybow.setup() keybow.spi = spi keybow.set_all(0, 255, 0) keybow.show() # Lazy capture recording # with open('/tmp/capture.txt', 'w') as f: # f.write(str(spi.captured)) # assert 1 == 2 assert spi.captured == [ 0, 0, 0, 0, 0, 0, 0, 0, # SOF 255, 0, 255, 0, # LED1 255, 0, 255, 0, # LED2 255, 0, 255, 0, # ... 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, # LED12 0] # EOF
def test_setup(): _mock() import keybow keybow._is_setup = False keybow.setup()
import requests import redis pttON_URL = "http://172.16.30.76/2/low" pttOFF_URL = "http://172.16.30.76/2/high" cwURL = "http://172.16.30.76/rotate/cw" ccwURL = "http://172.16.30.76/rotate/ccw" ptt = 0 cwselect = 0 pttbutton = 1 pttlight = 0 ccwselect = 2 keybow.setup(keybow.MINI) redis = redis.Redis(host='localhost', port=6379, db=0) @keybow.on() def handle_key(index, state): global pttbutton global cwselect global ccwselect global ptt if state: if index == pttbutton: if ptt == 1: try: time.sleep(0.5)