Beispiel #1
0
def test_make_serial_spi():
    """
    :py:func:`luma.core.cmdline.make_serial.spi` returns an SPI instance.
    """
    factory = cmdline.make_serial(test_spi_opts)
    with pytest.raises(error.UnsupportedPlatform):
        factory.spi()
Beispiel #2
0
def test_make_serial_ftdi_i2c(mock_controller):
    """
    :py:func:`luma.core.cmdline.make_serial.ftdi_i2c` returns an I2C instance.
    """
    class opts:
        ftdi_device = 'ftdi://dummy'
        i2c_port = 200
        i2c_address = 0x710

    factory = cmdline.make_serial(opts)
    assert 'luma.core.interface.serial.i2c' in repr(factory.ftdi_i2c())
Beispiel #3
0
def test_make_serial_ftdi_spi(mock_controller):
    """
    :py:func:`luma.core.cmdline.make_serial.ftdi_spi` returns an SPI instance.
    """
    class opts(test_spi_opts):
        ftdi_device = 'ftdi://dummy'
        gpio_data_command = 5
        gpio_reset = 6
        gpio_backlight = 7

    factory = cmdline.make_serial(opts)
    assert 'luma.core.interface.serial.spi' in repr(factory.ftdi_spi())
Beispiel #4
0
def test_make_serial_spi_alt_gpio():
    """
    :py:func:`luma.core.cmdline.make_serial.spi` returns an SPI instance
    when using an alternative GPIO implementation.
    """
    class opts(test_spi_opts):
        gpio = 'fake_gpio'

    with patch.dict('sys.modules', **{'fake_gpio': Mock(unsafe=True)}):
        factory = cmdline.make_serial(opts)
        with pytest.raises(error.DeviceNotFoundError):
            factory.spi()
Beispiel #5
0
def test_make_serial_spi():
    """
    :py:func:`luma.core.cmdline.make_serial.spi` returns an SPI instance.
    """
    try:
        factory = cmdline.make_serial(test_spi_opts)
        assert 'luma.core.interface.serial.spi' in repr(factory.spi())
    except ImportError:
        # non-rpi platform, e.g. macos
        pytest.skip(rpi_gpio_missing)
    except error.UnsupportedPlatform as e:
        # non-rpi platform, e.g. ubuntu 64-bit
        pytest.skip('{0} ({1})'.format(type(e).__name__, str(e)))
Beispiel #6
0
def test_make_serial_i2c():
    """
    :py:func:`luma.core.cmdline.make_serial.i2c` returns an I2C instance.
    """
    class opts:
        i2c_port = 200
        i2c_address = 0x710

    path_name = '/dev/i2c-{}'.format(opts.i2c_port)
    fake_open = i2c_error(path_name, errno.ENOENT)
    factory = cmdline.make_serial(opts)

    with patch('os.open', fake_open):
        with pytest.raises(error.DeviceNotFoundError):
            factory.i2c()
Beispiel #7
0
def test_make_serial_spi_alt_gpio():
    """
    :py:func:`luma.core.cmdline.make_serial.spi` returns an SPI instance
    when using an alternative GPIO implementation.
    """
    class opts(test_spi_opts):
        gpio = 'fake_gpio'

    with patch.dict('sys.modules', **{'fake_gpio': Mock(unsafe=True)}):
        try:
            factory = cmdline.make_serial(opts)
            assert 'luma.core.interface.serial.spi' in repr(factory.spi())
        except ImportError:
            pytest.skip(spidev_missing)
        except error.DeviceNotFoundError as e:
            # non-rpi platform, e.g. ubuntu 64-bit
            pytest.skip('{0} ({1})'.format(type(e).__name__, str(e)))