import unittest

from transformers.utils.backbone_utils import (
    BackboneMixin,
    get_aligned_output_features_output_indices,
    verify_out_features_out_indices,
)


class 			UpperCAmelCase__    (		unittest.TestCase					):



  """simple docstring"""






  def 	_UpperCAmelCase				(				self:			Optional[Any]   ) -> int:




    '''simple docstring'''




    __UpperCAmelCase						    =       ["a", "b", "c"]

    # Defaults to last layer if both are None
    __UpperCAmelCase    ,		__UpperCAmelCase						    =       get_aligned_output_features_output_indices(__lowerCAmelCase				,				__lowerCAmelCase				,				__lowerCAmelCase   )
    self.assertEqual(__lowerCAmelCase				,				["c"]   )
    self.assertEqual(__lowerCAmelCase				,				[2]   )

    # Out indices set to match out features
    __UpperCAmelCase    ,		__UpperCAmelCase						    =       get_aligned_output_features_output_indices(["a", "c"]				,				__lowerCAmelCase				,				__lowerCAmelCase   )
    self.assertEqual(__lowerCAmelCase				,				["a", "c"]   )
    self.assertEqual(__lowerCAmelCase				,				[0, 2]   )

    # Out features set to match out indices
    __UpperCAmelCase    ,		__UpperCAmelCase						    =       get_aligned_output_features_output_indices(__lowerCAmelCase				,				[0, 2]				,				__lowerCAmelCase   )
    self.assertEqual(__lowerCAmelCase				,				["a", "c"]   )
    self.assertEqual(__lowerCAmelCase				,				[0, 2]   )

    # Out features selected from negative indices
    __UpperCAmelCase    ,		__UpperCAmelCase						    =       get_aligned_output_features_output_indices(__lowerCAmelCase				,				[-3, -1]				,				__lowerCAmelCase   )
    self.assertEqual(__lowerCAmelCase				,				["a", "c"]   )
    self.assertEqual(__lowerCAmelCase				,				[-3, -1]   )






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




    '''simple docstring'''




    with self.assertRaises(__lowerCAmelCase   ):
      verify_out_features_out_indices(["a", "b"]				,				(0, 1)				,				__lowerCAmelCase   )

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

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

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

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

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

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

    # Out features and out indices should be in order
    with self.assertRaises(__lowerCAmelCase   ):
      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 	_UpperCAmelCase				(				self:			Optional[int]   ) -> Tuple:




    '''simple docstring'''




    __UpperCAmelCase						    =       BackboneMixin()

    __UpperCAmelCase						    =       ["a", "b", "c"]
    __UpperCAmelCase						    =       ["a", "c"]
    __UpperCAmelCase						    =       [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
    __UpperCAmelCase						    =       ["a", "b"]
    self.assertEqual(backbone.out_features				,				["a", "b"]   )
    self.assertEqual(backbone.out_indices				,				[0, 1]   )

    __UpperCAmelCase						    =       [-3, -1]
    self.assertEqual(backbone.out_features				,				["a", "c"]   )
    self.assertEqual(backbone.out_indices				,				[-3, -1]   )




import inspect
import unittest


class 			UpperCAmelCase__    (		unittest.TestCase					):



  """simple docstring"""






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




    '''simple docstring'''




    try:
      import diffusers  # noqa: F401
    except ImportError:
      assert False






  def 	_UpperCAmelCase				(				self:			Dict   ) -> Dict:




    '''simple docstring'''




    import diffusers
    from diffusers.dependency_versions_table import deps

    __UpperCAmelCase						    =       inspect.getmembers(__lowerCAmelCase				,				inspect.isclass   )

    for cls_name, cls_module in all_classes:
      if "dummy_" in cls_module.__module__:
        for backend in cls_module._backends:
          if backend == "k_diffusion":
            __UpperCAmelCase						    =       "k-diffusion"
          elif backend == "invisible_watermark":
            __UpperCAmelCase						    =       "invisible-watermark"
          assert backend in deps, F'''{backend} is not in the deps table!'''



