



'''simple docstring'''

import doctest
import logging
import os
import unittest
from pathlib import Path
from typing import List, Union

import transformers
from transformers.testing_utils import require_tf, require_torch, slow


a							   =				logging.getLogger()






@unittest.skip("""Temporarily disable the doc tests."""    )
@require_torch
@require_tf
@slow
class 						a_		(     unittest.TestCase    ):


							def    UpperCamelCase     (				self   :						str      ,						a_   :						Path      ,						a_   :						Union[str, None] = None      ,						a_   :						Union[List[str], None] = None      ,						a_   :						Union[str, List[str], None] = None      ,						a_   :						bool = True      ,						)			->					Optional[int]:
										snake_case:    str      							=[file for file in os.listdir(A_			) if os.path.isfile(os.path.join(A_      ,						A_			)			)]

										if identifier is not None:
													snake_case:    Tuple      							=[file for file in files if identifier in file]

										if n_identifier is not None:
													if isinstance(A_      ,						A_			):
																for n_ in n_identifier:
																			snake_case:    Union[str, Any]      							=[file for file in files if n_ not in file]
													else:
																snake_case:    Any      							=[file for file in files if n_identifier not in file]

										snake_case:    str      							=ignore_files or []
										ignore_files.append('__init__.py'			)
										snake_case:    Union[str, Any]      							=[file for file in files if file not in ignore_files]

										for file in files:
													# Open all files
													print('Testing'      ,						A_			)

													if only_modules:
																snake_case:    Dict      							=file.split('.'			)[0]
																try:
																			snake_case:    List[Any]      							=getattr(A_      ,						A_			)
																			snake_case:    List[str]      							=doctest.DocTestSuite(A_			)
																			snake_case:    Optional[int]      							=unittest.TextTestRunner().run(A_			)
																			self.assertIs(len(result.failures			)      ,						0			)
																except AttributeError:
																			logger.info(F'''{module_identifier} is not a module.'''			)
													else:
																snake_case:    List[str]      							=doctest.testfile(str('..' / directory / file			)      ,						optionflags=doctest.ELLIPSIS			)
																self.assertIs(result.failed      ,						0			)


							def    UpperCamelCase     (				self   :						Any			)			->					List[str]:
										snake_case:    Any      							=Path('src/transformers'			)
										snake_case:    Optional[Any]      							='modeling'
										snake_case:    Dict      							=[
										    'modeling_ctrl.py',
										    'modeling_tf_ctrl.py',
										]
										self.analyze_directory(A_      ,						identifier=A_      ,						ignore_files=A_			)


							def    UpperCamelCase     (				self   :						Tuple			)			->					Union[str, Any]:
										snake_case:    List[str]      							=Path('src/transformers'			)
										snake_case:    Union[str, Any]      							='tokenization'
										self.analyze_directory(A_      ,						identifier=A_			)


							def    UpperCamelCase     (				self   :						Dict			)			->					Union[str, Any]:
										snake_case:    Dict      							=Path('src/transformers'			)
										snake_case:    List[str]      							='configuration'
										self.analyze_directory(A_      ,						identifier=A_			)


							def    UpperCamelCase     (				self   :						str			)			->					Tuple:
										snake_case:    Optional[int]      							=Path('src/transformers'			)
										snake_case:    str      							=['configuration', 'modeling', 'tokenization']
										self.analyze_directory(A_      ,						n_identifier=A_			)




							def    UpperCamelCase     (				self   :						Tuple			)			->					Optional[int]:
										snake_case:    Dict      							=Path('docs/source'			)
										snake_case:    int      							=['favicon.ico']
										self.analyze_directory(A_      ,						ignore_files=A_      ,						only_modules=A_			)








"""simple docstring"""




import json
import os
import tempfile

from transformers.testing_utils import check_json_file_has_correct_format




class 			__snake_case   :
							__a					 =       None




							def   __a   (     self:    int   ):
										__lowerCamelCase          =      self.feature_extraction_class(**self.feat_extract_dict   )
										__lowerCamelCase          =      json.loads(feat_extract.to_json_string()   )
										for key, value in self.feat_extract_dict.items():
													self.assertEqual(obj[key]     ,							A_   )




							def   __a   (     self:    List[str]   ):
										__lowerCamelCase          =      self.feature_extraction_class(**self.feat_extract_dict   )

										with tempfile.TemporaryDirectory() as tmpdirname:
													__lowerCamelCase          =      os.path.join(A_     ,							"""feat_extract.json"""   )
													feat_extract_first.to_json_file(A_   )
													__lowerCamelCase          =      self.feature_extraction_class.from_json_file(A_   )

										self.assertEqual(feat_extract_second.to_dict()     ,							feat_extract_first.to_dict()   )




							def   __a   (     self:    Optional[Any]   ):
										__lowerCamelCase          =      self.feature_extraction_class(**self.feat_extract_dict   )

										with tempfile.TemporaryDirectory() as tmpdirname:
													__lowerCamelCase          =      feat_extract_first.save_pretrained(A_   )[0]
													check_json_file_has_correct_format(A_   )
													__lowerCamelCase          =      self.feature_extraction_class.from_pretrained(A_   )

										self.assertEqual(feat_extract_second.to_dict()     ,							feat_extract_first.to_dict()   )




							def   __a   (     self:    List[Any]   ):
										__lowerCamelCase          =      self.feature_extraction_class()
										self.assertIsNotNone(A_   )




