# Path: pycoral/utils/edgetpu.py
# _EDGETPU_SHARED_LIB = {
#   'Linux': 'libedgetpu.so.1',
#   'Darwin': 'libedgetpu.1.dylib',
#   'Windows': 'edgetpu.dll'
# }[platform.system()]
# def load_edgetpu_delegate(options=None):
# def make_interpreter(model_path_or_content, device=None, delegate=None):
# def _is_valid_ctypes_input(input_data):
# def _gst_buffer_map(buffer):
# def _check_input_size(input_size, expected_input_size):
# def run_inference(interpreter, input_data):
# class _GstMapInfo(ctypes.Structure):
# 
# Path: tests/test_utils.py
# _TEST_DATA_DIR = ''
#   _TEST_DATA_DIR = args.test_data_dir
# def get_test_tmpdir():
# def test_data_path(path, *paths):
# def test_image(path, *paths):
# def temporary_file(suffix=None):
# def generate_random_input(seed, n):
# def prepare_images(image_list, directory, shape):
# def area(box):
# def iou(box_a, box_b):
# def prepare_data_set_from_directory(path, test_ratio, fixed_order):
# def coral_test_main():


import ctypes
import ctypes.util
import io
import numpy as np
import unittest
  import gi
from pycoral.utils import edgetpu
from tests import test_utils
  from gi.repository import Gst
    input_size = 224 * 224 * 3
    # Note: Exception is triggered because interpreter.allocate_tensors() is not
    # called.
    with self.assertRaisesRegex(RuntimeError,
                                'Invoke called on model that is not ready.'):
      edgetpu.invoke_with_dmabuffer(interpreter._native_handle(), 0, input_size)

  def test_invoke_with_mem_buffer_model_not_ready(self):
    interpreter = edgetpu.make_interpreter(
        self._default_test_model_path(), delegate=self.delegate)
    input_size = 224 * 224 * 3
    np_input = np.zeros(input_size, dtype=np.uint8)
    # Note: Exception is triggered because interpreter.allocate_tensors() is not
    # called.
    with self.assertRaisesRegex(RuntimeError,
                                'Invoke called on model that is not ready.'):
      edgetpu.invoke_with_membuffer(interpreter._native_handle(),
                                    np_input.ctypes.data, input_size)

  def test_list_edge_tpu_paths(self):
    self.assertGreater(len(edgetpu.list_edge_tpus()), 0)

  def test_set_verbosity(self):
    # Simply sets the verbosity and ensure it returns success.
    self.assertTrue(edgetpu.set_verbosity(10))
    # Returns the verbosity back to zero.
    self.assertTrue(edgetpu.set_verbosity(0))


if __name__ == '__main__':

# Path: pycoral/utils/edgetpu.py
# _EDGETPU_SHARED_LIB = {
#   'Linux': 'libedgetpu.so.1',
#   'Darwin': 'libedgetpu.1.dylib',
#   'Windows': 'edgetpu.dll'
# }[platform.system()]
# def load_edgetpu_delegate(options=None):
# def make_interpreter(model_path_or_content, device=None, delegate=None):
# def _is_valid_ctypes_input(input_data):
# def _gst_buffer_map(buffer):
# def _check_input_size(input_size, expected_input_size):
# def run_inference(interpreter, input_data):
# class _GstMapInfo(ctypes.Structure):
# 
# Path: tests/test_utils.py
# _TEST_DATA_DIR = ''
#   _TEST_DATA_DIR = args.test_data_dir
# def get_test_tmpdir():
# def test_data_path(path, *paths):
# def test_image(path, *paths):
# def temporary_file(suffix=None):
# def generate_random_input(seed, n):
# def prepare_images(image_list, directory, shape):
# def area(box):
# def iou(box_a, box_b):
# def prepare_data_set_from_directory(path, test_ratio, fixed_order):
# def coral_test_main():


# Path: tests/edgetpu_utils_test.py
import ctypes
import ctypes.util
import io
import numpy as np
import unittest
  import gi
from pycoral.utils import edgetpu
from tests import test_utils
  from gi.repository import Gst

    input_size = 224 * 224 * 3
    # Note: Exception is triggered because interpreter.allocate_tensors() is not
    # called.
    with self.assertRaisesRegex(RuntimeError,
                                'Invoke called on model that is not ready.'):
      edgetpu.invoke_with_dmabuffer(interpreter._native_handle(), 0, input_size)

  def test_invoke_with_mem_buffer_model_not_ready(self):
    interpreter = edgetpu.make_interpreter(
        self._default_test_model_path(), delegate=self.delegate)
    input_size = 224 * 224 * 3
    np_input = np.zeros(input_size, dtype=np.uint8)
    # Note: Exception is triggered because interpreter.allocate_tensors() is not
    # called.
    with self.assertRaisesRegex(RuntimeError,
                                'Invoke called on model that is not ready.'):
      edgetpu.invoke_with_membuffer(interpreter._native_handle(),
                                    np_input.ctypes.data, input_size)

  def test_list_edge_tpu_paths(self):
    self.assertGreater(len(edgetpu.list_edge_tpus()), 0)

  def test_set_verbosity(self):
    # Simply sets the verbosity and ensure it returns success.
    self.assertTrue(edgetpu.set_verbosity(10))
    # Returns the verbosity back to zero.
    self.assertTrue(edgetpu.set_verbosity(0))


if __name__ == '__main__':

  test_utils.coral_test_main()