




"""simple docstring"""



from tempfile import TemporaryDirectory
from unittest import TestCase
from unittest.mock import MagicMock, patch

from transformers import AutoModel, TFAutoModel
from transformers.onnx import FeaturesManager
from transformers.testing_utils import SMALL_MODEL_IDENTIFIER, require_tf, require_torch




@require_torch
@require_tf
class      UpperCAmelCase_  (						A_							):




    def 							__magic_name__							(   self						:	List[str]				)				->							Any:




     '''simple docstring'''

     A__	=    SMALL_MODEL_IDENTIFIER
     A__	=    "pt"
     A__	=    "tf"




    def 							__magic_name__							(   self						:	Union[str, Any]     ,			snake_case_						:	List[str]				)				->							Any:




     '''simple docstring'''

     A__	=    AutoModel.from_pretrained(self.test_model				)
     model_pt.save_pretrained(snake_case_				)




    def 							__magic_name__							(   self						:	Optional[Any]     ,			snake_case_						:	Dict				)				->							List[str]:




     '''simple docstring'''

     A__	=    TFAutoModel.from_pretrained(self.test_model     ,			from_pt=snake_case_				)
     model_tf.save_pretrained(snake_case_				)




    def 							__magic_name__							(   self						:	Optional[int]				)				->							Union[str, Any]:




     '''simple docstring'''

     A__	=    "mock_framework"

     # Framework provided - return whatever the user provides
     A__	=    FeaturesManager.determine_framework(self.test_model     ,			snake_case_				)
     self.assertEqual(snake_case_     ,			snake_case_				)

     # Local checkpoint and framework provided - return provided framework
     # PyTorch checkpoint
     with TemporaryDirectory() as local_pt_ckpt:
      self._setup_pt_ckpt(snake_case_				)
      A__	=    FeaturesManager.determine_framework(snake_case_     ,			snake_case_				)
      self.assertEqual(snake_case_     ,			snake_case_				)

     # TensorFlow checkpoint
     with TemporaryDirectory() as local_tf_ckpt:
      self._setup_tf_ckpt(snake_case_				)
      A__	=    FeaturesManager.determine_framework(snake_case_     ,			snake_case_				)
      self.assertEqual(snake_case_     ,			snake_case_				)




    def 							__magic_name__							(   self						:	int				)				->							Dict:




     '''simple docstring'''

     with TemporaryDirectory() as local_pt_ckpt:
      self._setup_pt_ckpt(snake_case_				)
      A__	=    FeaturesManager.determine_framework(snake_case_				)
      self.assertEqual(snake_case_     ,			self.framework_pt				)

     # TensorFlow checkpoint
     with TemporaryDirectory() as local_tf_ckpt:
      self._setup_tf_ckpt(snake_case_				)
      A__	=    FeaturesManager.determine_framework(snake_case_				)
      self.assertEqual(snake_case_     ,			self.framework_tf				)

     # Invalid local checkpoint
     with TemporaryDirectory() as local_invalid_ckpt:
      with self.assertRaises(snake_case_				):
       A__	=    FeaturesManager.determine_framework(snake_case_				)




    def 							__magic_name__							(   self						:	str				)				->							Any:




     '''simple docstring'''

     A__	=    MagicMock(return_value=snake_case_				)
     with patch("transformers.onnx.features.is_tf_available"     ,			snake_case_				):
      A__	=    FeaturesManager.determine_framework(self.test_model				)
      self.assertEqual(snake_case_     ,			self.framework_pt				)

     # PyTorch not in environment -> use TensorFlow
     A__	=    MagicMock(return_value=snake_case_				)
     with patch("transformers.onnx.features.is_torch_available"     ,			snake_case_				):
      A__	=    FeaturesManager.determine_framework(self.test_model				)
      self.assertEqual(snake_case_     ,			self.framework_tf				)

     # Both in environment -> use PyTorch
     A__	=    MagicMock(return_value=snake_case_				)
     A__	=    MagicMock(return_value=snake_case_				)
     with patch("transformers.onnx.features.is_tf_available"     ,			snake_case_				), patch(
         "transformers.onnx.features.is_torch_available"     ,			snake_case_				):
      A__	=    FeaturesManager.determine_framework(self.test_model				)
      self.assertEqual(snake_case_     ,			self.framework_pt				)

     # Both not in environment -> raise error
     A__	=    MagicMock(return_value=snake_case_				)
     A__	=    MagicMock(return_value=snake_case_				)
     with patch("transformers.onnx.features.is_tf_available"     ,			snake_case_				), patch(
         "transformers.onnx.features.is_torch_available"     ,			snake_case_				):
      with self.assertRaises(snake_case_				):
       A__	=    FeaturesManager.determine_framework(self.test_model				)











"""simple docstring"""



import baseaa







def   _SCREAMING_SNAKE_CASE       (							lowercase_						)						->		bytes:
 return baseaa.aaaencode(string.encode("utf-8"						)						)







def   _SCREAMING_SNAKE_CASE       (							lowercase_						)						->		str:
 return baseaa.aaadecode(lowercase_						).decode("utf-8"						)


if __name__ == "__main__":
      import doctest

      doctest.testmod()





