



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


_UpperCAmelCase     =			"""\
    Text data.
    Second line of data."""

_UpperCAmelCase     =			"""file"""





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





@pytest.fixture
def      __magic_name__				(							lowercase ):
   with open(os.path.join(tmpfs.local_root_dir							,			lowercase )							,			"""w""" ) as f:
      f.write(lowercase )
   return FILE_PATH





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

   SCREAMING_SNAKE_CASE_: str     			=xz_file
   SCREAMING_SNAKE_CASE_: Dict     			=(
       DownloadConfig(extract_compressed_file=lowercase )
       if default_cache_dir
       else DownloadConfig(cache_dir=tmp_path / custom_cache_dir							,			extract_compressed_file=lowercase )
   )
   SCREAMING_SNAKE_CASE_: int     			=cached_path(lowercase							,			download_config=lowercase )
   assert Path(lowercase ).parent.parts[-2:] == expected





def      __magic_name__				(							lowercase ):
   # absolute path
   SCREAMING_SNAKE_CASE_: Tuple     			=str(Path(lowercase ).resolve() )
   assert cached_path(lowercase ) == text_file
   # relative path
   SCREAMING_SNAKE_CASE_: Optional[int]     			=str(Path(lowercase ).resolve().relative_to(Path(os.getcwd() ) ) )
   assert cached_path(lowercase ) == text_file





def      __magic_name__				(							lowercase ):
   # absolute path
   SCREAMING_SNAKE_CASE_: str     			=str(tmp_path.resolve() / """__missing_file__.txt""" )
   with pytest.raises(lowercase ):
      cached_path(lowercase )
   # relative path
   SCREAMING_SNAKE_CASE_: Union[str, Any]     			="""./__missing_file__.txt"""
   with pytest.raises(lowercase ):
      cached_path(lowercase )





def      __magic_name__				(							lowercase ):
   SCREAMING_SNAKE_CASE_: Optional[Any]     			=get_from_cache(f'''tmp://{tmpfs_file}''' )
   with open(lowercase ) as f:
      SCREAMING_SNAKE_CASE_: int     			=f.read()
   assert output_file_content == FILE_CONTENT





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





@patch("""datasets.config.HF_DATASETS_OFFLINE"""							,			lowercase )
def      __magic_name__				(							lowercase ):
   SCREAMING_SNAKE_CASE_: str     			=tmp_path_factory.mktemp("""data""" ) / """file.html"""
   with pytest.raises(lowercase ):
      http_get("""https://huggingface.co"""							,			temp_file=lowercase )
   with pytest.raises(lowercase ):
      http_head("""https://huggingface.co""" )





@patch("""datasets.config.HF_DATASETS_OFFLINE"""							,			lowercase )
def      __magic_name__				(							lowercase ):
   SCREAMING_SNAKE_CASE_: Any     			=tmp_path_factory.mktemp("""data""" ) / """file.html"""
   with pytest.raises(lowercase ):
      ftp_get("""ftp://huggingface.co"""							,			temp_file=lowercase )
   with pytest.raises(lowercase ):
      ftp_head("""ftp://huggingface.co""" )





@patch("""datasets.config.HF_DATASETS_OFFLINE"""							,			lowercase )
def      __magic_name__				(							lowercase ):
   SCREAMING_SNAKE_CASE_: List[Any]     			=tmp_path_factory.mktemp("""data""" ) / """file.html"""
   with pytest.raises(lowercase ):
      fsspec_get("""s3://huggingface.co"""							,			temp_file=lowercase )
   with pytest.raises(lowercase ):
      fsspec_head("""s3://huggingface.co""" )








"""simple docstring"""
def      __magic_name__				(							lowercase ):
   return str(lowercase ) == str(lowercase )[::-1]





def      __magic_name__				(							lowercase ):
   return int(lowercase ) + int(str(lowercase )[::-1] )





def      __magic_name__				(							lowercase = 1_0000 ):
   SCREAMING_SNAKE_CASE_: List[str]     			=[]
   for num in range(1							,			lowercase ):
      SCREAMING_SNAKE_CASE_: List[Any]     			=0
      SCREAMING_SNAKE_CASE_: int     			=num
      while iterations < 50:
         SCREAMING_SNAKE_CASE_: Optional[Any]     			=sum_reverse(lowercase )
         iterations += 1
         if is_palindrome(lowercase ):
            break
      else:
         lychrel_nums.append(lowercase )
   return len(lowercase )


if __name__ == "__main__":
   print(f"""{solution() = }""")



