# Path: vizier/pyvizier/oss/metadata_util.py
# T = TypeVar('T')
# def assign(container: Union[study_pb2.StudySpec, study_pb2.Trial], *,
#            key: str, ns: str,
#            value: Union[str, any_pb2.Any, Message]
#           ) -> Tuple[key_value_pb2.KeyValue, bool]:
# def get(container: Union[study_pb2.StudySpec, study_pb2.Trial], *,
#         key: str, ns: str) -> Optional[str]:
# def get_proto(container: Union[study_pb2.StudySpec, study_pb2.Trial], *,
#               key: str, ns: str, cls: Type[T]) -> Optional[T]:


from vizier.pyvizier.oss import metadata_util
from vizier.service import study_pb2
from absl.testing import absltest
"""Tests for vizier.pyvizier.oss.metadata_util."""




class MetadataUtilTest(absltest.TestCase):

  def test_get(self):
    meta_trial = study_pb2.Trial(id=str(999))
    trial = study_pb2.Trial(id=1)
    metadata_util.assign(trial, key='any', ns='', value=meta_trial)
    metadata_util.assign(trial, key='text', ns='x', value='x-value')
    metadata_util.assign(trial, key='text', ns='', value='value')
    metadata_util.assign(trial, key='text', ns='y', value='y-value')
    self.assertEqual(
        metadata_util.get_proto(trial, key='any', ns='', cls=study_pb2.Trial),
        meta_trial)
    self.assertEqual(metadata_util.get(trial, key='text', ns=''), 'value')
    self.assertEqual(metadata_util.get(trial, key='text', ns='x'), 'x-value')

    self.assertIsNone(
        metadata_util.get_proto(trial, key='any', ns='', cls=study_pb2.Study))

# Path: vizier/pyvizier/oss/metadata_util.py
# T = TypeVar('T')
# def assign(container: Union[study_pb2.StudySpec, study_pb2.Trial], *,
#            key: str, ns: str,
#            value: Union[str, any_pb2.Any, Message]
#           ) -> Tuple[key_value_pb2.KeyValue, bool]:
# def get(container: Union[study_pb2.StudySpec, study_pb2.Trial], *,
#         key: str, ns: str) -> Optional[str]:
# def get_proto(container: Union[study_pb2.StudySpec, study_pb2.Trial], *,
#               key: str, ns: str, cls: Type[T]) -> Optional[T]:


# Path: vizier/pyvizier/oss/metadata_util_test.py
from vizier.pyvizier.oss import metadata_util
from vizier.service import study_pb2
from absl.testing import absltest

"""Tests for vizier.pyvizier.oss.metadata_util."""




class MetadataUtilTest(absltest.TestCase):

  def test_get(self):
    meta_trial = study_pb2.Trial(id=str(999))
    trial = study_pb2.Trial(id=1)
    metadata_util.assign(trial, key='any', ns='', value=meta_trial)
    metadata_util.assign(trial, key='text', ns='x', value='x-value')
    metadata_util.assign(trial, key='text', ns='', value='value')
    metadata_util.assign(trial, key='text', ns='y', value='y-value')
    self.assertEqual(
        metadata_util.get_proto(trial, key='any', ns='', cls=study_pb2.Trial),
        meta_trial)
    self.assertEqual(metadata_util.get(trial, key='text', ns=''), 'value')
    self.assertEqual(metadata_util.get(trial, key='text', ns='x'), 'x-value')

    self.assertIsNone(
        metadata_util.get_proto(trial, key='any', ns='', cls=study_pb2.Study))

    self.assertIsNone(metadata_util.get(trial, key='TYPO', ns=''))