






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 							A_    (						__lowercase			):






 '''simple docstring'''




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

     """simple docstring"""



     _UpperCAmelCase				:      Dict			  =				SMALL_MODEL_IDENTIFIER
     _UpperCAmelCase				:      Dict			  =				'''pt'''
     _UpperCAmelCase				:      Union[str, Any]			  =				'''tf'''


 def  snake_case__				(	self							,  _A) ->		Optional[int]:

     """simple docstring"""



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


 def  snake_case__				(	self							,  _A) ->		Optional[int]:

     """simple docstring"""



     _UpperCAmelCase				:      Any			  =				TFAutoModel.from_pretrained(self.test_model							,  from_pt=_A)
     model_tf.save_pretrained(_A)


 def  snake_case__				(	self) ->		Dict:

     """simple docstring"""



     _UpperCAmelCase				:      int			  =				'''mock_framework'''

     # Framework provided - return whatever the user provides
     _UpperCAmelCase				:      Optional[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				:      int			  =				FeaturesManager.determine_framework(_A							,  _A)
         self.assertEqual(_A							,  _A)

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


 def  snake_case__				(	self) ->		Any:

     """simple docstring"""



     with TemporaryDirectory() as local_pt_ckpt:
         self._setup_pt_ckpt(_A)
         _UpperCAmelCase				:      Tuple			  =				FeaturesManager.determine_framework(_A)
         self.assertEqual(_A							,  self.framework_pt)

     # TensorFlow checkpoint
     with TemporaryDirectory() as local_tf_ckpt:
         self._setup_tf_ckpt(_A)
         _UpperCAmelCase				:      Tuple			  =				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  snake_case__				(	self) ->		List[str]:

     """simple docstring"""



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

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

     # Both in environment -> use PyTorch
     _UpperCAmelCase				:      Optional[Any]			  =				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):
         _UpperCAmelCase				:      List[Any]			  =				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				:      Union[str, Any]			  =				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				:      str			  =				FeaturesManager.determine_framework(self.test_model)












import unittest

from knapsack import knapsack as k
class 							A_    (						unittest.TestCase			):






 '''simple docstring'''




 def  snake_case__				(	self) ->		Dict:

     """simple docstring"""



     _UpperCAmelCase				:      Optional[int]			  =				0
     _UpperCAmelCase				:      List[Any]			  =				[0]
     _UpperCAmelCase				:      Optional[Any]			  =				[0]
     _UpperCAmelCase				:      Optional[int]			  =				len(_A)
     self.assertEqual(k.knapsack(_A							,  _A							,  _A							,  _A)							,  0)

     _UpperCAmelCase				:      Optional[int]			  =				[60]
     _UpperCAmelCase				:      List[str]			  =				[10]
     _UpperCAmelCase				:      str			  =				len(_A)
     self.assertEqual(k.knapsack(_A							,  _A							,  _A							,  _A)							,  0)


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

     """simple docstring"""



     _UpperCAmelCase				:      Any			  =				3
     _UpperCAmelCase				:      int			  =				[1, 2, 3]
     _UpperCAmelCase				:      List[str]			  =				[3, 2, 1]
     _UpperCAmelCase				:      Union[str, Any]			  =				len(_A)
     self.assertEqual(k.knapsack(_A							,  _A							,  _A							,  _A)							,  5)


 def  snake_case__				(	self) ->		Tuple:

     """simple docstring"""



     _UpperCAmelCase				:      List[str]			  =				50
     _UpperCAmelCase				:      Tuple			  =				[60, 100, 120]
     _UpperCAmelCase				:      Optional[int]			  =				[10, 20, 30]
     _UpperCAmelCase				:      Optional[Any]			  =				len(_A)
     self.assertEqual(k.knapsack(_A							,  _A							,  _A							,  _A)							,  220)


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




