# Path: luma/core/interface/serial.py
# def ftdi_i2c(device='ftdi://::/1', address=0x3C):
#     """
#     Bridges an `I²C <https://en.wikipedia.org/wiki/I%C2%B2C>`_ (Inter-Integrated
#     Circuit) interface over an FTDI USB device to provide :py:func:`data` and
#     :py:func:`command` methods.
# 
#     :param device: A URI describing the location of the FTDI device. If ``None`` is
#         supplied (default), ``ftdi://::/1`` is used. See `pyftdi <https://pypi.org/project/pyftdi>`_
#         for further details of the naming scheme used.
#     :type device: string
#     :param address: I²C address, default: ``0x3C``.
#     :type address: int
#     :raises luma.core.error.DeviceAddressError: I2C device address is invalid.
# 
#     .. versionadded:: 1.9.0
#     """
#     from pyftdi.i2c import I2cController
# 
#     try:
#         addr = int(str(address), 0)
#     except ValueError:
#         raise luma.core.error.DeviceAddressError(
#             f'I2C device address invalid: {address}')
# 
#     controller = I2cController()
#     controller.configure(device)
# 
#     port = controller.get_port(addr)
# 
#     serial = i2c(bus=__FTDI_WRAPPER_I2C(controller, port))
#     serial._managed = True
#     serial._i2c_msg_write = lambda address, data: (address, data)
#     return serial


import pytest
import luma.core.error
from unittest.mock import Mock, patch
from luma.core.interface.serial import ftdi_i2c
from helpers import fib
    port = Mock()
    instance = Mock()
    instance.get_port = Mock(return_value=port)
    mock_controller.side_effect = [instance]

    serial = ftdi_i2c(device='ftdi://dummy', address=0x3C)
    serial.command(*cmds)
    port.write_to.assert_called_once_with(0x00, cmds)


@patch('pyftdi.i2c.I2cController')
def test_data(mock_controller):
    data = list(fib(100))
    port = Mock()
    instance = Mock()
    instance.get_port = Mock(return_value=port)
    mock_controller.side_effect = [instance]

    serial = ftdi_i2c(device='ftdi://dummy', address=0x3C)
    serial.data(data)
    port.write_to.assert_called_once_with(0x40, data)


@patch('pyftdi.i2c.I2cController')
def test_cleanup(mock_controller):
    port = Mock()
    instance = Mock()
    instance.get_port = Mock(return_value=port)
    mock_controller.side_effect = [instance]


# Path: luma/core/interface/serial.py
# def ftdi_i2c(device='ftdi://::/1', address=0x3C):
#     """
#     Bridges an `I²C <https://en.wikipedia.org/wiki/I%C2%B2C>`_ (Inter-Integrated
#     Circuit) interface over an FTDI USB device to provide :py:func:`data` and
#     :py:func:`command` methods.
# 
#     :param device: A URI describing the location of the FTDI device. If ``None`` is
#         supplied (default), ``ftdi://::/1`` is used. See `pyftdi <https://pypi.org/project/pyftdi>`_
#         for further details of the naming scheme used.
#     :type device: string
#     :param address: I²C address, default: ``0x3C``.
#     :type address: int
#     :raises luma.core.error.DeviceAddressError: I2C device address is invalid.
# 
#     .. versionadded:: 1.9.0
#     """
#     from pyftdi.i2c import I2cController
# 
#     try:
#         addr = int(str(address), 0)
#     except ValueError:
#         raise luma.core.error.DeviceAddressError(
#             f'I2C device address invalid: {address}')
# 
#     controller = I2cController()
#     controller.configure(device)
# 
#     port = controller.get_port(addr)
# 
#     serial = i2c(bus=__FTDI_WRAPPER_I2C(controller, port))
#     serial._managed = True
#     serial._i2c_msg_write = lambda address, data: (address, data)
#     return serial


# Path: tests/test_ftdi_i2c.py
import pytest
import luma.core.error
from unittest.mock import Mock, patch
from luma.core.interface.serial import ftdi_i2c
from helpers import fib

    port = Mock()
    instance = Mock()
    instance.get_port = Mock(return_value=port)
    mock_controller.side_effect = [instance]

    serial = ftdi_i2c(device='ftdi://dummy', address=0x3C)
    serial.command(*cmds)
    port.write_to.assert_called_once_with(0x00, cmds)


@patch('pyftdi.i2c.I2cController')
def test_data(mock_controller):
    data = list(fib(100))
    port = Mock()
    instance = Mock()
    instance.get_port = Mock(return_value=port)
    mock_controller.side_effect = [instance]

    serial = ftdi_i2c(device='ftdi://dummy', address=0x3C)
    serial.data(data)
    port.write_to.assert_called_once_with(0x40, data)


@patch('pyftdi.i2c.I2cController')
def test_cleanup(mock_controller):
    port = Mock()
    instance = Mock()
    instance.get_port = Mock(return_value=port)
    mock_controller.side_effect = [instance]


    serial = ftdi_i2c(device='ftdi://dummy', address=0x3C)