





"""simple docstring"""





import json
import os
import tempfile
import unittest

from transformers.modelcard import ModelCard

class 		lowercase ( unittest.TestCase ):





						def    _snake_case      (	self			)		->					Optional[int]:
												lowerCAmelCase  						=	{
												    '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': 55.1, 'ROUGE-1': 76},
												}





						def    _snake_case      (	self			)		->					List[Any]:
												lowerCAmelCase  						=	ModelCard.from_dict(self.inputs_dict			)
												self.assertTrue(hasattr(lowercase_				,						"""model_details"""			)			)
												self.assertTrue(hasattr(lowercase_				,						"""intended_use"""			)			)
												self.assertTrue(hasattr(lowercase_				,						"""factors"""			)			)
												self.assertTrue(hasattr(lowercase_				,						"""metrics"""			)			)
												self.assertTrue(hasattr(lowercase_				,						"""evaluation_data"""			)			)
												self.assertTrue(hasattr(lowercase_				,						"""training_data"""			)			)
												self.assertTrue(hasattr(lowercase_				,						"""quantitative_analyses"""			)			)
												self.assertTrue(hasattr(lowercase_				,						"""ethical_considerations"""			)			)
												self.assertTrue(hasattr(lowercase_				,						"""caveats_and_recommendations"""			)			)





						def    _snake_case      (	self			)		->					Union[str, Any]:
												lowerCAmelCase  						=	ModelCard.from_dict(self.inputs_dict			)
												lowerCAmelCase  						=	json.loads(modelcard.to_json_string()			)
												for key, value in self.inputs_dict.items():
																		self.assertEqual(obj[key]				,						lowercase_			)





						def    _snake_case      (	self			)		->					int:
												lowerCAmelCase  						=	ModelCard.from_dict(self.inputs_dict			)

												with tempfile.TemporaryDirectory() as tmpdirname:
																		lowerCAmelCase  						=	os.path.join(lowercase_				,						"""modelcard.json"""			)
																		model_card_first.to_json_file(lowercase_			)
																		lowerCAmelCase  						=	ModelCard.from_json_file(lowercase_			)

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





						def    _snake_case      (	self			)		->					int:
												lowerCAmelCase  						=	ModelCard.from_dict(self.inputs_dict			)

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

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













"""simple docstring"""





import unittest
from dataclasses import dataclass
from typing import Optional

from transformers.utils import ModelOutput

@dataclass
class 		lowercase ( _UpperCAmelCase ):
      _SCREAMING_SNAKE_CASE         =				42
      _SCREAMING_SNAKE_CASE         =				None
      _SCREAMING_SNAKE_CASE         =				None







class 		lowercase ( unittest.TestCase ):





      def    _snake_case      (	self			)		->					Optional[Any]:
            lowerCAmelCase  						=	ModelOutputTest(a=30			)
            self.assertEqual(x.a				,						30			)
            self.assertIsNone(x.b			)
            self.assertIsNone(x.c			)
            with self.assertRaises(lowercase			):
                  lowerCAmelCase  						=	x.d





      def    _snake_case      (	self			)		->					Optional[Any]:
            lowerCAmelCase  						=	ModelOutputTest(a=30				,						b=10			)
            self.assertEqual(x[0]				,						30			)
            self.assertEqual(x[1]				,						10			)
            self.assertEqual(x[:2]				,						(30, 10)			)
            self.assertEqual(x[:]				,						(30, 10)			)

            lowerCAmelCase  						=	ModelOutputTest(a=30				,						c=10			)
            self.assertEqual(x[0]				,						30			)
            self.assertEqual(x[1]				,						10			)
            self.assertEqual(x[:2]				,						(30, 10)			)
            self.assertEqual(x[:]				,						(30, 10)			)





      def    _snake_case      (	self			)		->					Tuple:
            lowerCAmelCase  						=	ModelOutputTest(a=30				,						b=10			)
            self.assertEqual(x["""a"""]				,						30			)
            self.assertEqual(x["""b"""]				,						10			)
            with self.assertRaises(lowercase			):
                  lowerCAmelCase  						=	x["""c"""]

            lowerCAmelCase  						=	ModelOutputTest(a=30				,						c=10			)
            self.assertEqual(x["""a"""]				,						30			)
            self.assertEqual(x["""c"""]				,						10			)
            with self.assertRaises(lowercase			):
                  lowerCAmelCase  						=	x["""b"""]





      def    _snake_case      (	self			)		->					Union[str, Any]:
            lowerCAmelCase  						=	ModelOutputTest(a=30			)
            self.assertEqual(list(x.keys()			)				,						["""a"""]			)
            self.assertEqual(list(x.values()			)				,						[30]			)
            self.assertEqual(list(x.items()			)				,						[("""a""", 30)]			)
            self.assertEqual(list(lowercase			)				,						["""a"""]			)

            lowerCAmelCase  						=	ModelOutputTest(a=30				,						b=10			)
            self.assertEqual(list(x.keys()			)				,						["""a""", """b"""]			)
            self.assertEqual(list(x.values()			)				,						[30, 10]			)
            self.assertEqual(list(x.items()			)				,						[("""a""", 30), ("""b""", 10)]			)
            self.assertEqual(list(lowercase			)				,						["""a""", """b"""]			)

            lowerCAmelCase  						=	ModelOutputTest(a=30				,						c=10			)
            self.assertEqual(list(x.keys()			)				,						["""a""", """c"""]			)
            self.assertEqual(list(x.values()			)				,						[30, 10]			)
            self.assertEqual(list(x.items()			)				,						[("""a""", 30), ("""c""", 10)]			)
            self.assertEqual(list(lowercase			)				,						["""a""", """c"""]			)

            with self.assertRaises(lowercase			):
                  lowerCAmelCase  						=	x.update({"""d""": 20}			)
            with self.assertRaises(lowercase			):
                  del x["a"]
            with self.assertRaises(lowercase			):
                  lowerCAmelCase  						=	x.pop("""a"""			)
            with self.assertRaises(lowercase			):
                  lowerCAmelCase  						=	x.setdefault("""d"""				,						32			)





      def    _snake_case      (	self			)		->					Dict:
            lowerCAmelCase  						=	ModelOutputTest(a=30			)
            lowerCAmelCase  						=	10
            self.assertEqual(x.a				,						10			)
            self.assertEqual(x["""a"""]				,						10			)





      def    _snake_case      (	self			)		->					List[str]:
            lowerCAmelCase  						=	ModelOutputTest(a=30			)
            lowerCAmelCase  						=	10
            self.assertEqual(x.a				,						10			)
            self.assertEqual(x["""a"""]				,						10			)





      def    _snake_case      (	self			)		->					str:
            lowerCAmelCase  						=	ModelOutputTest({"""a""": 30, """b""": 10}			)
            self.assertEqual(list(x.keys()			)				,						["""a""", """b"""]			)
            self.assertEqual(x.a				,						30			)
            self.assertEqual(x.b				,						10			)





      def    _snake_case      (	self			)		->					Dict:
            lowerCAmelCase  						=	ModelOutputTest([("""a""", 30), ("""b""", 10)]			)
            self.assertEqual(list(x.keys()			)				,						["""a""", """b"""]			)
            self.assertEqual(x.a				,						30			)
            self.assertEqual(x.b				,						10			)

            with self.assertRaises(lowercase			):
                  lowerCAmelCase  						=	ModelOutputTest([("""a""", 30), (10, 10)]			)

            lowerCAmelCase  						=	ModelOutputTest(a=(30, 30)			)
            self.assertEqual(list(x.keys()			)				,						["""a"""]			)
            self.assertEqual(x.a				,						(30, 30)			)






