



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


lowercase__					:						str												=						'''\
    Text data.
    Second line of data.'''

lowercase__					:						Any												=						'''file'''




@pytest.fixture(scope='''session'''					)
def __lowercase    (							_a					):
    snake_case_				:  List[str]       =			tmp_path_factory.mktemp('''data'''					) / (FILE_PATH + '''.zstd''')
    snake_case_				:  Optional[Any]       =			bytes(_a	,    '''utf-8'''					)
    with zstd.open(_a	,    '''wb'''					) as f:
        f.write(_a					)
    return path




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




@pytest.mark.parametrize('''compression_format'''	,    ['''gzip''', '''xz''', '''zstd''']					)
def __lowercase    (							_a	,    _a	,    _a	,    _a	,    _a	,    _a					):
    snake_case_				:  str       =			{'''gzip''': gz_file, '''xz''': xz_file, '''zstd''': zstd_path}
    snake_case_				:  Optional[int]       =			input_paths[compression_format]
    snake_case_				:  Tuple       =			tmp_path / '''cache'''
    snake_case_				:  str       =			DownloadConfig(cache_dir=_a	,    extract_compressed_file=_a					)
    snake_case_				:  int       =			cached_path(_a	,    download_config=_a					)
    with open(_a					) as f:
        snake_case_				:  Optional[Any]       =			f.read()
    with open(_a					) as f:
        snake_case_				:  Tuple       =			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 __lowercase    (							_a	,    _a	,    _a	,    _a	,    _a					):
    snake_case_				:  List[str]       =			'''custom_cache'''
    snake_case_				:  Dict       =			'''custom_extracted_dir'''
    snake_case_				:  str       =			tmp_path / '''custom_extracted_path'''
    if default_extracted:
        snake_case_				:  str       =			('''downloads''' if default_cache_dir else custom_cache_dir, '''extracted''')
    else:
        monkeypatch.setattr('''datasets.config.EXTRACTED_DATASETS_DIR'''	,    _a					)
        monkeypatch.setattr('''datasets.config.EXTRACTED_DATASETS_PATH'''	,    str(_a					)					)
        snake_case_				:  Union[str, Any]       =			custom_extracted_path.parts[-2:] if default_cache_dir else (custom_cache_dir, custom_extracted_dir)

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




def __lowercase    (							_a					):
    # absolute path
    snake_case_				:  Any       =			str(Path(_a					).resolve()					)
    assert cached_path(_a					) == text_file
    # relative path
    snake_case_				:  Optional[Any]       =			str(Path(_a					).resolve().relative_to(Path(os.getcwd()					)					)					)
    assert cached_path(_a					) == text_file




def __lowercase    (							_a					):
    # absolute path
    snake_case_				:  Dict       =			str(tmp_path.resolve() / '''__missing_file__.txt'''					)
    with pytest.raises(_a					):
        cached_path(_a					)
    # relative path
    snake_case_				:  int       =			'''./__missing_file__.txt'''
    with pytest.raises(_a					):
        cached_path(_a					)




def __lowercase    (							_a					):
    snake_case_				:  Optional[int]       =			get_from_cache(f"tmp://{tmpfs_file}"					)
    with open(_a					) as f:
        snake_case_				:  Tuple       =			f.read()
    assert output_file_content == FILE_CONTENT




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




@patch('''datasets.config.HF_DATASETS_OFFLINE'''	,    _a					)
def __lowercase    (							_a					):
    snake_case_				:  List[str]       =			tmp_path_factory.mktemp('''data'''					) / '''file.html'''
    with pytest.raises(_a					):
        http_get('''https://huggingface.co'''	,    temp_file=_a					)
    with pytest.raises(_a					):
        http_head('''https://huggingface.co'''					)




@patch('''datasets.config.HF_DATASETS_OFFLINE'''	,    _a					)
def __lowercase    (							_a					):
    snake_case_				:  Optional[int]       =			tmp_path_factory.mktemp('''data'''					) / '''file.html'''
    with pytest.raises(_a					):
        ftp_get('''ftp://huggingface.co'''	,    temp_file=_a					)
    with pytest.raises(_a					):
        ftp_head('''ftp://huggingface.co'''					)






@patch('''datasets.config.HF_DATASETS_OFFLINE'''	,    _a					)
def __lowercase    (							_a					):
    snake_case_				:  Optional[int]       =			tmp_path_factory.mktemp('''data'''					) / '''file.html'''
    with pytest.raises(_a					):
        fsspec_get('''s3://huggingface.co'''	,    temp_file=_a					)
    with pytest.raises(_a					):
        fsspec_head('''s3://huggingface.co'''					)










"""simple docstring"""

from dataclasses import dataclass
from enum import Enum
from typing import List, Optional, Union

import numpy as np
import PIL
from PIL import Image

from ...utils import BaseOutput, is_torch_available, is_transformers_available




@dataclass
class  _UpperCAmelCase (    lowerCAmelCase__):
 _lowerCAmelCase     :    Union[List[PIL.Image.Image], np.ndarray]
 _lowerCAmelCase     :    Optional[List[bool]]


if is_transformers_available() and is_torch_available():
     from .pipeline_semantic_stable_diffusion import SemanticStableDiffusionPipeline





