


'''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        lowercase     (							A__ ):

		"""simple docstring"""

		def    lowerCAmelCase__    (		self							):

							'''simple docstring'''


							UpperCamelCase__       :List[str]							 =			SMALL_MODEL_IDENTIFIER
							UpperCamelCase__       :Tuple							 =			'''pt'''
							UpperCamelCase__       :Optional[Any]							 =			'''tf'''




		def    lowerCAmelCase__    (		self   ,       UpperCamelCase_							):

							'''simple docstring'''


							UpperCamelCase__       :Any							 =			AutoModel.from_pretrained(self.test_model							)
							model_pt.save_pretrained(UpperCamelCase_							)




		def    lowerCAmelCase__    (		self   ,       UpperCamelCase_							):

							'''simple docstring'''


							UpperCamelCase__       :Optional[Any]							 =			TFAutoModel.from_pretrained(self.test_model   ,       from_pt=UpperCamelCase_							)
							model_tf.save_pretrained(UpperCamelCase_							)




		def    lowerCAmelCase__    (		self							):

							'''simple docstring'''


							UpperCamelCase__       :int							 =			'''mock_framework'''

							# Framework provided - return whatever the user provides
							UpperCamelCase__       :Optional[int]							 =			FeaturesManager.determine_framework(self.test_model   ,       UpperCamelCase_							)
							self.assertEqual(UpperCamelCase_   ,       UpperCamelCase_							)

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

							# TensorFlow checkpoint
							with TemporaryDirectory() as local_tf_ckpt:
												self._setup_tf_ckpt(UpperCamelCase_							)
												UpperCamelCase__       :Optional[Any]							 =			FeaturesManager.determine_framework(UpperCamelCase_   ,       UpperCamelCase_							)
												self.assertEqual(UpperCamelCase_   ,       UpperCamelCase_							)




		def    lowerCAmelCase__    (		self							):

							'''simple docstring'''


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

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

							# Invalid local checkpoint
							with TemporaryDirectory() as local_invalid_ckpt:
												with self.assertRaises(UpperCamelCase_							):
																	UpperCamelCase__       :List[str]							 =			FeaturesManager.determine_framework(UpperCamelCase_							)




		def    lowerCAmelCase__    (		self							):

							'''simple docstring'''


							UpperCamelCase__       :Optional[Any]							 =			MagicMock(return_value=UpperCamelCase_							)
							with patch('''transformers.onnx.features.is_tf_available'''   ,       UpperCamelCase_							):
												UpperCamelCase__       :Any							 =			FeaturesManager.determine_framework(self.test_model							)
												self.assertEqual(UpperCamelCase_   ,       self.framework_pt							)

							# PyTorch not in environment -> use TensorFlow
							UpperCamelCase__       :List[Any]							 =			MagicMock(return_value=UpperCamelCase_							)
							with patch('''transformers.onnx.features.is_torch_available'''   ,       UpperCamelCase_							):
												UpperCamelCase__       :Tuple							 =			FeaturesManager.determine_framework(self.test_model							)
												self.assertEqual(UpperCamelCase_   ,       self.framework_tf							)

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

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



'''simple docstring'''
# tests directory-specific settings - this file is run automatically
# by pytest before any tests are run

import sys
import warnings
from os.path import abspath, dirname, join


# allow having multiple repository checkouts and not needing to remember to rerun
# 'pip install -e .[dev]' when switching between checkouts and running tests.
__snake_case											=					abspath(join(dirname(dirname(__file__)), '''src'''))
sys.path.insert(1, git_repo_path)

# silence FutureWarning warnings in tests since often we can't act on them until
# they become normal warnings - i.e. the tests still need to test the current functionality
warnings.simplefilter(action='''ignore''', category=FutureWarning)


def       a				(      __a       )  ->     Optional[int]:



					'''simple docstring'''






					from diffusers.utils.testing_utils import pytest_addoption_shared

					pytest_addoption_shared(__a       )







def       a				(      __a       )  ->     str:



					'''simple docstring'''






					from diffusers.utils.testing_utils import pytest_terminal_summary_main

					UpperCamelCase__       :Union[str, Any]							 =			terminalreporter.config.getoption('''--make-reports'''       )
					if make_reports:
										pytest_terminal_summary_main(__a			, id=__a       )