Exemple #1
0
def test_spi_init():
    spi(gpio=gpio,
        spi=spidev,
        port=5,
        device=2,
        bus_speed_hz=942312,
        bcm_DC=17,
        bcm_RST=11)
    verify_spi_init(5, 2, 942312, 17, 11)
    gpio.output.assert_called_once_with(11, gpio.HIGH)
Exemple #2
0
def test_spi_command():
    cmds = [3, 1, 4, 2]
    serial = spi(gpio=gpio, spi=spidev, port=9, device=1)
    serial.command(*cmds)
    verify_spi_init(9, 1)
    gpio.output.assert_has_calls([call(25, gpio.HIGH), call(24, gpio.LOW)])
    spidev.xfer2.assert_called_once_with(cmds)
Exemple #3
0
def test_spi_data():
    data = list(fib(100))
    serial = spi(gpio=gpio, spi=spidev, port=9, device=1)
    serial.data(data)
    verify_spi_init(9, 1)
    gpio.output.assert_has_calls([call(25, gpio.HIGH), call(24, gpio.HIGH)])
    spidev.xfer2.assert_called_once_with(data)
Exemple #4
0
def test_spi_cleanup():
    serial = spi(gpio=gpio, spi=spidev, port=9, device=1)
    serial.cleanup()
    verify_spi_init(9, 1)
    spidev.close.assert_called_once_with()
    gpio.cleanup.assert_called_once_with()
Exemple #5
0
def test_spi_init_device_not_found():
    import spidev
    with pytest.raises(oled.error.DeviceNotFoundError) as ex:
        spi(gpio=gpio, spi=spidev.SpiDev())
    assert str(ex.value) == 'SPI device not found'