






"""simple docstring"""
import unittest

from transformers import AutoConfig, AutoTokenizer, BertConfig, TensorType, is_flax_available
from transformers.testing_utils import DUMMY_UNKNOWN_IDENTIFIER, require_flax, slow


if is_flax_available():
				import jax

				from transformers.models.auto.modeling_flax_auto import FlaxAutoModel
				from transformers.models.bert.modeling_flax_bert import FlaxBertModel
				from transformers.models.roberta.modeling_flax_roberta import FlaxRobertaModel







@require_flax
class     UpperCamelCase_ (unittest.TestCase  ):





	@slow
	def   _SCREAMING_SNAKE_CASE   (   self      :				List[str]		)		->    List[Any]:
				for model_name in ["bert-base-cased", "bert-large-uncased"]:
							with self.subTest(lowerCAmelCase_		):
										UpperCAmelCase_  :				Dict      =      AutoConfig.from_pretrained(lowerCAmelCase_		)
										self.assertIsNotNone(lowerCAmelCase_		)
										self.assertIsInstance(lowerCAmelCase_			,			lowerCAmelCase_		)

										UpperCAmelCase_  :				Any      =      FlaxAutoModel.from_pretrained(lowerCAmelCase_		)
										self.assertIsNotNone(lowerCAmelCase_		)
										self.assertIsInstance(lowerCAmelCase_			,			lowerCAmelCase_		)





	@slow
	def   _SCREAMING_SNAKE_CASE   (   self      :				Union[str, Any]		)		->    int:
				for model_name in ["roberta-base", "roberta-large"]:
							with self.subTest(lowerCAmelCase_		):
										UpperCAmelCase_  :				List[Any]      =      AutoConfig.from_pretrained(lowerCAmelCase_		)
										self.assertIsNotNone(lowerCAmelCase_		)
										self.assertIsInstance(lowerCAmelCase_			,			lowerCAmelCase_		)

										UpperCAmelCase_  :				List[Any]      =      FlaxAutoModel.from_pretrained(lowerCAmelCase_		)
										self.assertIsNotNone(lowerCAmelCase_		)
										self.assertIsInstance(lowerCAmelCase_			,			lowerCAmelCase_		)





	@slow
	def   _SCREAMING_SNAKE_CASE   (   self      :				Tuple		)		->    Dict:
				for model_name in ["bert-base-cased", "bert-large-uncased"]:
							UpperCAmelCase_  :				Any      =      AutoTokenizer.from_pretrained(lowerCAmelCase_		)
							UpperCAmelCase_  :				List[str]      =      FlaxBertModel.from_pretrained(lowerCAmelCase_		)
							UpperCAmelCase_  :				int      =      tokenizer("Do you support jax jitted function?"			,			return_tensors=TensorType.JAX		)

							@jax.jit
							def eval(**lowerCAmelCase_      :				List[Any]		):
										return model(**lowerCAmelCase_		)

							eval(**lowerCAmelCase_		).block_until_ready()





	@slow
	def   _SCREAMING_SNAKE_CASE   (   self      :				List[str]		)		->    Optional[int]:
				for model_name in ["roberta-base", "roberta-large"]:
							UpperCAmelCase_  :				Tuple      =      AutoTokenizer.from_pretrained(lowerCAmelCase_		)
							UpperCAmelCase_  :				Optional[int]      =      FlaxRobertaModel.from_pretrained(lowerCAmelCase_		)
							UpperCAmelCase_  :				List[Any]      =      tokenizer("Do you support jax jitted function?"			,			return_tensors=TensorType.JAX		)

							@jax.jit
							def eval(**lowerCAmelCase_      :				Dict		):
										return model(**lowerCAmelCase_		)

							eval(**lowerCAmelCase_		).block_until_ready()





	def   _SCREAMING_SNAKE_CASE   (   self      :				str		)		->    Tuple:
				with self.assertRaisesRegex(
				    lowerCAmelCase_			,			"bert-base is not a local folder and is not a valid model identifier"		):
							UpperCAmelCase_  :				Optional[int]      =      FlaxAutoModel.from_pretrained("bert-base"		)





	def   _SCREAMING_SNAKE_CASE   (   self      :				int		)		->    Any:
				with self.assertRaisesRegex(
				    lowerCAmelCase_			,			R"aaaaaa is not a valid git identifier \(branch name, tag name or commit id\)"		):
							UpperCAmelCase_  :				Dict      =      FlaxAutoModel.from_pretrained(lowerCAmelCase_			,			revision="aaaaaa"		)





	def   _SCREAMING_SNAKE_CASE   (   self      :				Union[str, Any]		)		->    Union[str, Any]:
				with self.assertRaisesRegex(
				    lowerCAmelCase_			,			"hf-internal-testing/config-no-model does not appear to have a file named flax_model.msgpack"			,			):
							UpperCAmelCase_  :				str      =      FlaxAutoModel.from_pretrained("hf-internal-testing/config-no-model"		)





	def   _SCREAMING_SNAKE_CASE   (   self      :				Any		)		->    Optional[int]:
				with self.assertRaisesRegex(lowerCAmelCase_			,			"Use `from_pt=True` to load this model"		):
							UpperCAmelCase_  :				Union[str, Any]      =      FlaxAutoModel.from_pretrained("hf-internal-testing/tiny-bert-pt-only"		)











"""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


lowerCamelCase_       			=   logging.getLogger()







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





	def   _SCREAMING_SNAKE_CASE   (   self      :				Union[str, Any]			,			lowerCAmelCase_      :				Path			,			lowerCAmelCase_      :				Union[str, None] = None			,			lowerCAmelCase_      :				Union[List[str], None] = None			,			lowerCAmelCase_      :				Union[str, List[str], None] = None			,			lowerCAmelCase_      :				bool = True			,			)		->    Tuple:
				UpperCAmelCase_  :				Optional[Any]      =      [file for file in os.listdir(lowerCAmelCase_		) if os.path.isfile(os.path.join(lowerCAmelCase_			,			lowerCAmelCase_		)		)]

				if identifier is not None:
							UpperCAmelCase_  :				Optional[int]      =      [file for file in files if identifier in file]

				if n_identifier is not None:
							if isinstance(lowerCAmelCase_			,			lowerCAmelCase_		):
										for n_ in n_identifier:
													UpperCAmelCase_  :				List[Any]      =      [file for file in files if n_ not in file]
							else:
										UpperCAmelCase_  :				Optional[Any]      =      [file for file in files if n_identifier not in file]

				UpperCAmelCase_  :				List[Any]      =      ignore_files or []
				ignore_files.append("__init__.py"		)
				UpperCAmelCase_  :				Optional[Any]      =      [file for file in files if file not in ignore_files]

				for file in files:
							# Open all files
							print("Testing"			,			lowerCAmelCase_		)

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





	def   _SCREAMING_SNAKE_CASE   (   self      :				Optional[int]		)		->    List[Any]:
				UpperCAmelCase_  :				Optional[int]      =      Path("src/transformers"		)
				UpperCAmelCase_  :				List[Any]      =      "modeling"
				UpperCAmelCase_  :				Tuple      =      [
				    "modeling_ctrl.py",
				    "modeling_tf_ctrl.py",
				]
				self.analyze_directory(lowerCAmelCase_			,			identifier=lowerCAmelCase_			,			ignore_files=lowerCAmelCase_		)





	def   _SCREAMING_SNAKE_CASE   (   self      :				Union[str, Any]		)		->    List[Any]:
				UpperCAmelCase_  :				List[str]      =      Path("src/transformers"		)
				UpperCAmelCase_  :				int      =      "tokenization"
				self.analyze_directory(lowerCAmelCase_			,			identifier=lowerCAmelCase_		)





	def   _SCREAMING_SNAKE_CASE   (   self      :				Optional[Any]		)		->    Optional[Any]:
				UpperCAmelCase_  :				int      =      Path("src/transformers"		)
				UpperCAmelCase_  :				Any      =      "configuration"
				self.analyze_directory(lowerCAmelCase_			,			identifier=lowerCAmelCase_		)





	def   _SCREAMING_SNAKE_CASE   (   self      :				Any		)		->    Any:
				UpperCAmelCase_  :				int      =      Path("src/transformers"		)
				UpperCAmelCase_  :				List[Any]      =      ["configuration", "modeling", "tokenization"]
				self.analyze_directory(lowerCAmelCase_			,			n_identifier=lowerCAmelCase_		)





	def   _SCREAMING_SNAKE_CASE   (   self      :				List[str]		)		->    Dict:
				UpperCAmelCase_  :				List[str]      =      Path("docs/source"		)
				UpperCAmelCase_  :				int      =      ["favicon.ico"]
				self.analyze_directory(lowerCAmelCase_			,			ignore_files=lowerCAmelCase_			,			only_modules=lowerCAmelCase_		)



