





import os
from pathlib import Path
from unittest.mock import patch

import pytest
import zstandard as zstd

from datasets.download.download_config import DownloadConfig
from datasets.utils.file_utils import (
    OfflineModeIsEnabled,
    cached_path,
    fsspec_get,
    fsspec_head,
    ftp_get,
    ftp_head,
    get_from_cache,
    http_get,
    http_head,
)


UpperCamelCase__     =	'''\
    Text data.
    Second line of data.'''

UpperCamelCase__     =	'''file'''





@pytest.fixture(scope="""session"""    )
def       _UpperCamelCase       (a__				:Any    ) ->    List[str]:






							"""simple docstring"""





							UpperCamelCase__			       =     tmp_path_factory.mktemp("""data"""    ) / (FILE_PATH + """.zstd""")
							UpperCamelCase__			       =     bytes(snake_case_				,     """utf-8"""    )
							with zstd.open(snake_case_				,     """wb"""    ) as f:
														f.write(snake_case_    )
							return path





@pytest.fixture
def       _UpperCamelCase       (a__				:Optional[Any]    ) ->    Any:






							"""simple docstring"""





							with open(os.path.join(tmpfs.local_root_dir				,     snake_case_    )				,     """w"""    ) as f:
														f.write(snake_case_    )
							return FILE_PATH





@pytest.mark.parametrize("""compression_format"""				,     ["""gzip""", """xz""", """zstd"""]    )
def       _UpperCamelCase       (a__				:Optional[Any]				,     a__				:Optional[int]				,     a__				:Optional[int]				,     a__				:List[Any]				,     a__				:str				,     a__				:str    ) ->    Dict:






							"""simple docstring"""





							UpperCamelCase__			       =     {"""gzip""": gz_file, """xz""": xz_file, """zstd""": zstd_path}
							UpperCamelCase__			       =     input_paths[compression_format]
							UpperCamelCase__			       =     tmp_path / """cache"""
							UpperCamelCase__			       =     DownloadConfig(cache_dir=snake_case_				,     extract_compressed_file=snake_case_    )
							UpperCamelCase__			       =     cached_path(snake_case_				,     download_config=snake_case_    )
							with open(snake_case_    ) as f:
														UpperCamelCase__			       =     f.read()
							with open(snake_case_    ) as f:
														UpperCamelCase__			       =     f.read()
							assert extracted_file_content == expected_file_content





@pytest.mark.parametrize("""default_extracted"""				,     [True, False]    )
@pytest.mark.parametrize("""default_cache_dir"""				,     [True, False]    )
def       _UpperCamelCase       (a__				:Optional[Any]				,     a__				:List[Any]				,     a__				:Optional[int]				,     a__				:Dict				,     a__				:int    ) ->    List[str]:






							"""simple docstring"""





							UpperCamelCase__			       =     """custom_cache"""
							UpperCamelCase__			       =     """custom_extracted_dir"""
							UpperCamelCase__			       =     tmp_path / """custom_extracted_path"""
							if default_extracted:
														UpperCamelCase__			       =     ("""downloads""" if default_cache_dir else custom_cache_dir, """extracted""")
							else:
														monkeypatch.setattr("""datasets.config.EXTRACTED_DATASETS_DIR"""				,     snake_case_    )
														monkeypatch.setattr("""datasets.config.EXTRACTED_DATASETS_PATH"""				,     str(snake_case_    )    )
														UpperCamelCase__			       =     custom_extracted_path.parts[-2:] if default_cache_dir else (custom_cache_dir, custom_extracted_dir)

							UpperCamelCase__			       =     xz_file
							UpperCamelCase__			       =     (
							    DownloadConfig(extract_compressed_file=snake_case_    )
							    if default_cache_dir
							    else DownloadConfig(cache_dir=tmp_path / custom_cache_dir				,     extract_compressed_file=snake_case_    )
							)
							UpperCamelCase__			       =     cached_path(snake_case_				,     download_config=snake_case_    )
							assert Path(snake_case_    ).parent.parts[-2:] == expected





def       _UpperCamelCase       (a__				:int    ) ->    Optional[Any]:






							"""simple docstring"""





							UpperCamelCase__			       =     str(Path(snake_case_    ).resolve()    )
							assert cached_path(snake_case_    ) == text_file
							# relative path
							UpperCamelCase__			       =     str(Path(snake_case_    ).resolve().relative_to(Path(os.getcwd()    )    )    )
							assert cached_path(snake_case_    ) == text_file





def       _UpperCamelCase       (a__				:Tuple    ) ->    Optional[int]:






							"""simple docstring"""





							UpperCamelCase__			       =     str(tmp_path.resolve() / """__missing_file__.txt"""    )
							with pytest.raises(snake_case_    ):
														cached_path(snake_case_    )
							# relative path
							UpperCamelCase__			       =     """./__missing_file__.txt"""
							with pytest.raises(snake_case_    ):
														cached_path(snake_case_    )





def       _UpperCamelCase       (a__				:str    ) ->    Optional[int]:






							"""simple docstring"""





							UpperCamelCase__			       =     get_from_cache(f"""tmp://{tmpfs_file}"""    )
							with open(snake_case_    ) as f:
														UpperCamelCase__			       =     f.read()
							assert output_file_content == FILE_CONTENT





@patch("""datasets.config.HF_DATASETS_OFFLINE"""				,     snake_case_    )
def       _UpperCamelCase       () ->    int:






							"""simple docstring"""





							with pytest.raises(snake_case_    ):
														cached_path("""https://huggingface.co"""    )





@patch("""datasets.config.HF_DATASETS_OFFLINE"""				,     snake_case_    )
def       _UpperCamelCase       (a__				:Any    ) ->    int:






							"""simple docstring"""





							UpperCamelCase__			       =     tmp_path_factory.mktemp("""data"""    ) / """file.html"""
							with pytest.raises(snake_case_    ):
														http_get("""https://huggingface.co"""				,     temp_file=snake_case_    )
							with pytest.raises(snake_case_    ):
														http_head("""https://huggingface.co"""    )





@patch("""datasets.config.HF_DATASETS_OFFLINE"""				,     snake_case_    )
def       _UpperCamelCase       (a__				:Union[str, Any]    ) ->    Optional[int]:






							"""simple docstring"""





							UpperCamelCase__			       =     tmp_path_factory.mktemp("""data"""    ) / """file.html"""
							with pytest.raises(snake_case_    ):
														ftp_get("""ftp://huggingface.co"""				,     temp_file=snake_case_    )
							with pytest.raises(snake_case_    ):
														ftp_head("""ftp://huggingface.co"""    )





@patch("""datasets.config.HF_DATASETS_OFFLINE"""				,     snake_case_    )
def       _UpperCamelCase       (a__				:Any    ) ->    List[str]:






							"""simple docstring"""





							UpperCamelCase__			       =     tmp_path_factory.mktemp("""data"""    ) / """file.html"""
							with pytest.raises(snake_case_    ):
														fsspec_get("""s3://huggingface.co"""				,     temp_file=snake_case_    )
							with pytest.raises(snake_case_    ):
														fsspec_head("""s3://huggingface.co"""    )











from ...configuration_utils import PretrainedConfig
from ...utils import logging


UpperCamelCase__     =	logging.get_logger(__name__)

UpperCamelCase__     =	{
    "facebook/s2t-wav2vec2-large-en-de": (
        "https://huggingface.co/facebook/s2t-wav2vec2-large-en-de/resolve/main/config.json"
    ),
    # See all Speech2Text models at https://huggingface.co/models?filter=speech2text2
}

class     __SCREAMING_SNAKE_CASE   (       _a    ):
							snake_case       : Dict         =    """speech_to_text_2"""
							snake_case       : List[Any]         =    ["""past_key_values"""]
							snake_case       : List[str]         =    {"""num_attention_heads""": """decoder_attention_heads""", """hidden_size""": """d_model"""}






							def __init__(  self					,	__lowerCAmelCase=10000					,	__lowerCAmelCase=6					,	__lowerCAmelCase=2048					,	__lowerCAmelCase=4					,	__lowerCAmelCase=0.0					,	__lowerCAmelCase=True					,	__lowerCAmelCase="relu"					,	__lowerCAmelCase=256					,	__lowerCAmelCase=0.1					,	__lowerCAmelCase=0.0					,	__lowerCAmelCase=0.0					,	__lowerCAmelCase=0.02					,	__lowerCAmelCase=2					,	__lowerCAmelCase=True					,	__lowerCAmelCase=1					,	__lowerCAmelCase=0					,	__lowerCAmelCase=2					,	__lowerCAmelCase=1024					,	**__lowerCAmelCase					,	):
														UpperCamelCase__			       =     vocab_size
														UpperCamelCase__			       =     d_model
														UpperCamelCase__			       =     decoder_ffn_dim
														UpperCamelCase__			       =     decoder_layers
														UpperCamelCase__			       =     decoder_attention_heads
														UpperCamelCase__			       =     dropout
														UpperCamelCase__			       =     attention_dropout
														UpperCamelCase__			       =     activation_dropout
														UpperCamelCase__			       =     activation_function
														UpperCamelCase__			       =     init_std
														UpperCamelCase__			       =     decoder_layerdrop
														UpperCamelCase__			       =     use_cache
														UpperCamelCase__			       =     decoder_layers
														UpperCamelCase__			       =     scale_embedding  # scale factor will be sqrt(d_model) if True
														UpperCamelCase__			       =     max_target_positions

														super().__init__(
														    pad_token_id=__lowerCAmelCase					,	bos_token_id=__lowerCAmelCase					,	eos_token_id=__lowerCAmelCase					,	decoder_start_token_id=__lowerCAmelCase					,	**__lowerCAmelCase					,	)




