





import unittest
import warnings
from dataclasses import dataclass

from transformers.convert_slow_tokenizer import SpmConverter
from transformers.testing_utils import get_tests_dir

@dataclass
class      A_	:
	UpperCAmelCase__ =      42

class      A_	(unittest.TestCase      ):
	def 					_lowercase    (   self		):






				'''simple docstring'''







				UpperCAmelCase       		=    get_tests_dir('''fixtures/test_sentencepiece.model'''		)
				UpperCAmelCase       		=    get_tests_dir('''fixtures/test_sentencepiece_with_bytefallback.model'''		)

				UpperCAmelCase       		=    FakeOriginalTokenizer(vocab_file=_A		)

				with warnings.catch_warnings(record=_A		) as w:
							UpperCAmelCase       		=    SpmConverter(_A		)
				self.assertEqual(len(_A		)							, 0		)

				UpperCAmelCase       		=    FakeOriginalTokenizer(vocab_file=_A		)

				with warnings.catch_warnings(record=_A		) as w:
							UpperCAmelCase       		=    SpmConverter(_A		)
				self.assertEqual(len(_A		)							, 1		)

				self.assertIn(
				    '''The sentencepiece tokenizer that you are converting to a fast tokenizer uses the byte fallback option'''
				    ''' which is not implemented in the fast tokenizers.'''							, str(w[0].message		)							, )










import json
import os
import tempfile
import unittest

from transformers.modelcard import ModelCard

class      A_	(unittest.TestCase      ):
	def 					_lowercase    (   self		):






				'''simple docstring'''







				UpperCAmelCase       		=    {
				    '''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''': 7_6},
				}
	def 					_lowercase    (   self		):






				'''simple docstring'''







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






				'''simple docstring'''







				UpperCAmelCase       		=    ModelCard.from_dict(self.inputs_dict		)
				UpperCAmelCase       		=    json.loads(modelcard.to_json_string()		)
				for key, value in self.inputs_dict.items():
							self.assertEqual(obj[key]							, _A		)
	def 					_lowercase    (   self		):






				'''simple docstring'''







				UpperCAmelCase       		=    ModelCard.from_dict(self.inputs_dict		)

				with tempfile.TemporaryDirectory() as tmpdirname:
							UpperCAmelCase       		=    os.path.join(_A							, '''modelcard.json'''		)
							model_card_first.to_json_file(_A		)
							UpperCAmelCase       		=    ModelCard.from_json_file(_A		)

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







	def 					_lowercase    (   self		):






				'''simple docstring'''







				UpperCAmelCase       		=    ModelCard.from_dict(self.inputs_dict		)

				with tempfile.TemporaryDirectory() as tmpdirname:
							model_card_first.save_pretrained(_A		)
							UpperCAmelCase       		=    ModelCard.from_pretrained(_A		)

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



