





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_							(  UpperCamelCase__     ):


							def   _snake_case	(				self     :Optional[Any]		) -> Optional[Any]:



									"""simple docstring"""



									SCREAMING_SNAKE_CASE__								=   SMALL_MODEL_IDENTIFIER
									SCREAMING_SNAKE_CASE__								=   """pt"""
									SCREAMING_SNAKE_CASE__								=   """tf"""


							def   _snake_case	(				self     :List[Any]				,					__A     :Union[str, Any]		) -> List[Any]:



									"""simple docstring"""



									SCREAMING_SNAKE_CASE__								=   AutoModel.from_pretrained(self.test_model		)
									model_pt.save_pretrained(__A		)


							def   _snake_case	(				self     :Optional[int]				,					__A     :Any		) -> List[str]:



									"""simple docstring"""



									SCREAMING_SNAKE_CASE__								=   TFAutoModel.from_pretrained(self.test_model				,					from_pt=__A		)
									model_tf.save_pretrained(__A		)


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



									"""simple docstring"""



									SCREAMING_SNAKE_CASE__								=   """mock_framework"""

									# Framework provided - return whatever the user provides
									SCREAMING_SNAKE_CASE__								=   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		)
											SCREAMING_SNAKE_CASE__								=   FeaturesManager.determine_framework(__A				,					__A		)
											self.assertEqual(__A				,					__A		)

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


							def   _snake_case	(				self     :Union[str, Any]		) -> str:



									"""simple docstring"""



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

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

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


							def   _snake_case	(				self     :Tuple		) -> List[Any]:



									"""simple docstring"""



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

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

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

									# Both not in environment -> raise error
									SCREAMING_SNAKE_CASE__								=   MagicMock(return_value=__A		)
									SCREAMING_SNAKE_CASE__								=   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		):
													SCREAMING_SNAKE_CASE__								=   FeaturesManager.determine_framework(self.test_model		)






def 					SCREAMING_SNAKE_CASE__				(							UpperCamelCase__:				float       , UpperCamelCase__:				float     ):
		if mass < 0:
				raise ValueError("""The mass of a body cannot be negative"""     )
		return 0.5 * mass * abs(UpperCamelCase__     ) * abs(UpperCamelCase__     )


if __name__ == "__main__":
	import doctest

	doctest.testmod(verbose=True)