



"""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 SCREAMING_SNAKE_CASE__					(		__snake_case      ):



						def     lowerCAmelCase__(self							):





													'''simple docstring'''

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



						def     lowerCAmelCase__(self						,     _lowercase							):





													'''simple docstring'''

													__a		:		Tuple									=       AutoModel.from_pretrained(self.test_model							)
													model_pt.save_pretrained(_lowercase							)



						def     lowerCAmelCase__(self						,     _lowercase							):





													'''simple docstring'''

													__a		:		List[str]									=       TFAutoModel.from_pretrained(self.test_model						,     from_pt=_lowercase							)
													model_tf.save_pretrained(_lowercase							)



						def     lowerCAmelCase__(self							):





													'''simple docstring'''

													__a		:		Any									=       """mock_framework"""

													# Framework provided - return whatever the user provides
													__a		:		str									=       FeaturesManager.determine_framework(self.test_model						,     _lowercase							)
													self.assertEqual(_lowercase						,     _lowercase							)

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

													# TensorFlow checkpoint
													with TemporaryDirectory() as local_tf_ckpt:
																				self._setup_tf_ckpt(_lowercase							)
																				__a		:		List[str]									=       FeaturesManager.determine_framework(_lowercase						,     _lowercase							)
																				self.assertEqual(_lowercase						,     _lowercase							)



						def     lowerCAmelCase__(self							):





													'''simple docstring'''

													with TemporaryDirectory() as local_pt_ckpt:
																				self._setup_pt_ckpt(_lowercase							)
																				__a		:		List[Any]									=       FeaturesManager.determine_framework(_lowercase							)
																				self.assertEqual(_lowercase						,     self.framework_pt							)

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

													# Invalid local checkpoint
													with TemporaryDirectory() as local_invalid_ckpt:
																				with self.assertRaises(_lowercase							):
																											__a		:		str									=       FeaturesManager.determine_framework(_lowercase							)





						def     lowerCAmelCase__(self							):





													'''simple docstring'''

													__a		:		List[str]									=       MagicMock(return_value=_lowercase							)
													with patch("""transformers.onnx.features.is_tf_available"""						,     _lowercase							):
																				__a		:		Dict									=       FeaturesManager.determine_framework(self.test_model							)
																				self.assertEqual(_lowercase						,     self.framework_pt							)

													# PyTorch not in environment -> use TensorFlow
													__a		:		Tuple									=       MagicMock(return_value=_lowercase							)
													with patch("""transformers.onnx.features.is_torch_available"""						,     _lowercase							):
																				__a		:		Union[str, Any]									=       FeaturesManager.determine_framework(self.test_model							)
																				self.assertEqual(_lowercase						,     self.framework_tf							)

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

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






"""simple docstring"""

def       __magic_name__    (   _lowerCamelCase				: int  ,       _lowerCamelCase				: float  ,       _lowerCamelCase				: float					):
							return round(float(moles / volume					) * nfactor					)





def       __magic_name__    (   _lowerCamelCase				: float  ,       _lowerCamelCase				: float  ,       _lowerCamelCase				: float					):
							return round(float((moles * 0.08_21 * temperature) / (volume)					)					)





def       __magic_name__    (   _lowerCamelCase				: float  ,       _lowerCamelCase				: float  ,       _lowerCamelCase				: float					):
							return round(float((moles * 0.08_21 * temperature) / (pressure)					)					)





def       __magic_name__    (   _lowerCamelCase				: float  ,       _lowerCamelCase				: float  ,       _lowerCamelCase				: float					):
							return round(float((pressure * volume) / (0.08_21 * moles)					)					)


if __name__ == "__main__":
	import doctest

	doctest.testmod()

