



"""simple docstring"""
import inspect
import unittest
from typing import List

import numpy as np

from transformers import EfficientFormerConfig
from transformers.testing_utils import require_tf, require_vision, slow
from transformers.utils import cached_property, is_tf_available, is_vision_available

from ...test_configuration_common import ConfigTester
from ...test_modeling_tf_common import TFModelTesterMixin, floats_tensor, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_tf_available():
      import tensorflow as tf

      from transformers import (
          TFEfficientFormerForImageClassification,
          TFEfficientFormerForImageClassificationWithTeacher,
          TFEfficientFormerModel,
      )
      from transformers.models.efficientformer.modeling_tf_efficientformer import (
          TF_EFFICIENTFORMER_PRETRAINED_MODEL_ARCHIVE_LIST,
      )


if is_vision_available():
      from PIL import Image

      from transformers import EfficientFormerImageProcessor



class    SCREAMING_SNAKE_CASE__						:

   def __init__(     self   ,  _SCREAMING_SNAKE_CASE   ,  _SCREAMING_SNAKE_CASE = 13   ,  _SCREAMING_SNAKE_CASE = 64   ,  _SCREAMING_SNAKE_CASE = 2   ,  _SCREAMING_SNAKE_CASE = 3   ,  _SCREAMING_SNAKE_CASE = 3   ,  _SCREAMING_SNAKE_CASE = True   ,  _SCREAMING_SNAKE_CASE = True   ,  _SCREAMING_SNAKE_CASE = 128   ,  _SCREAMING_SNAKE_CASE=[16, 32, 64, 128]   ,  _SCREAMING_SNAKE_CASE = 7   ,  _SCREAMING_SNAKE_CASE = 4   ,  _SCREAMING_SNAKE_CASE = 37   ,  _SCREAMING_SNAKE_CASE = "gelu"   ,  _SCREAMING_SNAKE_CASE = 0.1   ,  _SCREAMING_SNAKE_CASE = 0.1   ,  _SCREAMING_SNAKE_CASE = 10   ,  _SCREAMING_SNAKE_CASE = 0.02   ,  _SCREAMING_SNAKE_CASE = 2   ,  _SCREAMING_SNAKE_CASE = 1   ,  _SCREAMING_SNAKE_CASE = 128   ,  _SCREAMING_SNAKE_CASE = [2, 2, 2, 2]   ,  _SCREAMING_SNAKE_CASE = 2   ,  _SCREAMING_SNAKE_CASE = 2   ,  )						->   Union[str, Any]:





     '''simple docstring'''




     UpperCAmelCase			:      Optional[Any]			=			parent
     UpperCAmelCase			:      int			=			batch_size
     UpperCAmelCase			:      Optional[int]			=			image_size
     UpperCAmelCase			:      Any			=			patch_size
     UpperCAmelCase			:      List[Any]			=			num_channels
     UpperCAmelCase			:      List[Any]			=			is_training
     UpperCAmelCase			:      Dict			=			use_labels
     UpperCAmelCase			:      Dict			=			hidden_size
     UpperCAmelCase			:      Tuple			=			num_hidden_layers
     UpperCAmelCase			:      Dict			=			num_attention_heads
     UpperCAmelCase			:      Union[str, Any]			=			intermediate_size
     UpperCAmelCase			:      Optional[int]			=			hidden_act
     UpperCAmelCase			:      Dict			=			hidden_dropout_prob
     UpperCAmelCase			:      str			=			attention_probs_dropout_prob
     UpperCAmelCase			:      List[Any]			=			type_sequence_label_size
     UpperCAmelCase			:      int			=			initializer_range
     UpperCAmelCase			:      Tuple			=			encoder_stride
     UpperCAmelCase			:      List[str]			=			num_attention_outputs
     UpperCAmelCase			:      Optional[Any]			=			embed_dim
     UpperCAmelCase			:      Any			=			embed_dim + 1
     UpperCAmelCase			:      Optional[Any]			=			resolution
     UpperCAmelCase			:      List[Any]			=			depths
     UpperCAmelCase			:      Any			=			hidden_sizes
     UpperCAmelCase			:      Any			=			dim
     UpperCAmelCase			:      Tuple			=			mlp_expansion_ratio

   def 			SCREAMING_SNAKE_CASE  (     self		)						->   Union[str, Any]:





     '''simple docstring'''




     UpperCAmelCase			:      Optional[Any]			=			floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]		)

     UpperCAmelCase			:      Dict			=			None
     if self.use_labels:
       UpperCAmelCase			:      Dict			=			ids_tensor([self.batch_size]   ,  self.type_sequence_label_size		)

     UpperCAmelCase			:      Optional[int]			=			self.get_config()

     return config, pixel_values, labels

   def 			SCREAMING_SNAKE_CASE  (     self		)						->   Any:





     '''simple docstring'''




     return EfficientFormerConfig(
         image_size=self.image_size   ,  patch_size=self.patch_size   ,  num_channels=self.num_channels   ,  hidden_size=self.hidden_size   ,  num_hidden_layers=self.num_hidden_layers   ,  num_attention_heads=self.num_attention_heads   ,  intermediate_size=self.intermediate_size   ,  hidden_act=self.hidden_act   ,  hidden_dropout_prob=self.hidden_dropout_prob   ,  attention_probs_dropout_prob=self.attention_probs_dropout_prob   ,  is_decoder=_SCREAMING_SNAKE_CASE   ,  initializer_range=self.initializer_range   ,  encoder_stride=self.encoder_stride   ,  resolution=self.resolution   ,  depths=self.depths   ,  hidden_sizes=self.hidden_sizes   ,  dim=self.dim   ,  mlp_expansion_ratio=self.mlp_expansion_ratio   ,  )

   def 			SCREAMING_SNAKE_CASE  (     self   ,  _SCREAMING_SNAKE_CASE   ,  _SCREAMING_SNAKE_CASE   ,  _SCREAMING_SNAKE_CASE		)						->   Optional[int]:





     '''simple docstring'''




     UpperCAmelCase			:      Any			=			TFEfficientFormerModel(config=_SCREAMING_SNAKE_CASE		)
     UpperCAmelCase			:      Optional[int]			=			model(_SCREAMING_SNAKE_CASE   ,  training=_SCREAMING_SNAKE_CASE		)
     self.parent.assertEqual(result.last_hidden_state.shape   ,  (self.batch_size, self.seq_length, self.hidden_size)		)

   def 			SCREAMING_SNAKE_CASE  (     self   ,  _SCREAMING_SNAKE_CASE   ,  _SCREAMING_SNAKE_CASE   ,  _SCREAMING_SNAKE_CASE		)						->   Any:





     '''simple docstring'''




     UpperCAmelCase			:      Union[str, Any]			=			self.type_sequence_label_size
     UpperCAmelCase			:      List[Any]			=			TFEfficientFormerForImageClassification(_SCREAMING_SNAKE_CASE		)
     UpperCAmelCase			:      Union[str, Any]			=			model(_SCREAMING_SNAKE_CASE   ,  labels=_SCREAMING_SNAKE_CASE   ,  training=_SCREAMING_SNAKE_CASE		)
     self.parent.assertEqual(result.logits.shape   ,  (self.batch_size, self.type_sequence_label_size)		)

     # test greyscale images
     UpperCAmelCase			:      List[str]			=			1
     UpperCAmelCase			:      Tuple			=			TFEfficientFormerForImageClassification(_SCREAMING_SNAKE_CASE		)

     UpperCAmelCase			:      Tuple			=			floats_tensor([self.batch_size, 1, self.image_size, self.image_size]		)
     UpperCAmelCase			:      Tuple			=			model(_SCREAMING_SNAKE_CASE   ,  labels=_SCREAMING_SNAKE_CASE		)
     self.parent.assertEqual(result.logits.shape   ,  (self.batch_size, self.type_sequence_label_size)		)




   def 			SCREAMING_SNAKE_CASE  (     self		)						->   List[str]:





     '''simple docstring'''




     UpperCAmelCase			:      List[Any]			=			self.prepare_config_and_inputs()
     UpperCAmelCase			:      int			=			config_and_inputs
     UpperCAmelCase			:      Tuple			=			{"""pixel_values""": pixel_values}
     return config, inputs_dict



@require_tf
class    SCREAMING_SNAKE_CASE__						(      UpperCAmelCase__   ,    UpperCAmelCase__   ,    unittest.TestCase				):
   __lowerCAmelCase						:     List[str]		=		(
       (
           TFEfficientFormerModel,
           TFEfficientFormerForImageClassificationWithTeacher,
           TFEfficientFormerForImageClassification,
       )
       if is_tf_available()
       else ()
   )
   __lowerCAmelCase						:     Any		=		(
       {
           'feature-extraction': TFEfficientFormerModel,
           'image-classification': (
               TFEfficientFormerForImageClassification,
               TFEfficientFormerForImageClassificationWithTeacher,
           ),
       }
       if is_tf_available()
       else {}
   )

   __lowerCAmelCase						:     Union[str, Any]		=		False

   __lowerCAmelCase						:     List[Any]		=		False
   __lowerCAmelCase						:     str		=		False
   __lowerCAmelCase						:     List[Any]		=		False
   __lowerCAmelCase						:     List[Any]		=		False

   def 			SCREAMING_SNAKE_CASE  (     self		)						->   List[str]:





     '''simple docstring'''




     UpperCAmelCase			:      List[str]			=			TFEfficientFormerModelTester(self		)
     UpperCAmelCase			:      Union[str, Any]			=			ConfigTester(
         self   ,  config_class=_SCREAMING_SNAKE_CASE   ,  has_text_modality=_SCREAMING_SNAKE_CASE   ,  hidden_size=37		)

   def 			SCREAMING_SNAKE_CASE  (     self		)						->   int:





     '''simple docstring'''




     self.config_tester.run_common_tests()

   @unittest.skip(reason="""EfficientFormer does not use inputs_embeds"""		)
   def 			SCREAMING_SNAKE_CASE  (     self		)						->   Tuple:





     '''simple docstring'''




     pass

   @unittest.skip(reason="""EfficientFormer does not support input and output embeddings"""		)
   def 			SCREAMING_SNAKE_CASE  (     self		)						->   Optional[Any]:





     '''simple docstring'''




     pass

   def 			SCREAMING_SNAKE_CASE  (     self		)						->   Union[str, Any]:





     '''simple docstring'''




     UpperCAmelCase			:      Optional[Any]			=			self.model_tester.prepare_config_and_inputs_for_common()

     for model_class in self.all_model_classes:
       UpperCAmelCase			:      List[Any]			=			model_class(_SCREAMING_SNAKE_CASE		)
       UpperCAmelCase			:      Dict			=			inspect.signature(model.call		)
       # signature.parameters is an OrderedDict => so arg_names order is deterministic
       UpperCAmelCase			:      List[str]			=			[*signature.parameters.keys()]

       UpperCAmelCase			:      int			=			["""pixel_values"""]
       self.assertListEqual(arg_names[:1]   ,  _SCREAMING_SNAKE_CASE		)

   def 			SCREAMING_SNAKE_CASE  (     self		)						->   Any:





     '''simple docstring'''




     def check_hidden_states_output(_SCREAMING_SNAKE_CASE   ,  _SCREAMING_SNAKE_CASE   ,  _SCREAMING_SNAKE_CASE		):
       UpperCAmelCase			:      Union[str, Any]			=			model_class(_SCREAMING_SNAKE_CASE		)

       UpperCAmelCase			:      str			=			model(**self._prepare_for_class(_SCREAMING_SNAKE_CASE   ,  _SCREAMING_SNAKE_CASE		)   ,  training=_SCREAMING_SNAKE_CASE		)
       UpperCAmelCase			:      Optional[Any]			=			outputs.encoder_hidden_states if config.is_encoder_decoder else outputs.hidden_states

       UpperCAmelCase			:      str			=			getattr(
           self.model_tester   ,  """expected_num_hidden_layers"""   ,  self.model_tester.num_hidden_layers + 1		)
       self.assertEqual(len(_SCREAMING_SNAKE_CASE		)   ,  _SCREAMING_SNAKE_CASE		)

       if hasattr(self.model_tester   ,  """encoder_seq_length"""		):
         UpperCAmelCase			:      Any			=			self.model_tester.encoder_seq_length
         if hasattr(self.model_tester   ,  """chunk_length"""		) and self.model_tester.chunk_length > 1:
           UpperCAmelCase			:      Dict			=			seq_length * self.model_tester.chunk_length
       else:
         UpperCAmelCase			:      Any			=			self.model_tester.seq_length

       self.assertListEqual(
           list(hidden_states[-1].shape[-2:]		)   ,  [seq_length, self.model_tester.hidden_size]   ,  )

       if config.is_encoder_decoder:
         UpperCAmelCase			:      int			=			outputs.decoder_hidden_states

         self.asseretIsInstance(_SCREAMING_SNAKE_CASE   ,  (list, tuple)		)
         self.assertEqual(len(_SCREAMING_SNAKE_CASE		)   ,  _SCREAMING_SNAKE_CASE		)
         UpperCAmelCase			:      List[Any]			=			getattr(self.model_tester   ,  """seq_length"""   ,  _SCREAMING_SNAKE_CASE		)
         UpperCAmelCase			:      List[str]			=			getattr(self.model_tester   ,  """decoder_seq_length"""   ,  _SCREAMING_SNAKE_CASE		)

         self.assertListEqual(
             list(hidden_states[-1].shape[-2:]		)   ,  [decoder_seq_length, self.model_tester.hidden_size]   ,  )

     UpperCAmelCase			:      Optional[int]			=			self.model_tester.prepare_config_and_inputs_for_common()

     for model_class in self.all_model_classes:
       UpperCAmelCase			:      Any			=			True
       check_hidden_states_output(_SCREAMING_SNAKE_CASE   ,  _SCREAMING_SNAKE_CASE   ,  _SCREAMING_SNAKE_CASE		)

       # check that output_hidden_states also work using config
       del inputs_dict["output_hidden_states"]
       UpperCAmelCase			:      int			=			True

       check_hidden_states_output(_SCREAMING_SNAKE_CASE   ,  _SCREAMING_SNAKE_CASE   ,  _SCREAMING_SNAKE_CASE		)

   def 			SCREAMING_SNAKE_CASE  (     self   ,  _SCREAMING_SNAKE_CASE   ,  _SCREAMING_SNAKE_CASE   ,  _SCREAMING_SNAKE_CASE=False		)						->   Tuple:





     '''simple docstring'''




     UpperCAmelCase			:      Any			=			super()._prepare_for_class(_SCREAMING_SNAKE_CASE   ,  _SCREAMING_SNAKE_CASE   ,  return_labels=_SCREAMING_SNAKE_CASE		)

     if return_labels:
       if model_class.__name__ == "TFEfficientFormerForImageClassificationWithTeacher":
         del inputs_dict["labels"]

     return inputs_dict

   def 			SCREAMING_SNAKE_CASE  (     self		)						->   str:





     '''simple docstring'''




     UpperCAmelCase			:      Dict			=			self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_model(*_SCREAMING_SNAKE_CASE		)

   @unittest.skip(reason="""EfficientFormer does not implement masked image modeling yet"""		)
   def 			SCREAMING_SNAKE_CASE  (     self		)						->   Tuple:





     '''simple docstring'''




     UpperCAmelCase			:      Tuple			=			self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_for_masked_image_modeling(*_SCREAMING_SNAKE_CASE		)

   def 			SCREAMING_SNAKE_CASE  (     self		)						->   Union[str, Any]:





     '''simple docstring'''




     UpperCAmelCase			:      Tuple			=			self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_for_image_classification(*_SCREAMING_SNAKE_CASE		)

   @slow
   def 			SCREAMING_SNAKE_CASE  (     self		)						->   Optional[Any]:





     '''simple docstring'''




     for model_name in TF_EFFICIENTFORMER_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
       UpperCAmelCase			:      int			=			TFEfficientFormerModel.from_pretrained(_SCREAMING_SNAKE_CASE		)
       self.assertIsNotNone(_SCREAMING_SNAKE_CASE		)

   def 			SCREAMING_SNAKE_CASE  (     self		)						->   List[str]:





     '''simple docstring'''




     UpperCAmelCase			:      List[str]			=			self.model_tester.prepare_config_and_inputs_for_common()
     UpperCAmelCase			:      Optional[Any]			=			True

     UpperCAmelCase			:      Tuple			=			getattr(self.model_tester   ,  """seq_length"""   ,  _SCREAMING_SNAKE_CASE		)
     UpperCAmelCase			:      Any			=			getattr(self.model_tester   ,  """encoder_seq_length"""   ,  _SCREAMING_SNAKE_CASE		)
     UpperCAmelCase			:      int			=			getattr(self.model_tester   ,  """key_length"""   ,  _SCREAMING_SNAKE_CASE		)
     UpperCAmelCase			:      Optional[int]			=			getattr(self.model_tester   ,  """chunk_length"""   ,  _SCREAMING_SNAKE_CASE		)

     if chunk_length is not None and hasattr(self.model_tester   ,  """num_hashes"""		):
       UpperCAmelCase			:      int			=			encoder_seq_length * self.model_tester.num_hashes

     for model_class in self.all_model_classes:
       UpperCAmelCase			:      List[Any]			=			True
       UpperCAmelCase			:      int			=			False
       UpperCAmelCase			:      Any			=			True
       UpperCAmelCase			:      List[str]			=			model_class(_SCREAMING_SNAKE_CASE		)

       UpperCAmelCase			:      Optional[int]			=			model(**self._prepare_for_class(_SCREAMING_SNAKE_CASE   ,  _SCREAMING_SNAKE_CASE		)   ,  training=_SCREAMING_SNAKE_CASE		)
       UpperCAmelCase			:      str			=			outputs.encoder_attentions if config.is_encoder_decoder else outputs.attentions
       self.assertEqual(len(_SCREAMING_SNAKE_CASE		)   ,  self.model_tester.num_attention_outputs		)

       # check that output_attentions also work using config
       del inputs_dict["output_attentions"]
       UpperCAmelCase			:      Optional[Any]			=			True
       UpperCAmelCase			:      List[Any]			=			model_class(_SCREAMING_SNAKE_CASE		)
       UpperCAmelCase			:      Optional[int]			=			model(**self._prepare_for_class(_SCREAMING_SNAKE_CASE   ,  _SCREAMING_SNAKE_CASE		)   ,  training=_SCREAMING_SNAKE_CASE		)

       UpperCAmelCase			:      List[str]			=			outputs.encoder_attentions if config.is_encoder_decoder else outputs.attentions
       self.assertEqual(len(_SCREAMING_SNAKE_CASE		)   ,  self.model_tester.num_attention_outputs		)

       if chunk_length is not None:
         self.assertListEqual(
             list(attentions[0].shape[-4:]		)   ,  [self.model_tester.num_attention_heads, encoder_seq_length, chunk_length, encoder_key_length]   ,  )
       else:
         self.assertListEqual(
             list(attentions[0].shape[-3:]		)   ,  [self.model_tester.num_attention_heads, encoder_seq_length, encoder_key_length]   ,  )




   def 			SCREAMING_SNAKE_CASE  (     self		)						->   List[Any]:





     '''simple docstring'''




     UpperCAmelCase			:      List[str]			=			self.model_tester.prepare_config_and_inputs_for_common()

     for model_class in self.all_model_classes:
       # Prepare our model
       UpperCAmelCase			:      Union[str, Any]			=			model_class(_SCREAMING_SNAKE_CASE		)
       # These are maximally general inputs for the model, with multiple None dimensions
       # Hopefully this will catch any conditionals that fail for flexible shapes
       UpperCAmelCase			:      Optional[int]			=			{
           key: tf.keras.Input(shape=val.shape[1:]   ,  dtype=val.dtype   ,  name=_SCREAMING_SNAKE_CASE		)
           for key, val in model.input_signature.items()
           if key in model.dummy_inputs
       }
       UpperCAmelCase			:      List[str]			=			model(_SCREAMING_SNAKE_CASE		)
       self.assertTrue(outputs_dict is not None		)

def    _snake_case		(		):
  UpperCAmelCase			:      Optional[int]			=			Image.open("""./tests/fixtures/tests_samples/COCO/000000039769.png"""		)
  return image



@require_tf
@require_vision
class    SCREAMING_SNAKE_CASE__						(      unittest.TestCase				):

   @cached_property
   def 			SCREAMING_SNAKE_CASE  (     self		)						->   Dict:





     '''simple docstring'''




     return (
         EfficientFormerImageProcessor.from_pretrained("""snap-research/efficientformer-l1-300"""		)
         if is_vision_available()
         else None
     )

   @slow
   def 			SCREAMING_SNAKE_CASE  (     self		)						->   Any:





     '''simple docstring'''




     UpperCAmelCase			:      List[str]			=			TFEfficientFormerForImageClassification.from_pretrained("""snap-research/efficientformer-l1-300"""		)
     UpperCAmelCase			:      Tuple			=			self.default_image_processor
     UpperCAmelCase			:      Any			=			prepare_img()
     UpperCAmelCase			:      Any			=			image_processor(images=_SCREAMING_SNAKE_CASE   ,  return_tensors="""tf"""		)
     # forward pass
     UpperCAmelCase			:      Any			=			model(**_SCREAMING_SNAKE_CASE   ,  training=_SCREAMING_SNAKE_CASE		)
     # verify the logits
     UpperCAmelCase			:      Any			=			tf.TensorShape((1, 1000)		)
     self.assertEqual(outputs.logits.shape   ,  _SCREAMING_SNAKE_CASE		)
     UpperCAmelCase			:      int			=			tf.constant([-0.0555, 0.4825, -0.0852]		)
     self.assertTrue(np.allclose(outputs.logits[0, :3]   ,  _SCREAMING_SNAKE_CASE   ,  atol=1E-4		)		)




   @slow
   def 			SCREAMING_SNAKE_CASE  (     self		)						->   Any:





     '''simple docstring'''




     UpperCAmelCase			:      str			=			TFEfficientFormerForImageClassificationWithTeacher.from_pretrained(
         """snap-research/efficientformer-l1-300"""		)
     UpperCAmelCase			:      Optional[int]			=			self.default_image_processor
     UpperCAmelCase			:      Dict			=			prepare_img()
     UpperCAmelCase			:      Any			=			image_processor(images=_SCREAMING_SNAKE_CASE   ,  return_tensors="""tf"""		)
     # forward pass
     UpperCAmelCase			:      List[Any]			=			model(**_SCREAMING_SNAKE_CASE   ,  training=_SCREAMING_SNAKE_CASE		)
     # verify the logits
     UpperCAmelCase			:      Dict			=			tf.TensorShape((1, 1000)		)
     self.assertEqual(outputs.logits.shape   ,  _SCREAMING_SNAKE_CASE		)
     UpperCAmelCase			:      Dict			=			tf.constant([-0.1312, 0.4353, -1.0499]		)
     self.assertTrue(np.allclose(outputs.logits[0, :3]   ,  _SCREAMING_SNAKE_CASE   ,  atol=1E-4		)		)





"""simple docstring"""
import os

import pytest
import yaml

from datasets.features.features import Features, Value
from datasets.info import DatasetInfo, DatasetInfosDict

@pytest.mark.parametrize(
    """files"""    ,	[
        ["""full:README.md""", """dataset_infos.json"""],
        ["""empty:README.md""", """dataset_infos.json"""],
        ["""dataset_infos.json"""],
        ["""full:README.md"""],
    ]    ,	)
def    _snake_case		(		UpperCamelCase		:	str    ,	UpperCamelCase		:	Optional[Any]		):
 UpperCAmelCase			:      List[Any]			=			tmp_path_factory.mktemp("""dset_infos_dir"""		)
 if "full:README.md" in files:
  with open(dataset_infos_dir / """README.md"""    ,	"""w"""		) as f:
   f.write("""---\ndataset_info:\n  dataset_size: 42\n---"""		)
 if "empty:README.md" in files:
  with open(dataset_infos_dir / """README.md"""    ,	"""w"""		) as f:
   f.write(""""""		)
    # we want to support dataset_infos.json for backward compatibility
 if "dataset_infos.json" in files:
  with open(dataset_infos_dir / """dataset_infos.json"""    ,	"""w"""		) as f:
   f.write("""{\"default\": {\"dataset_size\": 42}}"""		)
 UpperCAmelCase			:      str			=			DatasetInfosDict.from_directory(UpperCamelCase		)
 assert dataset_infos
 assert dataset_infos["default"].dataset_size == 42

@pytest.mark.parametrize(
    """dataset_info"""    ,	[
        DatasetInfo(),
        DatasetInfo(
            description="""foo"""    ,	features=Features({"""a""": Value("""int32"""		)}		)    ,	builder_name="""builder"""    ,	config_name="""config"""    ,	version="""1.0.0"""    ,	splits=[{"""name""": """train"""}]    ,	download_size=42    ,	),
    ]    ,	)
def    _snake_case		(		UpperCamelCase		:	str    ,	UpperCamelCase		:	DatasetInfo		):
 UpperCAmelCase			:      List[Any]			=			str(UpperCamelCase		)
 dataset_info.write_to_directory(UpperCamelCase		)
 UpperCAmelCase			:      List[str]			=			DatasetInfo.from_directory(UpperCamelCase		)
 assert dataset_info == reloaded
 assert os.path.exists(os.path.join(UpperCamelCase    ,	"""dataset_info.json"""		)		)

def    _snake_case		(		):
 UpperCAmelCase			:      List[str]			=			DatasetInfo(
     description="""foo"""    ,	citation="""bar"""    ,	homepage="""https://foo.bar"""    ,	license="""CC0"""    ,	features=Features({"""a""": Value("""int32"""		)}		)    ,	post_processed={}    ,	supervised_keys=()    ,	task_templates=[]    ,	builder_name="""builder"""    ,	config_name="""config"""    ,	version="""1.0.0"""    ,	splits=[{"""name""": """train""", """num_examples""": 42}]    ,	download_checksums={}    ,	download_size=1337    ,	post_processing_size=442    ,	dataset_size=1234    ,	size_in_bytes=1337 + 442 + 1234    ,	)
 UpperCAmelCase			:      str			=			dataset_info._to_yaml_dict()
 assert sorted(UpperCamelCase		) == sorted(DatasetInfo._INCLUDED_INFO_IN_YAML		)
 for key in DatasetInfo._INCLUDED_INFO_IN_YAML:
  assert key in dataset_info_yaml_dict
  assert isinstance(dataset_info_yaml_dict[key]    ,	(list, dict, int, str)		)
 UpperCAmelCase			:      Union[str, Any]			=			yaml.safe_dump(UpperCamelCase		)
 UpperCAmelCase			:      List[str]			=			yaml.safe_load(UpperCamelCase		)
 assert dataset_info_yaml_dict == reloaded

def    _snake_case		(		):
 UpperCAmelCase			:      List[str]			=			DatasetInfo()
 UpperCAmelCase			:      Union[str, Any]			=			dataset_info._to_yaml_dict()
 assert dataset_info_yaml_dict == {}

@pytest.mark.parametrize(
    """dataset_infos_dict"""    ,	[
        DatasetInfosDict(),
        DatasetInfosDict({"""default""": DatasetInfo()}		),
        DatasetInfosDict({"""my_config_name""": DatasetInfo()}		),
        DatasetInfosDict(
            {
                """default""": DatasetInfo(
                    description="""foo"""    ,	features=Features({"""a""": Value("""int32"""		)}		)    ,	builder_name="""builder"""    ,	config_name="""config"""    ,	version="""1.0.0"""    ,	splits=[{"""name""": """train"""}]    ,	download_size=42    ,	)
            }		),
        DatasetInfosDict(
            {
                """v1""": DatasetInfo(dataset_size=42		),
                """v2""": DatasetInfo(dataset_size=1337		),
            }		),
    ]    ,	)
def    _snake_case		(		UpperCamelCase		:	Optional[int]    ,	UpperCamelCase		:	DatasetInfosDict		):
 UpperCAmelCase			:      List[str]			=			str(UpperCamelCase		)
 dataset_infos_dict.write_to_directory(UpperCamelCase		)
 UpperCAmelCase			:      List[Any]			=			DatasetInfosDict.from_directory(UpperCamelCase		)

 # the config_name of the dataset_infos_dict take over the attribute
 for config_name, dataset_info in dataset_infos_dict.items():
  UpperCAmelCase			:      Union[str, Any]			=			config_name
  # the yaml representation doesn't include fields like description or citation
  # so we just test that we can recover what we can from the yaml
  UpperCAmelCase			:      Optional[Any]			=			DatasetInfo._from_yaml_dict(dataset_info._to_yaml_dict()		)
 assert dataset_infos_dict == reloaded

 if dataset_infos_dict:
  assert os.path.exists(os.path.join(UpperCamelCase    ,	"""README.md"""		)		)
