"""simple docstring"""






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,
)


lowerCAmelCase__  :  str						     =	'\\n    Text data.\n    Second line of data.'

lowerCAmelCase__  :  List[Any]						     =	'file'



@pytest.fixture(scope='session'       )
def   a_						(					lowerCamelCase       ):
				UpperCAmelCase__             =							tmp_path_factory.mktemp('data'       ) / (FILE_PATH + '.zstd')
				UpperCAmelCase__             =							bytes(lowerCamelCase					,			'utf-8'       )
				with zstd.open(lowerCamelCase					,			'wb'       ) as f:
								f.write(lowerCamelCase       )
				return path



@pytest.fixture
def   a_						(					lowerCamelCase       ):
				with open(os.path.join(tmpfs.local_root_dir					,			lowerCamelCase       )					,			'w'       ) as f:
								f.write(lowerCamelCase       )
				return FILE_PATH



@pytest.mark.parametrize('compression_format'					,			['gzip', 'xz', 'zstd']       )
def   a_						(					lowerCamelCase					,			lowerCamelCase					,			lowerCamelCase					,			lowerCamelCase					,			lowerCamelCase					,			lowerCamelCase       ):
				UpperCAmelCase__             =							{'gzip': gz_file, 'xz': xz_file, 'zstd': zstd_path}
				UpperCAmelCase__             =							input_paths[compression_format]
				UpperCAmelCase__             =							tmp_path / 'cache'
				UpperCAmelCase__             =							DownloadConfig(cache_dir=lowerCamelCase					,			extract_compressed_file=lowerCamelCase       )
				UpperCAmelCase__             =							cached_path(lowerCamelCase					,			download_config=lowerCamelCase       )
				with open(lowerCamelCase       ) as f:
								UpperCAmelCase__             =							f.read()
				with open(lowerCamelCase       ) 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   a_						(					lowerCamelCase					,			lowerCamelCase					,			lowerCamelCase					,			lowerCamelCase					,			lowerCamelCase       ):
				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'					,			lowerCamelCase       )
								monkeypatch.setattr('datasets.config.EXTRACTED_DATASETS_PATH'					,			str(lowerCamelCase       )       )
								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=lowerCamelCase       )
				    if default_cache_dir
				    else DownloadConfig(cache_dir=tmp_path / custom_cache_dir					,			extract_compressed_file=lowerCamelCase       )
				)
				UpperCAmelCase__             =							cached_path(lowerCamelCase					,			download_config=lowerCamelCase       )
				assert Path(lowerCamelCase       ).parent.parts[-2:] == expected



def   a_						(					lowerCamelCase       ):
				# absolute path
				UpperCAmelCase__             =							str(Path(lowerCamelCase       ).resolve()       )
				assert cached_path(lowerCamelCase       ) == text_file
				# relative path
				UpperCAmelCase__             =							str(Path(lowerCamelCase       ).resolve().relative_to(Path(os.getcwd()       )       )       )
				assert cached_path(lowerCamelCase       ) == text_file



def   a_						(					lowerCamelCase       ):
				# absolute path
				UpperCAmelCase__             =							str(tmp_path.resolve() / '__missing_file__.txt'       )
				with pytest.raises(lowerCamelCase       ):
								cached_path(lowerCamelCase       )
				# relative path
				UpperCAmelCase__             =							'./__missing_file__.txt'
				with pytest.raises(lowerCamelCase       ):
								cached_path(lowerCamelCase       )



def   a_						(					lowerCamelCase       ):
				UpperCAmelCase__             =							get_from_cache(f'''tmp://{tmpfs_file}'''       )
				with open(lowerCamelCase       ) as f:
								UpperCAmelCase__             =							f.read()
				assert output_file_content == FILE_CONTENT



@patch('datasets.config.HF_DATASETS_OFFLINE'					,			lowerCamelCase       )
def   a_						(					):
				with pytest.raises(lowerCamelCase       ):
								cached_path('https://huggingface.co'       )



@patch('datasets.config.HF_DATASETS_OFFLINE'					,			lowerCamelCase       )
def   a_						(					lowerCamelCase       ):
				UpperCAmelCase__             =							tmp_path_factory.mktemp('data'       ) / 'file.html'
				with pytest.raises(lowerCamelCase       ):
								http_get('https://huggingface.co'					,			temp_file=lowerCamelCase       )
				with pytest.raises(lowerCamelCase       ):
								http_head('https://huggingface.co'       )



@patch('datasets.config.HF_DATASETS_OFFLINE'					,			lowerCamelCase       )
def   a_						(					lowerCamelCase       ):
				UpperCAmelCase__             =							tmp_path_factory.mktemp('data'       ) / 'file.html'
				with pytest.raises(lowerCamelCase       ):
								ftp_get('ftp://huggingface.co'					,			temp_file=lowerCamelCase       )
				with pytest.raises(lowerCamelCase       ):
								ftp_head('ftp://huggingface.co'       )







@patch('datasets.config.HF_DATASETS_OFFLINE'					,			lowerCamelCase       )
def   a_						(					lowerCamelCase       ):
				UpperCAmelCase__             =							tmp_path_factory.mktemp('data'       ) / 'file.html'
				with pytest.raises(lowerCamelCase       ):
								fsspec_get('s3://huggingface.co'					,			temp_file=lowerCamelCase       )
				with pytest.raises(lowerCamelCase       ):
								fsspec_head('s3://huggingface.co'       )




"""simple docstring"""






from typing import TYPE_CHECKING

from ....utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available


lowerCAmelCase__  :  str						     =	{
    'configuration_mctct': ['MCTCT_PRETRAINED_CONFIG_ARCHIVE_MAP', 'MCTCTConfig'],
    'feature_extraction_mctct': ['MCTCTFeatureExtractor'],
    'processing_mctct': ['MCTCTProcessor'],
}


try:
						if not is_torch_available():
												raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
						pass
else:
						lowerCAmelCase__  :  Any						     =	[
						    'MCTCT_PRETRAINED_MODEL_ARCHIVE_LIST',
						    'MCTCTForCTC',
						    'MCTCTModel',
						    'MCTCTPreTrainedModel',
						]


if TYPE_CHECKING:
						from .configuration_mctct import MCTCT_PRETRAINED_CONFIG_ARCHIVE_MAP, MCTCTConfig
						from .feature_extraction_mctct import MCTCTFeatureExtractor
						from .processing_mctct import MCTCTProcessor

						try:
												if not is_torch_available():
																		raise OptionalDependencyNotAvailable()
						except OptionalDependencyNotAvailable:
												pass
						else:
												from .modeling_mctct import MCTCT_PRETRAINED_MODEL_ARCHIVE_LIST, MCTCTForCTC, MCTCTModel, MCTCTPreTrainedModel

else:
						import sys

						lowerCAmelCase__  :  Any						     =	_LazyModule(__name__, globals()['__file__'], _import_structure, module_spec=__spec__)



