





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 						lowerCamelCase__     (     UpperCamelCase__			:       Optional[Any]						)			-> Dict:



					'''simple docstring'''




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





@pytest.fixture
def 						lowerCamelCase__     (     UpperCamelCase__			:       Union[str, Any]						)			-> str:



					'''simple docstring'''




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





@pytest.mark.parametrize('compression_format'       ,    ['gzip', 'xz', 'zstd']						)
def 						lowerCamelCase__     (     UpperCamelCase__			:       Optional[Any]       ,    UpperCamelCase__			:       str       ,    UpperCamelCase__			:       Any       ,    UpperCamelCase__			:       Union[str, Any]       ,    UpperCamelCase__			:       List[str]       ,    UpperCamelCase__			:       Optional[Any]						)			-> List[Any]:



					'''simple docstring'''




					_snake_case									=				{'gzip': gz_file, 'xz': xz_file, 'zstd': zstd_path}
					_snake_case									=				input_paths[compression_format]
					_snake_case									=				tmp_path / 'cache'
					_snake_case									=				DownloadConfig(cache_dir=UpperCamelCase__       ,    extract_compressed_file=UpperCamelCase__						)
					_snake_case									=				cached_path(UpperCamelCase__       ,    download_config=UpperCamelCase__						)
					with open(UpperCamelCase__						) as f:
										_snake_case									=				f.read()
					with open(UpperCamelCase__						) as f:
										_snake_case									=				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 						lowerCamelCase__     (     UpperCamelCase__			:       List[str]       ,    UpperCamelCase__			:       Any       ,    UpperCamelCase__			:       List[Any]       ,    UpperCamelCase__			:       Any       ,    UpperCamelCase__			:       Tuple						)			-> Dict:



					'''simple docstring'''




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

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





def 						lowerCamelCase__     (     UpperCamelCase__			:       int						)			-> str:



					'''simple docstring'''




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





def 						lowerCamelCase__     (     UpperCamelCase__			:       Tuple						)			-> Union[str, Any]:



					'''simple docstring'''




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





def 						lowerCamelCase__     (     UpperCamelCase__			:       List[Any]						)			-> List[str]:



					'''simple docstring'''




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





@patch('datasets.config.HF_DATASETS_OFFLINE'       ,    UpperCamelCase__						)
def 						lowerCamelCase__     (     )			-> Union[str, Any]:



					'''simple docstring'''




					with pytest.raises(UpperCamelCase__						):
										cached_path('https://huggingface.co'						)





@patch('datasets.config.HF_DATASETS_OFFLINE'       ,    UpperCamelCase__						)
def 						lowerCamelCase__     (     UpperCamelCase__			:       Any						)			-> int:



					'''simple docstring'''




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





@patch('datasets.config.HF_DATASETS_OFFLINE'       ,    UpperCamelCase__						)
def 						lowerCamelCase__     (     UpperCamelCase__			:       Optional[Any]						)			-> str:



					'''simple docstring'''




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





@patch('datasets.config.HF_DATASETS_OFFLINE'       ,    UpperCamelCase__						)
def 						lowerCamelCase__     (     UpperCamelCase__			:       Tuple						)			-> Optional[Any]:



					'''simple docstring'''




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










from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available


UpperCAmelCase_      							=     {
    """configuration_bigbird_pegasus""": [
        """BIGBIRD_PEGASUS_PRETRAINED_CONFIG_ARCHIVE_MAP""",
        """BigBirdPegasusConfig""",
        """BigBirdPegasusOnnxConfig""",
    ],
}

try:
					if not is_torch_available():
										raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
					pass
else:
					UpperCAmelCase_      							=     [
					    """BIGBIRD_PEGASUS_PRETRAINED_MODEL_ARCHIVE_LIST""",
					    """BigBirdPegasusForCausalLM""",
					    """BigBirdPegasusForConditionalGeneration""",
					    """BigBirdPegasusForQuestionAnswering""",
					    """BigBirdPegasusForSequenceClassification""",
					    """BigBirdPegasusModel""",
					    """BigBirdPegasusPreTrainedModel""",
					]


if TYPE_CHECKING:
					from .configuration_bigbird_pegasus import (
					    BIGBIRD_PEGASUS_PRETRAINED_CONFIG_ARCHIVE_MAP,
					    BigBirdPegasusConfig,
					    BigBirdPegasusOnnxConfig,
					)

					try:
										if not is_torch_available():
															raise OptionalDependencyNotAvailable()
					except OptionalDependencyNotAvailable:
										pass
					else:
										from .modeling_bigbird_pegasus import (
										    BIGBIRD_PEGASUS_PRETRAINED_MODEL_ARCHIVE_LIST,
										    BigBirdPegasusForCausalLM,
										    BigBirdPegasusForConditionalGeneration,
										    BigBirdPegasusForQuestionAnswering,
										    BigBirdPegasusForSequenceClassification,
										    BigBirdPegasusModel,
										    BigBirdPegasusPreTrainedModel,
										)


else:
					import sys

					UpperCAmelCase_      							=     _LazyModule(__name__, globals()["""__file__"""], _import_structure, module_spec=__spec__)



