
"""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_						(lowerCamelCase_    ):
 """simple docstring"""




 def 	a   (			self							:			Tuple			)->       str:



      """simple docstring"""

      UpperCAmelCase_    :     List[Any]            =	SMALL_MODEL_IDENTIFIER
      UpperCAmelCase_    :     Union[str, Any]            =	"""pt"""
      UpperCAmelCase_    :     int            =	"""tf"""




 def 	a   (			self							:			Dict  , a_							:			List[Any]			)->       int:



      """simple docstring"""

      UpperCAmelCase_    :     Optional[int]            =	AutoModel.from_pretrained(self.test_model			)
      model_pt.save_pretrained(a_			)




 def 	a   (			self							:			int  , a_							:			Tuple			)->       Optional[Any]:



      """simple docstring"""

      UpperCAmelCase_    :     int            =	TFAutoModel.from_pretrained(self.test_model  , from_pt=a_			)
      model_tf.save_pretrained(a_			)




 def 	a   (			self							:			Optional[Any]			)->       Tuple:



      """simple docstring"""

      UpperCAmelCase_    :     str            =	"""mock_framework"""

      # Framework provided - return whatever the user provides
      UpperCAmelCase_    :     int            =	FeaturesManager.determine_framework(self.test_model  , a_			)
      self.assertEqual(a_  , a_			)

      # Local checkpoint and framework provided - return provided framework
      # PyTorch checkpoint
      with TemporaryDirectory() as local_pt_ckpt:
           self._setup_pt_ckpt(a_			)
           UpperCAmelCase_    :     Optional[int]            =	FeaturesManager.determine_framework(a_  , a_			)
           self.assertEqual(a_  , a_			)

      # TensorFlow checkpoint
      with TemporaryDirectory() as local_tf_ckpt:
           self._setup_tf_ckpt(a_			)
           UpperCAmelCase_    :     List[Any]            =	FeaturesManager.determine_framework(a_  , a_			)
           self.assertEqual(a_  , a_			)




 def 	a   (			self							:			Any			)->       Any:



      """simple docstring"""

      with TemporaryDirectory() as local_pt_ckpt:
           self._setup_pt_ckpt(a_			)
           UpperCAmelCase_    :     str            =	FeaturesManager.determine_framework(a_			)
           self.assertEqual(a_  , self.framework_pt			)

      # TensorFlow checkpoint
      with TemporaryDirectory() as local_tf_ckpt:
           self._setup_tf_ckpt(a_			)
           UpperCAmelCase_    :     str            =	FeaturesManager.determine_framework(a_			)
           self.assertEqual(a_  , self.framework_tf			)

      # Invalid local checkpoint
      with TemporaryDirectory() as local_invalid_ckpt:
           with self.assertRaises(a_			):
                UpperCAmelCase_    :     int            =	FeaturesManager.determine_framework(a_			)






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



      """simple docstring"""

      UpperCAmelCase_    :     Optional[Any]            =	MagicMock(return_value=a_			)
      with patch("""transformers.onnx.features.is_tf_available"""  , a_			):
           UpperCAmelCase_    :     str            =	FeaturesManager.determine_framework(self.test_model			)
           self.assertEqual(a_  , self.framework_pt			)

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

      # Both in environment -> use PyTorch
      UpperCAmelCase_    :     Any            =	MagicMock(return_value=a_			)
      UpperCAmelCase_    :     List[Any]            =	MagicMock(return_value=a_			)
      with patch("""transformers.onnx.features.is_tf_available"""  , a_			), patch(
          """transformers.onnx.features.is_torch_available"""  , a_			):
           UpperCAmelCase_    :     str            =	FeaturesManager.determine_framework(self.test_model			)
           self.assertEqual(a_  , self.framework_pt			)

      # Both not in environment -> raise error
      UpperCAmelCase_    :     List[str]            =	MagicMock(return_value=a_			)
      UpperCAmelCase_    :     Tuple            =	MagicMock(return_value=a_			)
      with patch("""transformers.onnx.features.is_tf_available"""  , a_			), patch(
          """transformers.onnx.features.is_torch_available"""  , a_			):
           with self.assertRaises(a_			):
                UpperCAmelCase_    :     Tuple            =	FeaturesManager.determine_framework(self.test_model			)



"""simple docstring"""







def       A_      (       lowercase = 1    ,			lowercase = 1000   )  ->				int:


     """simple docstring"""







     UpperCAmelCase_    :     Tuple            =	1
     UpperCAmelCase_    :     List[str]            =	0

     for divide_by_number in range(lowercase    ,			digit + 1   ):
          UpperCAmelCase_    :     list[int]            =	[]
          UpperCAmelCase_    :     Optional[int]            =	numerator
          for _ in range(1    ,			digit + 1   ):
               if now_divide in has_been_divided:
                    if longest_list_length < len(lowercase   ):
                         UpperCAmelCase_    :     Dict            =	len(lowercase   )
                         UpperCAmelCase_    :     Optional[int]            =	divide_by_number
               else:
                    has_been_divided.append(lowercase   )
                    UpperCAmelCase_    :     List[str]            =	now_divide * 10 % divide_by_number

     return the_digit


# Tests
if __name__ == "__main__":
       import doctest

       doctest.testmod()

