"""simple docstring"""





import sys
import tempfile
import unittest
import unittest.mock as mock
from pathlib import Path

from huggingface_hub import HfFolder, delete_repo
from requests.exceptions import HTTPError

from transformers import AutoFeatureExtractor, WavaVecaFeatureExtractor
from transformers.testing_utils import TOKEN, USER, get_tests_dir, is_staging_test


sys.path.append(str(Path(__file__).parent.parent / '''utils'''))

from test_module.custom_feature_extraction import CustomFeatureExtractor  # noqa E402


__A  =				get_tests_dir('''fixtures''')
class  _snake_case     (					unittest.TestCase		):






						def       lowerCamelCase__     (       self      :			str    ):
													# A mock response for an HTTP head request to emulate server down
													__lowerCamelCase					:		List[Any]		   =     mock.Mock()
													__lowerCamelCase					:		Optional[Any]		   =     500
													__lowerCamelCase					:		List[Any]		   =     {}
													__lowerCamelCase					:		List[str]		   =     HTTPError
													__lowerCamelCase					:		List[Any]		   =     {}

													# Download this model to make sure it's in the cache.
													__lowerCamelCase					:		str		   =     WavaVecaFeatureExtractor.from_pretrained("hf-internal-testing/tiny-random-wav2vec2"    )
													# Under the mock environment we get a 500 error when trying to reach the model.
													with mock.patch("requests.Session.request"							,					return_value=UpperCAmelCase    ) as mock_head:
																				__lowerCamelCase					:		List[str]		   =     WavaVecaFeatureExtractor.from_pretrained("hf-internal-testing/tiny-random-wav2vec2"    )
																				# This check we did call the fake head request
																				mock_head.assert_called()







						def       lowerCamelCase__     (       self      :			int    ):
													# This test is for deprecated behavior and can be removed in v5
													__lowerCamelCase					:		Dict		   =     WavaVecaFeatureExtractor.from_pretrained(
													    "https://huggingface.co/hf-internal-testing/tiny-random-wav2vec2/resolve/main/preprocessor_config.json"    )

@is_staging_test
class  _snake_case     (					unittest.TestCase		):






						@classmethod
						def       lowerCamelCase__     (       cls      :			List[str]    ):
													__lowerCamelCase					:		Any		   =     TOKEN
													HfFolder.save_token(UpperCAmelCase    )






						@classmethod
						def       lowerCamelCase__     (       cls      :			Union[str, Any]    ):
													try:
																				delete_repo(token=cls._token							,					repo_id="test-feature-extractor"    )
													except HTTPError:
																				pass

													try:
																				delete_repo(token=cls._token							,					repo_id="valid_org/test-feature-extractor-org"    )
													except HTTPError:
																				pass

													try:
																				delete_repo(token=cls._token							,					repo_id="test-dynamic-feature-extractor"    )
													except HTTPError:
																				pass






						def       lowerCamelCase__     (       self      :			Dict    ):
													__lowerCamelCase					:		List[str]		   =     WavaVecaFeatureExtractor.from_pretrained(UpperCAmelCase    )
													feature_extractor.push_to_hub("test-feature-extractor"							,					use_auth_token=self._token    )

													__lowerCamelCase					:		Dict		   =     WavaVecaFeatureExtractor.from_pretrained(F"""{USER}/test-feature-extractor"""    )
													for k, v in feature_extractor.__dict__.items():
																				self.assertEqual(UpperCAmelCase							,					getattr(UpperCAmelCase							,					UpperCAmelCase    )    )

													# Reset repo
													delete_repo(token=self._token							,					repo_id="test-feature-extractor"    )

													# Push to hub via save_pretrained
													with tempfile.TemporaryDirectory() as tmp_dir:
																				feature_extractor.save_pretrained(
																				    UpperCAmelCase							,					repo_id="test-feature-extractor"							,					push_to_hub=UpperCAmelCase							,					use_auth_token=self._token    )

													__lowerCamelCase					:		List[str]		   =     WavaVecaFeatureExtractor.from_pretrained(F"""{USER}/test-feature-extractor"""    )
													for k, v in feature_extractor.__dict__.items():
																				self.assertEqual(UpperCAmelCase							,					getattr(UpperCAmelCase							,					UpperCAmelCase    )    )






						def       lowerCamelCase__     (       self      :			Dict    ):
													__lowerCamelCase					:		Optional[int]		   =     WavaVecaFeatureExtractor.from_pretrained(UpperCAmelCase    )
													feature_extractor.push_to_hub("valid_org/test-feature-extractor"							,					use_auth_token=self._token    )

													__lowerCamelCase					:		str		   =     WavaVecaFeatureExtractor.from_pretrained("valid_org/test-feature-extractor"    )
													for k, v in feature_extractor.__dict__.items():
																				self.assertEqual(UpperCAmelCase							,					getattr(UpperCAmelCase							,					UpperCAmelCase    )    )

													# Reset repo
													delete_repo(token=self._token							,					repo_id="valid_org/test-feature-extractor"    )

													# Push to hub via save_pretrained
													with tempfile.TemporaryDirectory() as tmp_dir:
																				feature_extractor.save_pretrained(
																				    UpperCAmelCase							,					repo_id="valid_org/test-feature-extractor-org"							,					push_to_hub=UpperCAmelCase							,					use_auth_token=self._token    )

													__lowerCamelCase					:		Any		   =     WavaVecaFeatureExtractor.from_pretrained("valid_org/test-feature-extractor-org"    )
													for k, v in feature_extractor.__dict__.items():
																				self.assertEqual(UpperCAmelCase							,					getattr(UpperCAmelCase							,					UpperCAmelCase    )    )







						def       lowerCamelCase__     (       self      :			Optional[Any]    ):
													CustomFeatureExtractor.register_for_auto_class()
													__lowerCamelCase					:		Optional[int]		   =     CustomFeatureExtractor.from_pretrained(UpperCAmelCase    )

													feature_extractor.push_to_hub("test-dynamic-feature-extractor"							,					use_auth_token=self._token    )

													# This has added the proper auto_map field to the config
													self.assertDictEqual(
													    feature_extractor.auto_map							,					{"AutoFeatureExtractor": "custom_feature_extraction.CustomFeatureExtractor"}							,					)

													__lowerCamelCase					:		Union[str, Any]		   =     AutoFeatureExtractor.from_pretrained(
													    F"""{USER}/test-dynamic-feature-extractor"""							,					trust_remote_code=UpperCAmelCase    )
													# Can't make an isinstance check because the new_feature_extractor is from the CustomFeatureExtractor class of a dynamic module
													self.assertEqual(new_feature_extractor.__class__.__name__							,					"CustomFeatureExtractor"    )
"""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.
__A  =				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_   (   _lowerCamelCase:	List[Any]      ) ->      Union[str, Any]:



							'''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_   (   _lowerCamelCase:	Union[str, Any]      ) ->      Any:



							'''simple docstring'''

							from transformers.testing_utils import pytest_addoption_shared

							pytest_addoption_shared(_lowerCamelCase      )


def    lowercase_   (   _lowerCamelCase:	Optional[int]      ) ->      Tuple:



							'''simple docstring'''

							from transformers.testing_utils import pytest_terminal_summary_main

							__lowerCamelCase					:		Any		   =     terminalreporter.config.getoption("--make-reports"      )
							if make_reports:
														pytest_terminal_summary_main(_lowerCamelCase						,   id=_lowerCamelCase      )


def    lowercase_   (   _lowerCamelCase:	Union[str, Any]						,   _lowerCamelCase:	Tuple      ) ->      Dict:



							'''simple docstring'''

							if exitstatus == 5:
														__lowerCamelCase					:		Optional[int]		   =     0


# Doctest custom flag to ignore output.
__A  =				doctest.register_optionflag('''IGNORE_RESULT''')

__A  =				doctest.OutputChecker
class  _snake_case     (					a__		):






						def       lowerCamelCase__     (       self      :			List[str]							,					UpperCAmelCase      :			int							,					UpperCAmelCase      :			Any							,					UpperCAmelCase      :			int    ):
													if IGNORE_RESULT & optionflags:
																				return True
													return OutputChecker.check_output(self							,					UpperCAmelCase							,					UpperCAmelCase							,					UpperCAmelCase    )

__A  =				CustomOutputChecker
__A  =				HfDoctestModule







__A  =				HfDocTestParser