# Path: android_env/components/specs.py
# _PROTO_DTYPE_TO_NUMPY_DTYPE = {
#     task_pb2.ArraySpec.DataType.FLOAT: np.float32,
#     task_pb2.ArraySpec.DataType.DOUBLE: np.float64,
#     task_pb2.ArraySpec.DataType.INT8: np.int8,
#     task_pb2.ArraySpec.DataType.INT16: np.int16,
#     task_pb2.ArraySpec.DataType.INT32: np.int32,
#     task_pb2.ArraySpec.DataType.INT64: np.int64,
#     task_pb2.ArraySpec.DataType.UINT8: np.uint8,
#     task_pb2.ArraySpec.DataType.UINT16: np.uint16,
#     task_pb2.ArraySpec.DataType.UINT32: np.uint32,
#     task_pb2.ArraySpec.DataType.UINT64: np.uint64,
#     task_pb2.ArraySpec.DataType.BOOL: np.bool_,
#     task_pb2.ArraySpec.DataType.STRING_U1: np.dtype(('U1')),
#     task_pb2.ArraySpec.DataType.STRING_U16: np.dtype(('<U16')),
#     task_pb2.ArraySpec.DataType.STRING_U25: np.dtype(('<U25')),
#     task_pb2.ArraySpec.DataType.STRING_U250: np.dtype(('<U250')),
# }
# def base_action_spec(num_fingers: int = 1) -> Dict[str, specs.Array]:
# def base_observation_spec(height: int, width: int) -> Dict[str, specs.Array]:
# def base_task_extras_spec(task: task_pb2.Task) -> Dict[str, dm_env.specs.Array]:
# def _convert_spec(array_spec: task_pb2.ArraySpec) -> specs.Array:


from absl.testing import absltest
from absl.testing import parameterized
from android_env.components import specs
from android_env.proto import task_pb2
from dm_env import specs as dm_env_specs
import numpy as np
    array_spec_2 = task_pb2.ArraySpec()
    array_spec_2.name = 'my_extra_2'
    array_spec_2.shape.extend([1])
    array_spec_2.dtype = task_pb2.ArraySpec.UINT8

    fake_task = task_pb2.Task()
    fake_task.extras_spec.extend([array_spec_1, array_spec_2])
    task_extras_spec = specs.base_task_extras_spec(fake_task)
    for spec in task_extras_spec.values():
      self.assertIsInstance(spec, dm_env_specs.Array)

    self.assertEqual(task_extras_spec['my_extra_1'].shape, (10, 10))
    self.assertEqual(task_extras_spec['my_extra_2'].shape, (1,))
    self.assertEqual(task_extras_spec['my_extra_1'].dtype, np.float32)
    self.assertEqual(task_extras_spec['my_extra_2'].dtype, np.uint8)

  @parameterized.parameters(
      ('name_1', [480, 320, 3], task_pb2.ArraySpec.FLOAT, np.float32),
      ('name_2', [100, 100, 3], task_pb2.ArraySpec.INT32, np.int32),
      ('name_3', [123, 456, 3], task_pb2.ArraySpec.UINT8, np.uint8),
      ('name_4', [480, 320, 1], task_pb2.ArraySpec.BOOL, np.bool_),
      ('', [480, 320], task_pb2.ArraySpec.STRING_U25, np.dtype(('<U25'))),
  )
  def test_convert_spec(self, name, shape, dtype, expected_dtype):
    fake_array_spec = task_pb2.ArraySpec()
    fake_array_spec.name = name
    fake_array_spec.dtype = dtype
    fake_array_spec.shape.extend(shape)
    fake_task = task_pb2.Task()
    fake_task.extras_spec.extend([fake_array_spec])

# Path: android_env/components/specs.py
# _PROTO_DTYPE_TO_NUMPY_DTYPE = {
#     task_pb2.ArraySpec.DataType.FLOAT: np.float32,
#     task_pb2.ArraySpec.DataType.DOUBLE: np.float64,
#     task_pb2.ArraySpec.DataType.INT8: np.int8,
#     task_pb2.ArraySpec.DataType.INT16: np.int16,
#     task_pb2.ArraySpec.DataType.INT32: np.int32,
#     task_pb2.ArraySpec.DataType.INT64: np.int64,
#     task_pb2.ArraySpec.DataType.UINT8: np.uint8,
#     task_pb2.ArraySpec.DataType.UINT16: np.uint16,
#     task_pb2.ArraySpec.DataType.UINT32: np.uint32,
#     task_pb2.ArraySpec.DataType.UINT64: np.uint64,
#     task_pb2.ArraySpec.DataType.BOOL: np.bool_,
#     task_pb2.ArraySpec.DataType.STRING_U1: np.dtype(('U1')),
#     task_pb2.ArraySpec.DataType.STRING_U16: np.dtype(('<U16')),
#     task_pb2.ArraySpec.DataType.STRING_U25: np.dtype(('<U25')),
#     task_pb2.ArraySpec.DataType.STRING_U250: np.dtype(('<U250')),
# }
# def base_action_spec(num_fingers: int = 1) -> Dict[str, specs.Array]:
# def base_observation_spec(height: int, width: int) -> Dict[str, specs.Array]:
# def base_task_extras_spec(task: task_pb2.Task) -> Dict[str, dm_env.specs.Array]:
# def _convert_spec(array_spec: task_pb2.ArraySpec) -> specs.Array:


# Path: android_env/components/specs_test.py
from absl.testing import absltest
from absl.testing import parameterized
from android_env.components import specs
from android_env.proto import task_pb2
from dm_env import specs as dm_env_specs
import numpy as np

    array_spec_2 = task_pb2.ArraySpec()
    array_spec_2.name = 'my_extra_2'
    array_spec_2.shape.extend([1])
    array_spec_2.dtype = task_pb2.ArraySpec.UINT8

    fake_task = task_pb2.Task()
    fake_task.extras_spec.extend([array_spec_1, array_spec_2])
    task_extras_spec = specs.base_task_extras_spec(fake_task)
    for spec in task_extras_spec.values():
      self.assertIsInstance(spec, dm_env_specs.Array)

    self.assertEqual(task_extras_spec['my_extra_1'].shape, (10, 10))
    self.assertEqual(task_extras_spec['my_extra_2'].shape, (1,))
    self.assertEqual(task_extras_spec['my_extra_1'].dtype, np.float32)
    self.assertEqual(task_extras_spec['my_extra_2'].dtype, np.uint8)

  @parameterized.parameters(
      ('name_1', [480, 320, 3], task_pb2.ArraySpec.FLOAT, np.float32),
      ('name_2', [100, 100, 3], task_pb2.ArraySpec.INT32, np.int32),
      ('name_3', [123, 456, 3], task_pb2.ArraySpec.UINT8, np.uint8),
      ('name_4', [480, 320, 1], task_pb2.ArraySpec.BOOL, np.bool_),
      ('', [480, 320], task_pb2.ArraySpec.STRING_U25, np.dtype(('<U25'))),
  )
  def test_convert_spec(self, name, shape, dtype, expected_dtype):
    fake_array_spec = task_pb2.ArraySpec()
    fake_array_spec.name = name
    fake_array_spec.dtype = dtype
    fake_array_spec.shape.extend(shape)
    fake_task = task_pb2.Task()
    fake_task.extras_spec.extend([fake_array_spec])

    task_extras_spec = specs.base_task_extras_spec(fake_task)