





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


a__							:							int ='''\\n    Text data.\n    Second line of data.'''

a__							:							Optional[Any] ='''file'''
@pytest.fixture(scope='session'     )
def 				lowercase__   (   __lowercase						:  Optional[int]     ) ->      str:



       """simple docstring"""






       __UpperCamelCase       =  tmp_path_factory.mktemp('data'     ) / (FILE_PATH + '.zstd')
       __UpperCamelCase       =  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 				lowercase__   (   __lowercase						:  int     ) ->      List[Any]:



       """simple docstring"""






       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 				lowercase__   (   __lowercase						:  Dict				,  __lowercase						:  Dict				,  __lowercase						:  List[str]				,  __lowercase						:  Dict				,  __lowercase						:  Dict				,  __lowercase						:  Any     ) ->      Optional[int]:



       """simple docstring"""






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



       """simple docstring"""






       __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'				,  SCREAMING_SNAKE_CASE__     )
              monkeypatch.setattr('datasets.config.EXTRACTED_DATASETS_PATH'				,  str(SCREAMING_SNAKE_CASE__     )     )
              __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=SCREAMING_SNAKE_CASE__     )
           if default_cache_dir
           else DownloadConfig(cache_dir=tmp_path / custom_cache_dir				,  extract_compressed_file=SCREAMING_SNAKE_CASE__     )
       )
       __UpperCamelCase       =  cached_path(SCREAMING_SNAKE_CASE__				,  download_config=SCREAMING_SNAKE_CASE__     )
       assert Path(SCREAMING_SNAKE_CASE__     ).parent.parts[-2:] == expected
def 				lowercase__   (   __lowercase						:  Optional[Any]     ) ->      Dict:



       """simple docstring"""






       __UpperCamelCase       =  str(Path(SCREAMING_SNAKE_CASE__     ).resolve()     )
       assert cached_path(SCREAMING_SNAKE_CASE__     ) == text_file
       # relative path
       __UpperCamelCase       =  str(Path(SCREAMING_SNAKE_CASE__     ).resolve().relative_to(Path(os.getcwd()     )     )     )
       assert cached_path(SCREAMING_SNAKE_CASE__     ) == text_file
def 				lowercase__   (   __lowercase						:  List[Any]     ) ->      Any:



       """simple docstring"""






       __UpperCamelCase       =  str(tmp_path.resolve() / '__missing_file__.txt'     )
       with pytest.raises(SCREAMING_SNAKE_CASE__     ):
              cached_path(SCREAMING_SNAKE_CASE__     )
       # relative path
       __UpperCamelCase       =  './__missing_file__.txt'
       with pytest.raises(SCREAMING_SNAKE_CASE__     ):
              cached_path(SCREAMING_SNAKE_CASE__     )
def 				lowercase__   (   __lowercase						:  str     ) ->      Tuple:



       """simple docstring"""






       __UpperCamelCase       =  get_from_cache(F'''tmp://{tmpfs_file}'''     )
       with open(SCREAMING_SNAKE_CASE__     ) as f:
              __UpperCamelCase       =  f.read()
       assert output_file_content == FILE_CONTENT
@patch('datasets.config.HF_DATASETS_OFFLINE'				,  SCREAMING_SNAKE_CASE__     )
def 				lowercase__   (   ) ->      Optional[Any]:



       """simple docstring"""






       with pytest.raises(SCREAMING_SNAKE_CASE__     ):
              cached_path('https://huggingface.co'     )
@patch('datasets.config.HF_DATASETS_OFFLINE'				,  SCREAMING_SNAKE_CASE__     )
def 				lowercase__   (   __lowercase						:  List[str]     ) ->      List[Any]:



       """simple docstring"""






       __UpperCamelCase       =  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 				lowercase__   (   __lowercase						:  str     ) ->      Tuple:



       """simple docstring"""






       __UpperCamelCase       =  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 				lowercase__   (   __lowercase						:  Dict     ) ->      Any:



       """simple docstring"""






       __UpperCamelCase       =  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'     )




def 						_UpperCAmelCase				(			SCREAMING_SNAKE_CASE__			:					int = 10**12				):
     __UpperCamelCase    							=1
     __UpperCamelCase    							=0

     __UpperCamelCase    							=1
     __UpperCamelCase    							=1

     while numerator <= 2 * min_total - 1:
          prev_numerator += 2 * numerator
          numerator += 2 * prev_numerator

          prev_denominator += 2 * denominator
          denominator += 2 * prev_denominator

     return (denominator + 1) // 2


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





