

"""simple docstring"""






import unittest

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







class       snake_case__  ( unittest.TestCase     ):







			def 			__lowerCAmelCase				(			self			: int  ):





								'''simple docstring'''



								UpperCAmelCase			:   List[str]      =				["a", "b", "c"]

								# Defaults to last layer if both are None
								UpperCAmelCase      ,							UpperCAmelCase			:   List[Any]      =				get_aligned_output_features_output_indices(lowercase			,  lowercase			,  lowercase  )
								self.assertEqual(lowercase			,  ["c"]  )
								self.assertEqual(lowercase			,  [2]  )

								# Out indices set to match out features
								UpperCAmelCase      ,							UpperCAmelCase			:   List[Any]      =				get_aligned_output_features_output_indices(["a", "c"]			,  lowercase			,  lowercase  )
								self.assertEqual(lowercase			,  ["a", "c"]  )
								self.assertEqual(lowercase			,  [0, 2]  )

								# Out features set to match out indices
								UpperCAmelCase      ,							UpperCAmelCase			:   str      =				get_aligned_output_features_output_indices(lowercase			,  [0, 2]			,  lowercase  )
								self.assertEqual(lowercase			,  ["a", "c"]  )
								self.assertEqual(lowercase			,  [0, 2]  )

								# Out features selected from negative indices
								UpperCAmelCase      ,							UpperCAmelCase			:   Optional[Any]      =				get_aligned_output_features_output_indices(lowercase			,  [-3, -1]			,  lowercase  )
								self.assertEqual(lowercase			,  ["a", "c"]  )
								self.assertEqual(lowercase			,  [-3, -1]  )







			def 			__lowerCAmelCase				(			self			: int  ):





								'''simple docstring'''



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

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

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

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

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

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

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

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





								'''simple docstring'''



								UpperCAmelCase			:   Optional[int]      =				BackboneMixin()

								UpperCAmelCase			:   Optional[Any]      =				["a", "b", "c"]
								UpperCAmelCase			:   Union[str, Any]      =				["a", "c"]
								UpperCAmelCase			:   Dict      =				[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			:   Any      =				["a", "b"]
								self.assertEqual(backbone.out_features			,  ["a", "b"]  )
								self.assertEqual(backbone.out_indices			,  [0, 1]  )

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





"""simple docstring"""






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

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

import _pytest

from transformers.testing_utils import HfDoctestModule, HfDocTestParser


# 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_   :   Union[str, Any]        =       abspath(join(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   lowercase_	(    _lowercase       :		List[str]	):




					'''simple docstring'''






					config.addinivalue_line(
					    "markers"							,      "is_pt_tf_cross_test: mark test to run only when PT and TF interactions are tested"	)
					config.addinivalue_line(
					    "markers"							,      "is_pt_flax_cross_test: mark test to run only when PT and FLAX interactions are tested"	)
					config.addinivalue_line("markers"							,      "is_pipeline_test: mark test to run only when pipelines are tested"	)
					config.addinivalue_line("markers"							,      "is_staging_test: mark test to run only in the staging environment"	)
					config.addinivalue_line("markers"							,      "accelerate_tests: mark test that require accelerate"	)
					config.addinivalue_line("markers"							,      "tool_tests: mark the tool tests that are run on their specific schedule"	)



def   lowercase_	(    _lowercase       :		List[str]	):




					'''simple docstring'''






					from transformers.testing_utils import pytest_addoption_shared

					pytest_addoption_shared(_lowercase	)



def   lowercase_	(    _lowercase       :		Tuple	):




					'''simple docstring'''






					from transformers.testing_utils import pytest_terminal_summary_main

					UpperCAmelCase			:   Optional[int]      =				terminalreporter.config.getoption("--make-reports"	)
					if make_reports:
										pytest_terminal_summary_main(_lowercase							,      id=_lowercase	)



def   lowercase_	(    _lowercase       :		str							,      _lowercase       :		Dict	):




					'''simple docstring'''






					if exitstatus == 5:
										UpperCAmelCase			:   List[str]      =				0


# Doctest custom flag to ignore output.
snake_case_   :   Union[str, Any]        =       doctest.register_optionflag("""IGNORE_RESULT""")

snake_case_   :   Optional[int]        =       doctest.OutputChecker







class       snake_case__  ( lowerCAmelCase_     ):







			def 			__lowerCAmelCase				(			self			: List[Any]			,  lowercase			: Tuple			,  lowercase			: Optional[Any]			,  lowercase			: int  ):





								'''simple docstring'''



								if IGNORE_RESULT & optionflags:
													return True
								return OutputChecker.check_output(self			,  lowercase			,  lowercase			,  lowercase  )

snake_case_   :   List[str]        =       CustomOutputChecker
snake_case_   :   Optional[Any]        =       HfDoctestModule




snake_case_   :   List[str]        =       HfDocTestParser


