


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


__magic_name__			=      '\\n    Text data.\n    Second line of data.'

__magic_name__			=      'file'




@pytest.fixture(scope="""session""")
def      lowerCamelCase					(      lowerCamelCase  :      Tuple):
      A_						:  Optional[int]          =				tmp_path_factory.mktemp("""data""") / (FILE_PATH + """.zstd""")
      A_						:  Optional[Any]          =				bytes(_SCREAMING_SNAKE_CASE							,						"""utf-8""")
      with zstd.open(_SCREAMING_SNAKE_CASE							,						"""wb""") as f:
            f.write(_SCREAMING_SNAKE_CASE)
      return path




@pytest.fixture
def      lowerCamelCase					(      lowerCamelCase  :      Optional[int]):
      with open(os.path.join(tmpfs.local_root_dir							,						_SCREAMING_SNAKE_CASE)							,						"""w""") as f:
            f.write(_SCREAMING_SNAKE_CASE)
      return FILE_PATH




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

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




def      lowerCamelCase					(      lowerCamelCase  :      Tuple):
      # absolute path
      A_						:  Tuple          =				str(Path(_SCREAMING_SNAKE_CASE).resolve())
      assert cached_path(_SCREAMING_SNAKE_CASE) == text_file
      # relative path
      A_						:  Union[str, Any]          =				str(Path(_SCREAMING_SNAKE_CASE).resolve().relative_to(Path(os.getcwd())))
      assert cached_path(_SCREAMING_SNAKE_CASE) == text_file




def      lowerCamelCase					(      lowerCamelCase  :      List[str]):
      # absolute path
      A_						:  str          =				str(tmp_path.resolve() / """__missing_file__.txt""")
      with pytest.raises(_SCREAMING_SNAKE_CASE):
            cached_path(_SCREAMING_SNAKE_CASE)
      # relative path
      A_						:  List[str]          =				"""./__missing_file__.txt"""
      with pytest.raises(_SCREAMING_SNAKE_CASE):
            cached_path(_SCREAMING_SNAKE_CASE)




def      lowerCamelCase					(      lowerCamelCase  :      Union[str, Any]):
      A_						:  Dict          =				get_from_cache(F'tmp://{tmpfs_file}')
      with open(_SCREAMING_SNAKE_CASE) as f:
            A_						:  List[str]          =				f.read()
      assert output_file_content == FILE_CONTENT




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




@patch("""datasets.config.HF_DATASETS_OFFLINE"""							,						_SCREAMING_SNAKE_CASE)
def      lowerCamelCase					(      lowerCamelCase  :      Any):
      A_						:  List[str]          =				tmp_path_factory.mktemp("""data""") / """file.html"""
      with pytest.raises(_SCREAMING_SNAKE_CASE):
            http_get("""https://huggingface.co"""							,						temp_file=_SCREAMING_SNAKE_CASE)
      with pytest.raises(_SCREAMING_SNAKE_CASE):
            http_head("""https://huggingface.co""")




@patch("""datasets.config.HF_DATASETS_OFFLINE"""							,						_SCREAMING_SNAKE_CASE)
def      lowerCamelCase					(      lowerCamelCase  :      int):
      A_						:  Dict          =				tmp_path_factory.mktemp("""data""") / """file.html"""
      with pytest.raises(_SCREAMING_SNAKE_CASE):
            ftp_get("""ftp://huggingface.co"""							,						temp_file=_SCREAMING_SNAKE_CASE)
      with pytest.raises(_SCREAMING_SNAKE_CASE):
            ftp_head("""ftp://huggingface.co""")






@patch("""datasets.config.HF_DATASETS_OFFLINE"""							,						_SCREAMING_SNAKE_CASE)
def      lowerCamelCase					(      lowerCamelCase  :      Optional[int]):
      A_						:  List[str]          =				tmp_path_factory.mktemp("""data""") / """file.html"""
      with pytest.raises(_SCREAMING_SNAKE_CASE):
            fsspec_get("""s3://huggingface.co"""							,						temp_file=_SCREAMING_SNAKE_CASE)
      with pytest.raises(_SCREAMING_SNAKE_CASE):
            fsspec_head("""s3://huggingface.co""")




'''simple docstring'''


from ..utils import DummyObject, requires_backends



class 	__lowerCAmelCase		(							metaclass=__SCREAMING_SNAKE_CASE    ):


  '''simple docstring'''







  a_  					=							["""torch""", """torchsde"""]






  def __init__(							self :       Any	,*_a :       Union[str, Any]	,**_a :       Optional[int] ):

        '''simple docstring'''




        requires_backends(self	,["""torch""", """torchsde"""] )






  @classmethod
  def        _a							(							cls :       Optional[int]	,*_a :       List[Any]	,**_a :       Any ):

        '''simple docstring'''




        requires_backends(cls	,["""torch""", """torchsde"""] )






  @classmethod
  def        _a							(							cls :       List[Any]	,*_a :       Tuple	,**_a :       Union[str, Any] ):

        '''simple docstring'''




        requires_backends(cls	,["""torch""", """torchsde"""] )
