Example #1
0
def test_init_device_not_found():
    port = 200
    address = 0x710
    path_name = '/dev/i2c-{}'.format(port)
    fake_open = i2c_error(path_name, errno.ENOENT)

    with patch('os.open', fake_open):
        with pytest.raises(luma.core.error.DeviceNotFoundError) as ex:
            i2c(port=port, address=address)
        assert str(ex.value) == 'I2C device not found: {}'.format(path_name)
Example #2
0
def test_init_device_permission_error():
    port = 1
    path_name = f'/dev/i2c-{port}'
    fake_open = i2c_error(path_name, errno.EACCES)

    with patch('os.open', fake_open):
        try:
            i2c(port=port)
        except luma.core.error.DevicePermissionError as ex:
            # permission error: device exists but no permission
            assert str(ex) == f'I2C device permission denied: {path_name}'
Example #3
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()
Example #4
0
def test_make_interface_pcf8574():
    """
    :py:func:`luma.core.cmdline.make_interface.pcf8574` returns an pcf8574 instance.
    """
    class opts:
        i2c_port = 200
        i2c_address = 0x710

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

    with patch('os.open', fake_open):
        with pytest.raises(error.DeviceNotFoundError):
            factory.pcf8574()