code: def test_bidirectional_mode(pattern, target_data, options):
      """
      Testing NetGear's Bidirectional Mode with different data-types
      """
      # initialize
      stream = None
      server = None
      client = None
      try:
          logger.debug(
              "Given Input Data: {}".format(
                  target_data
                  if not isinstance(target_data, np.ndarray)
                  else "IMAGE"
              )
          )
          # open stream
          options_gear = {"THREAD_TIMEOUT": 60}
          # change colorspace
          colorspace = (
              "COLOR_BGR2GRAY"
              if isinstance(options["jpeg_compression"], str)
              and options["jpeg_compression"].strip().upper() == "GRAY"
              else None
          )
          if colorspace == "COLOR_BGR2GRAY" and isinstance(
              target_data, np.ndarray
          ):
              target_data = cv2.cvtColor(
                  target_data, cv2.COLOR_BGR2GRAY
              )
  
          stream = VideoGear(
              source=return_testvideo_path(),
              colorspace=colorspace,
              **options_gear,
          ).start()
          # define params
          client = NetGear(
              pattern=pattern,
              receive_mode=True,
              logging=True,
              **options,
          )
          server = NetGear(pattern=pattern, logging=True, **options)
          # check if target data is numpy ndarray
          if isinstance(target_data, np.ndarray):
              # sent frame and data from server to client
              server.send(target_data, message=target_data)
              # client receives the data and frame and send its data
              server_data, frame_client = client.recv(
                  return_data=target_data
              )
              # server receives the data and cycle continues
              client_data = server.send(target_data)
              # test if received successfully
              assert not (client_data is None), "Test Failed!"
          else:
              # get frame from stream
              frame_server = stream.read()
              assert not (frame_server is None)
              # sent frame and data from server to client
              server.send(frame_server, message=target_data)
              # client receives the data and frame and send its data
              server_data, frame_client = client.recv(
                  return_data=target_data
              )
              # server receives the data and cycle continues
              client_data = server.send(
                  frame_server, message=target_data
              )
              # check if received frame exactly matches input frame
              if not options["jpeg_compression"] in [
                  True,
                  "GRAY",
                  ["invalid"],
              ]:
                  assert np.array_equal(frame_server, frame_client)
              # logger.debug data received at client-end and server-end
              logger.debug(
                  "Data received at Server-end: {}".format(server_data)
              )
              logger.debug(
                  "Data received at Client-end: {}".format(client_data)
              )
              assert client_data == server_data
      except Exception as e:
          if isinstance(
              e, (ZMQError, ValueError, RuntimeError, queue.Empty)
          ):
              pytest.xfail(str(e))
          else:
              pytest.fail(str(e))
      finally:
          # clean resources
          if not (stream is None):
              stream.stop()
          if not (server is None):
              server.close(kill=True)
          if not (client is None):
              client.close(kill=True)
  
imports: import os
  import platform
  import queue
  import cv2
  import numpy
  import pytest
  import random
  import logging
  import tempfile
  from zmq.error import ZMQError
  from vidgear.gears import NetGear, VideoGear
  from vidgear.gears.helper import logger_handler
label_desc: Use image node_id 7 for calling a global function with example usage: test_bidirectional_mode(pattern, target_data, options) without return types