def test_device_add_neighbour_device(buffer_connection): from moler.device.unixlocal import UnixLocal dev1 = UnixLocal(io_connection=buffer_connection) dev2 = UnixLocal(io_connection=buffer_connection) neighbour_devices = dev1.get_neighbour_devices(device_type=UnixLocal) assert 0 == len(neighbour_devices) dev1.add_neighbour_device(neighbour_device=dev2, bidirectional=True) neighbour_devices = dev1.get_neighbour_devices(device_type=UnixLocal) assert 1 == len(neighbour_devices) neighbour_devices = dev2.get_neighbour_devices(device_type=UnixLocal) assert 1 == len(neighbour_devices) # device is added only once dev1.add_neighbour_device(neighbour_device=dev2) neighbour_devices = dev1.get_neighbour_devices(device_type=UnixLocal) assert 1 == len(neighbour_devices) neighbour_devices = dev1.get_neighbour_devices(device_type=None) assert 1 == len(neighbour_devices) neighbour_devices = dev1.get_neighbour_devices(device_type=int) assert 0 == len(neighbour_devices)
def test_device_add_neighbour_device_without_bidirectional(buffer_connection): from moler.device.unixlocal import UnixLocal dev1 = UnixLocal(io_connection=buffer_connection) dev2 = UnixLocal(io_connection=buffer_connection) dev1.add_neighbour_device(neighbour_device=dev2, bidirectional=False) neighbour_devices = dev1.get_neighbour_devices(device_type=UnixLocal) assert 1 == len(neighbour_devices) neighbour_devices = dev2.get_neighbour_devices(device_type=UnixLocal) assert 0 == len(neighbour_devices)