"""simple docstring"""


# tests directory-specific settings - this file is run automatically
# by pytest before any tests are run

import doctest
import sys
import warnings
from os.path import abspath, dirname, join

import _pytest

from transformers.testing_utils import HfDoctestModule, HfDocTestParser


# allow having multiple repository checkouts and not needing to remember to rerun
# 'pip install -e .[dev]' when switching between checkouts and running tests.
lowerCAmelCase_:					int     =					abspath(join(dirname(__file__), "src"))
sys.path.insert(1, git_repo_path)

# silence FutureWarning warnings in tests since often we can't act on them until
# they become normal warnings - i.e. the tests still need to test the current functionality
warnings.simplefilter(action="ignore", category=FutureWarning)







def 					__a   (		A      ):






     '''simple docstring'''



     config.addinivalue_line(
         "markers"    ,				"is_pt_tf_cross_test: mark test to run only when PT and TF interactions are tested"      )
     config.addinivalue_line(
         "markers"    ,				"is_pt_flax_cross_test: mark test to run only when PT and FLAX interactions are tested"      )
     config.addinivalue_line("markers"    ,				"is_pipeline_test: mark test to run only when pipelines are tested"      )
     config.addinivalue_line("markers"    ,				"is_staging_test: mark test to run only in the staging environment"      )
     config.addinivalue_line("markers"    ,				"accelerate_tests: mark test that require accelerate"      )
     config.addinivalue_line("markers"    ,				"tool_tests: mark the tool tests that are run on their specific schedule"      )







def 					__a   (		A      ):






     '''simple docstring'''



     from transformers.testing_utils import pytest_addoption_shared

     pytest_addoption_shared(A      )







def 					__a   (		A      ):






     '''simple docstring'''



     from transformers.testing_utils import pytest_terminal_summary_main

     lowercase__				 =							terminalreporter.config.getoption("--make-reports"      )
     if make_reports:
          pytest_terminal_summary_main(A    ,				id=A      )







def 					__a   (		A    ,				A      ):






     '''simple docstring'''



     if exitstatus == 5:
          lowercase__				 =							0


# Doctest custom flag to ignore output.
lowerCAmelCase_:					int     =					doctest.register_optionflag("IGNORE_RESULT")

lowerCAmelCase_:					Optional[int]     =					doctest.OutputChecker






class    a__    (   _a	):


   def 	snake_case__	(     self,				_UpperCAmelCase,				_UpperCAmelCase,				_UpperCAmelCase  ):
        '''simple docstring'''



        if IGNORE_RESULT & optionflags:
             return True
        return OutputChecker.check_output(self,				_UpperCAmelCase,				_UpperCAmelCase,				_UpperCAmelCase  )



lowerCAmelCase_:					int     =					CustomOutputChecker
lowerCAmelCase_:					Dict     =					HfDoctestModule




lowerCAmelCase_:					Any     =					HfDocTestParser





"""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    a__    (   unittest.TestCase	):


   @slow
   def 	snake_case__	(     self  ):
        '''simple docstring'''



        for model_name in ["bert-base-cased", "bert-large-uncased"]:
             with self.subTest(_UpperCAmelCase  ):
                  lowercase__				 =							AutoConfig.from_pretrained(_UpperCAmelCase  )
                  self.assertIsNotNone(_UpperCAmelCase  )
                  self.assertIsInstance(_UpperCAmelCase,				_UpperCAmelCase  )

                  lowercase__				 =							FlaxAutoModel.from_pretrained(_UpperCAmelCase  )
                  self.assertIsNotNone(_UpperCAmelCase  )
                  self.assertIsInstance(_UpperCAmelCase,				_UpperCAmelCase  )


   @slow
   def 	snake_case__	(     self  ):
        '''simple docstring'''



        for model_name in ["roberta-base", "roberta-large"]:
             with self.subTest(_UpperCAmelCase  ):
                  lowercase__				 =							AutoConfig.from_pretrained(_UpperCAmelCase  )
                  self.assertIsNotNone(_UpperCAmelCase  )
                  self.assertIsInstance(_UpperCAmelCase,				_UpperCAmelCase  )

                  lowercase__				 =							FlaxAutoModel.from_pretrained(_UpperCAmelCase  )
                  self.assertIsNotNone(_UpperCAmelCase  )
                  self.assertIsInstance(_UpperCAmelCase,				_UpperCAmelCase  )


   @slow
   def 	snake_case__	(     self  ):
        '''simple docstring'''



        for model_name in ["bert-base-cased", "bert-large-uncased"]:
             lowercase__				 =							AutoTokenizer.from_pretrained(_UpperCAmelCase  )
             lowercase__				 =							FlaxBertModel.from_pretrained(_UpperCAmelCase  )
             lowercase__				 =							tokenizer("Do you support jax jitted function?",				return_tensors=TensorType.JAX  )

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

             eval(**_UpperCAmelCase  ).block_until_ready()


   @slow
   def 	snake_case__	(     self  ):
        '''simple docstring'''



        for model_name in ["roberta-base", "roberta-large"]:
             lowercase__				 =							AutoTokenizer.from_pretrained(_UpperCAmelCase  )
             lowercase__				 =							FlaxRobertaModel.from_pretrained(_UpperCAmelCase  )
             lowercase__				 =							tokenizer("Do you support jax jitted function?",				return_tensors=TensorType.JAX  )

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

             eval(**_UpperCAmelCase  ).block_until_ready()


   def 	snake_case__	(     self  ):
        '''simple docstring'''



        with self.assertRaisesRegex(
            _UpperCAmelCase,				"bert-base is not a local folder and is not a valid model identifier"  ):
             lowercase__				 =							FlaxAutoModel.from_pretrained("bert-base"  )


   def 	snake_case__	(     self  ):
        '''simple docstring'''



        with self.assertRaisesRegex(
            _UpperCAmelCase,				R"aaaaaa is not a valid git identifier \(branch name, tag name or commit id\)"  ):
             lowercase__				 =							FlaxAutoModel.from_pretrained(_UpperCAmelCase,				revision="aaaaaa"  )


   def 	snake_case__	(     self  ):
        '''simple docstring'''



        with self.assertRaisesRegex(
            _UpperCAmelCase,				"hf-internal-testing/config-no-model does not appear to have a file named flax_model.msgpack",				):
             lowercase__				 =							FlaxAutoModel.from_pretrained("hf-internal-testing/config-no-model"  )


   def 	snake_case__	(     self  ):
        '''simple docstring'''



        with self.assertRaisesRegex(_UpperCAmelCase,				"Use `from_pt=True` to load this model"  ):
             lowercase__				 =							FlaxAutoModel.from_pretrained("hf-internal-testing/tiny-bert-pt-only"  )




