
"""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 	lowerCAmelCase_						(a__  ):


				"""simple docstring"""



				def 	__magic_name__    (self    )					->		str:



											"""simple docstring"""




											SCREAMING_SNAKE_CASE__						:       str           =   SMALL_MODEL_IDENTIFIER
											SCREAMING_SNAKE_CASE__						:       str           =   """pt"""
											SCREAMING_SNAKE_CASE__						:       Dict           =   """tf"""



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



											"""simple docstring"""




											SCREAMING_SNAKE_CASE__						:       List[str]           =   AutoModel.from_pretrained(self.test_model    )
											model_pt.save_pretrained(SCREAMING_SNAKE_CASE__    )



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



											"""simple docstring"""




											SCREAMING_SNAKE_CASE__						:       Union[str, Any]           =   TFAutoModel.from_pretrained(self.test_model   ,       from_pt=SCREAMING_SNAKE_CASE__    )
											model_tf.save_pretrained(SCREAMING_SNAKE_CASE__    )



				def 	__magic_name__    (self    )					->		str:



											"""simple docstring"""




											SCREAMING_SNAKE_CASE__						:       Any           =   """mock_framework"""

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

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

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



				def 	__magic_name__    (self    )					->		Optional[int]:



											"""simple docstring"""




											with TemporaryDirectory() as local_pt_ckpt:
																		self._setup_pt_ckpt(SCREAMING_SNAKE_CASE__    )
																		SCREAMING_SNAKE_CASE__						:       Optional[int]           =   FeaturesManager.determine_framework(SCREAMING_SNAKE_CASE__    )
																		self.assertEqual(SCREAMING_SNAKE_CASE__   ,       self.framework_pt    )

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

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



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



											"""simple docstring"""




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

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

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

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






"""simple docstring"""




import math
import unittest

def lowercase_  (   _snake_case						):
							assert isinstance(_snake_case   ,_snake_case						) and (
							    number >= 0
							), "'number' must been an int and positive"

							if 1 < number < 4:
														# 2 and 3 are primes
														return True
							elif number < 2 or number % 2 == 0 or number % 3 == 0:
														# Negatives, 0, 1, all even numbers, all multiples of 3 are not primes
														return False

							# All primes number are in format of 6k +/- 1
							for i in range(5   ,int(math.sqrt(_snake_case						) + 1						)   ,6						):
														if number % i == 0 or number % (i + 2) == 0:
																					return False
							return True



class 	lowerCAmelCase_						(unittest.TestCase  ):


				"""simple docstring"""



				def 	__magic_name__    (self    )					->		Dict:



											"""simple docstring"""




											self.assertTrue(is_prime(2    )    )
											self.assertTrue(is_prime(3    )    )
											self.assertTrue(is_prime(5    )    )
											self.assertTrue(is_prime(7    )    )
											self.assertTrue(is_prime(11    )    )
											self.assertTrue(is_prime(13    )    )
											self.assertTrue(is_prime(17    )    )
											self.assertTrue(is_prime(19    )    )
											self.assertTrue(is_prime(23    )    )
											self.assertTrue(is_prime(29    )    )



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



											"""simple docstring"""




											with self.assertRaises(SCREAMING_SNAKE_CASE__    ):
																		is_prime(-19    )
											self.assertFalse(
											    is_prime(0    )   ,       """Zero doesn't have any positive factors, primes must have exactly two."""   ,       )
											self.assertFalse(
											    is_prime(1    )   ,       """One only has 1 positive factor, primes must have exactly two."""   ,       )
											self.assertFalse(is_prime(2 * 2    )    )
											self.assertFalse(is_prime(2 * 3    )    )
											self.assertFalse(is_prime(3 * 3    )    )
											self.assertFalse(is_prime(3 * 5    )    )
											self.assertFalse(is_prime(3 * 5 * 7    )    )


if __name__ == "__main__":
					unittest.main()




