


import unittest

from transformers.utils.backbone_utils import (
    BackboneMixin,
    get_aligned_output_features_output_indices,
    verify_out_features_out_indices,
)
class 				SCREAMING_SNAKE_CASE__						(       unittest.TestCase    ):
      def  SCREAMING_SNAKE_CASE							( self       : Tuple  )	->    Any:
             a_      :	Tuple							=						['a', 'b', 'c']

             # Defaults to last layer if both are None
             a_							,	a_      :	Dict							=						get_aligned_output_features_output_indices(SCREAMING_SNAKE_CASE__  ,							SCREAMING_SNAKE_CASE__  ,							SCREAMING_SNAKE_CASE__  )
             self.assertEqual(SCREAMING_SNAKE_CASE__  ,							['c']  )
             self.assertEqual(SCREAMING_SNAKE_CASE__  ,							[2]  )

             # Out indices set to match out features
             a_							,	a_      :	Optional[Any]							=						get_aligned_output_features_output_indices(['a', 'c']  ,							SCREAMING_SNAKE_CASE__  ,							SCREAMING_SNAKE_CASE__  )
             self.assertEqual(SCREAMING_SNAKE_CASE__  ,							['a', 'c']  )
             self.assertEqual(SCREAMING_SNAKE_CASE__  ,							[0, 2]  )

             # Out features set to match out indices
             a_							,	a_      :	int							=						get_aligned_output_features_output_indices(SCREAMING_SNAKE_CASE__  ,							[0, 2]  ,							SCREAMING_SNAKE_CASE__  )
             self.assertEqual(SCREAMING_SNAKE_CASE__  ,							['a', 'c']  )
             self.assertEqual(SCREAMING_SNAKE_CASE__  ,							[0, 2]  )

             # Out features selected from negative indices
             a_							,	a_      :	Dict							=						get_aligned_output_features_output_indices(SCREAMING_SNAKE_CASE__  ,							[-3, -1]  ,							SCREAMING_SNAKE_CASE__  )
             self.assertEqual(SCREAMING_SNAKE_CASE__  ,							['a', 'c']  )
             self.assertEqual(SCREAMING_SNAKE_CASE__  ,							[-3, -1]  )
      def  SCREAMING_SNAKE_CASE							( self       : int  )	->    Dict:
             # Stage names must be set
             with self.assertRaises(SCREAMING_SNAKE_CASE__  ):
                    verify_out_features_out_indices(['a', 'b']  ,							(0, 1)  ,							SCREAMING_SNAKE_CASE__  )

             # Out features must be a list
             with self.assertRaises(SCREAMING_SNAKE_CASE__  ):
                    verify_out_features_out_indices(('a', 'b')  ,							(0, 1)  ,							['a', 'b']  )

             # Out features must be a subset of stage names
             with self.assertRaises(SCREAMING_SNAKE_CASE__  ):
                    verify_out_features_out_indices(['a', 'b']  ,							(0, 1)  ,							['a']  )

             # Out indices must be a list or tuple
             with self.assertRaises(SCREAMING_SNAKE_CASE__  ):
                    verify_out_features_out_indices(SCREAMING_SNAKE_CASE__  ,							0  ,							['a', 'b']  )

             # Out indices must be a subset of stage names
             with self.assertRaises(SCREAMING_SNAKE_CASE__  ):
                    verify_out_features_out_indices(SCREAMING_SNAKE_CASE__  ,							(0, 1)  ,							['a']  )

             # Out features and out indices must be the same length
             with self.assertRaises(SCREAMING_SNAKE_CASE__  ):
                    verify_out_features_out_indices(['a', 'b']  ,							(0,)  ,							['a', 'b', 'c']  )

             # Out features should match out indices
             with self.assertRaises(SCREAMING_SNAKE_CASE__  ):
                    verify_out_features_out_indices(['a', 'b']  ,							(0, 2)  ,							['a', 'b', 'c']  )

             # Out features and out indices should be in order
             with self.assertRaises(SCREAMING_SNAKE_CASE__  ):
                    verify_out_features_out_indices(['b', 'a']  ,							(0, 1)  ,							['a', 'b']  )

             # Check passes with valid inputs
             verify_out_features_out_indices(['a', 'b', 'd']  ,							(0, 1, -1)  ,							['a', 'b', 'c', 'd']  )

      def  SCREAMING_SNAKE_CASE							( self       : str  )	->    Tuple:
             a_      :	Optional[int]							=						BackboneMixin()

             a_      :	str							=						['a', 'b', 'c']
             a_      :	str							=						['a', 'c']
             a_      :	Any							=						[0, 2]

             # Check that the output features and indices are set correctly
             self.assertEqual(backbone.out_features  ,							['a', 'c']  )
             self.assertEqual(backbone.out_indices  ,							[0, 2]  )

             # Check out features and indices are updated correctly
             a_      :	Union[str, Any]							=						['a', 'b']
             self.assertEqual(backbone.out_features  ,							['a', 'b']  )
             self.assertEqual(backbone.out_indices  ,							[0, 1]  )

             a_      :	Union[str, Any]							=						[-3, -1]
             self.assertEqual(backbone.out_features  ,							['a', 'c']  )
             self.assertEqual(backbone.out_indices  ,							[-3, -1]  )






import os
import tempfile
import unittest

from transformers.models.marian.convert_marian_tatoeba_to_pytorch import DEFAULT_REPO, TatoebaConverter
from transformers.testing_utils import slow
from transformers.utils import cached_property
@unittest.skipUnless(os.path.exists(lowercase__    )		,					'''Tatoeba directory does not exist.'''    )
class 				SCREAMING_SNAKE_CASE__						(       unittest.TestCase    ):
      @cached_property
      def  SCREAMING_SNAKE_CASE							( self       : str  )	->    List[Any]:
             a_      :	Optional[Any]							=						tempfile.mkdtemp()
             return TatoebaConverter(save_dir=SCREAMING_SNAKE_CASE__  )
      @slow
      def  SCREAMING_SNAKE_CASE							( self       : List[Any]  )	->    Optional[Any]:
             self.resolver.convert_models(['heb-eng']  )

      @slow
      def  SCREAMING_SNAKE_CASE							( self       : int  )	->    Any:
             a_							,	a_      :	Dict							=						self.resolver.write_model_card('opus-mt-he-en'  ,							dry_run=SCREAMING_SNAKE_CASE__  )
             assert mmeta["long_pair"] == "heb-eng"


