# Path: envlogger/converters/spec_codec.py
# _ENVIRONMENT_SPEC_NAMES = [
#     'observation_spec',
#     'action_spec',
#     'reward_spec',
#     'discount_spec',
# ]
# def encode_environment_specs(
#     env: Optional[dm_env.Environment]) -> Dict[str, Any]:
# def decode_environment_specs(
#     encoded_specs: Dict[str, Any]) -> Dict[str, Optional[specs.Array]]:
# def _array_spec_to_dict(array_spec: specs.Array) -> Dict[str, Any]:
# def encode(
#     spec: Union[specs.Array, List[Any], Tuple[Any], Dict[str, Any]]
# ) -> Union[List[Any], Tuple[Any], Dict[str, Any]]:
# def decode(
#     spec: Union[List[Any], Tuple[Any], Dict[str, Any]]
# ) -> Union[specs.Array, List[Any], Tuple[Any], Dict[str, Any]]:


from typing import Any, Dict
from absl.testing import absltest
from absl.testing import parameterized
from dm_env import specs
from envlogger.converters import spec_codec
import dm_env
import numpy as np
  )
  def test_decode_discrete_array(self, input_spec_dict, expected_spec):
    result = spec_codec.decode(input_spec_dict)
    self.assertIsInstance(result, specs.DiscreteArray)
    self.assertEqual(result, expected_spec)

  # Lists of specs.Arrays.

  @parameterized.named_parameters(
      ('empty_list', [], []),
      ('single_spec', [{
          'shape': np.array([], np.int64),
          'dtype': 'float32',
          'name': 'my_spec',
      }], [specs.Array((), np.float32, 'my_spec')]),
      ('two_specs', [{
          'shape': np.array([1, 2, 3], np.int64),
          'dtype': 'float32',
          'name': 'spec1',
      }, {
          'shape': np.array([3, 2, 1], np.int64),
          'dtype': 'int32',
          'name': 'spec2',
      }], [
          specs.Array((1, 2, 3), np.float32, 'spec1'),
          specs.Array((3, 2, 1), np.int32, 'spec2')
      ]),
  )
  def test_decode_list_of_specs(self, input_spec, expected_spec_list):
    """Checks that we can encode lists of Array specs."""

# Path: envlogger/converters/spec_codec.py
# _ENVIRONMENT_SPEC_NAMES = [
#     'observation_spec',
#     'action_spec',
#     'reward_spec',
#     'discount_spec',
# ]
# def encode_environment_specs(
#     env: Optional[dm_env.Environment]) -> Dict[str, Any]:
# def decode_environment_specs(
#     encoded_specs: Dict[str, Any]) -> Dict[str, Optional[specs.Array]]:
# def _array_spec_to_dict(array_spec: specs.Array) -> Dict[str, Any]:
# def encode(
#     spec: Union[specs.Array, List[Any], Tuple[Any], Dict[str, Any]]
# ) -> Union[List[Any], Tuple[Any], Dict[str, Any]]:
# def decode(
#     spec: Union[List[Any], Tuple[Any], Dict[str, Any]]
# ) -> Union[specs.Array, List[Any], Tuple[Any], Dict[str, Any]]:


# Path: envlogger/converters/spec_codec_test.py
from typing import Any, Dict
from absl.testing import absltest
from absl.testing import parameterized
from dm_env import specs
from envlogger.converters import spec_codec
import dm_env
import numpy as np

  )
  def test_decode_discrete_array(self, input_spec_dict, expected_spec):
    result = spec_codec.decode(input_spec_dict)
    self.assertIsInstance(result, specs.DiscreteArray)
    self.assertEqual(result, expected_spec)

  # Lists of specs.Arrays.

  @parameterized.named_parameters(
      ('empty_list', [], []),
      ('single_spec', [{
          'shape': np.array([], np.int64),
          'dtype': 'float32',
          'name': 'my_spec',
      }], [specs.Array((), np.float32, 'my_spec')]),
      ('two_specs', [{
          'shape': np.array([1, 2, 3], np.int64),
          'dtype': 'float32',
          'name': 'spec1',
      }, {
          'shape': np.array([3, 2, 1], np.int64),
          'dtype': 'int32',
          'name': 'spec2',
      }], [
          specs.Array((1, 2, 3), np.float32, 'spec1'),
          specs.Array((3, 2, 1), np.int32, 'spec2')
      ]),
  )
  def test_decode_list_of_specs(self, input_spec, expected_spec_list):
    """Checks that we can encode lists of Array specs."""

    result = spec_codec.decode(input_spec)