
import re
import tempfile
import unittest
from pathlib import Path

from datasets.utils.metadata import DatasetMetadata
def     UpperCAmelCase__							(       __magic_name__						:     str  ):


					'''simple docstring'''

					lowerCAmelCase		:					List[Any]  	=     min(re.search('''^ +'''							,  __magic_name__  ).end() if t.startswith(''' '''  ) else 0 for t in string.splitlines()  )
					return "\n".join([line[indent_level:] for line in string.splitlines() if indent_level < len(__magic_name__  )]  )


__SCREAMING_SNAKE_CASE			:   Any         =     '\\n---\nlanguage:\n- zh\n- en\ntask_ids:\n- sentiment-classification\n---\n# Begin of markdown\n\nSome cool dataset card\n'

__SCREAMING_SNAKE_CASE			:   str         =     '\\n---\n---\n# Begin of markdown\n\nSome cool dataset card\n'


__SCREAMING_SNAKE_CASE			:   Optional[Any]         =     '\\n# Begin of markdown\n\nSome cool dataset card\n'


class 		__magic_name__   (						unittest.TestCase    ):





		def       _A							(							self    :	List[Any]				):
							with tempfile.TemporaryDirectory() as tmp_dir:
												lowerCAmelCase		:					Optional[Any]  	=     Path(lowerCamelCase__				) / '''README.md'''
												with open(lowerCamelCase__						,  '''w+'''				) as readme_file:
																	readme_file.write(lowerCamelCase__				)
												lowerCAmelCase		:					Dict  	=     DatasetMetadata.from_readme(lowerCamelCase__				)
												self.assertDictEqual(lowerCamelCase__						,  {'''language''': ['''zh''', '''en'''], '''task_ids''': ['''sentiment-classification''']}				)

												with open(lowerCamelCase__						,  '''w+'''				) as readme_file:
																	readme_file.write(lowerCamelCase__				)
												lowerCAmelCase		:					Union[str, Any]  	=     DatasetMetadata.from_readme(lowerCamelCase__				)
												self.assertDictEqual(lowerCamelCase__						,  {}				)

												with open(lowerCamelCase__						,  '''w+'''				) as readme_file:
																	readme_file.write(lowerCamelCase__				)
												lowerCAmelCase		:					Union[str, Any]  	=     DatasetMetadata.from_readme(lowerCamelCase__				)
												self.assertEqual(lowerCamelCase__						,  {}				)





		def       _A							(							self    :	List[Any]				):
							lowerCAmelCase		:					List[Any]  	=     _dedent(
							    '''\
            annotations_creators:
            - found
            language_creators:
            - found
            language:
            - en
            license:
            - unknown
            multilinguality:
            - monolingual
            pretty_name: Test Dataset
            size_categories:
            - 10K<n<100K
            source_datasets:
            - extended|other-yahoo-webscope-l6
            task_categories:
            - question-answering
            task_ids:
            - open-domain-qa
            '''				)
							assert DatasetMetadata.from_yaml_string(lowerCamelCase__				)

							lowerCAmelCase		:					Any  	=     _dedent(
							    '''\
            annotations_creators:
            - found
            language:
            - en
            license:
            - unknown
            multilinguality:
            - monolingual
            pretty_name: Test Dataset
            size_categories:
            - 10K<n<100K
            source_datasets:
            - extended|other-yahoo-webscope-l6
            task_categories:
            - question-answering
            task_ids:
            - open-domain-qa
            task_ids:
            - open-domain-qa
            '''				)
							with self.assertRaises(lowerCamelCase__				):
												DatasetMetadata.from_yaml_string(lowerCamelCase__				)

							lowerCAmelCase		:					Optional[Any]  	=     _dedent(
							    '''\
            annotations_creators:
            - found
            language_creators:
            - found
            language:
            - en
            license:
            - unknown
            multilinguality:
            - monolingual
            pretty_name: Test Dataset
            size_categories:
            - 10K<n<100K
            source_datasets:
            - extended|other-yahoo-webscope-l6
            task_categories:
            - text-classification
            task_ids:
            - multi-class-classification
            paperswithcode_id:
            - squad
            configs:
            - en
            train-eval-index:
            - config: en
              task: text-classification
              task_id: multi_class_classification
              splits:
                train_split: train
                eval_split: test
              col_mapping:
                text: text
                label: target
              metrics:
                - type: accuracy
                  name: Accuracy
            extra_gated_prompt: |
              By clicking on “Access repository” below, you also agree to ImageNet Terms of Access:
              [RESEARCHER_FULLNAME] (the "Researcher") has requested permission to use the ImageNet database (the "Database") at Princeton University and Stanford University. In exchange for such permission, Researcher hereby agrees to the following terms and conditions:
              1. Researcher shall use the Database only for non-commercial research and educational purposes.
            extra_gated_fields:
              Company: text
              Country: text
              I agree to use this model for non-commerical use ONLY: checkbox
            '''				)
							assert DatasetMetadata.from_yaml_string(lowerCamelCase__				)


import json
import os
import tempfile
import unittest

from transformers.modelcard import ModelCard


class 		__magic_name__   (						unittest.TestCase    ):





		def       _A							(							self    :	Dict				):
							lowerCAmelCase		:					List[Any]  	=     {
							    '''model_details''': {
							        '''Organization''': '''testing''',
							        '''Model date''': '''today''',
							        '''Model version''': '''v2.1, Developed by Test Corp in 2019.''',
							        '''Architecture''': '''Convolutional Neural Network.''',
							    },
							    '''metrics''': '''BLEU and ROUGE-1''',
							    '''evaluation_data''': {
							        '''Datasets''': {'''BLEU''': '''My-great-dataset-v1''', '''ROUGE-1''': '''My-short-dataset-v2.1'''},
							        '''Preprocessing''': '''See details on https://arxiv.org/pdf/1810.03993.pdf''',
							    },
							    '''training_data''': {
							        '''Dataset''': '''English Wikipedia dump dated 2018-12-01''',
							        '''Preprocessing''': (
							            '''Using SentencePiece vocabulary of size 52k tokens. See details on'''
							            ''' https://arxiv.org/pdf/1810.03993.pdf'''
							        ),
							    },
							    '''quantitative_analyses''': {'''BLEU''': 5_5.1, '''ROUGE-1''': 7_6},
							}





		def       _A							(							self    :	str				):
							lowerCAmelCase		:					Dict  	=     ModelCard.from_dict(self.inputs_dict				)
							self.assertTrue(hasattr(lowerCamelCase__						,  '''model_details'''				)				)
							self.assertTrue(hasattr(lowerCamelCase__						,  '''intended_use'''				)				)
							self.assertTrue(hasattr(lowerCamelCase__						,  '''factors'''				)				)
							self.assertTrue(hasattr(lowerCamelCase__						,  '''metrics'''				)				)
							self.assertTrue(hasattr(lowerCamelCase__						,  '''evaluation_data'''				)				)
							self.assertTrue(hasattr(lowerCamelCase__						,  '''training_data'''				)				)
							self.assertTrue(hasattr(lowerCamelCase__						,  '''quantitative_analyses'''				)				)
							self.assertTrue(hasattr(lowerCamelCase__						,  '''ethical_considerations'''				)				)
							self.assertTrue(hasattr(lowerCamelCase__						,  '''caveats_and_recommendations'''				)				)





		def       _A							(							self    :	Optional[Any]				):
							lowerCAmelCase		:					Tuple  	=     ModelCard.from_dict(self.inputs_dict				)
							lowerCAmelCase		:					Dict  	=     json.loads(modelcard.to_json_string()				)
							for key, value in self.inputs_dict.items():
												self.assertEqual(obj[key]						,  lowerCamelCase__				)





		def       _A							(							self    :	Tuple				):
							lowerCAmelCase		:					Tuple  	=     ModelCard.from_dict(self.inputs_dict				)

							with tempfile.TemporaryDirectory() as tmpdirname:
												lowerCAmelCase		:					str  	=     os.path.join(lowerCamelCase__						,  '''modelcard.json'''				)
												model_card_first.to_json_file(lowerCamelCase__				)
												lowerCAmelCase		:					Dict  	=     ModelCard.from_json_file(lowerCamelCase__				)

							self.assertEqual(model_card_second.to_dict()						,  model_card_first.to_dict()				)





		def       _A							(							self    :	Union[str, Any]				):
							lowerCAmelCase		:					int  	=     ModelCard.from_dict(self.inputs_dict				)

							with tempfile.TemporaryDirectory() as tmpdirname:
												model_card_first.save_pretrained(lowerCamelCase__				)
												lowerCAmelCase		:					Any  	=     ModelCard.from_pretrained(lowerCamelCase__				)

							self.assertEqual(model_card_second.to_dict()						,  model_card_first.to_dict()				)
