




'''simple docstring'''







def 						snake_case_							(_a	:							int     ):
    if not isinstance(_a    ,   _a     ):
        raise ValueError('''Input must be an integer'''     )
    if input_num <= 0:
        raise ValueError('''Input must be positive'''     )
    return sum(
        divisor for divisor in range(1    ,   input_num // 2 + 1     ) if input_num % divisor == 0     )


if __name__ == "__main__":
   import doctest

   doctest.testmod()









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


__snake_case						:List[str]      		=     '''\
    Text data.
    Second line of data.'''

__snake_case						:Optional[Any]      		=     '''file'''





@pytest.fixture(scope='''session'''				)
def      __snake_case	(			_UpperCAmelCase				):
    __a						       =				tmp_path_factory.mktemp('''data'''				) / (FILE_PATH + '''.zstd''')
    __a						       =				bytes(_UpperCAmelCase   , '''utf-8'''				)
    with zstd.open(_UpperCAmelCase   , '''wb'''				) as f:
        f.write(_UpperCAmelCase				)
    return path





@pytest.fixture
def      __snake_case	(			_UpperCAmelCase				):
    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      __snake_case	(			_UpperCAmelCase   , _UpperCAmelCase   , _UpperCAmelCase   , _UpperCAmelCase   , _UpperCAmelCase   , _UpperCAmelCase				):
    __a						       =				{'''gzip''': gz_file, '''xz''': xz_file, '''zstd''': zstd_path}
    __a						       =				input_paths[compression_format]
    __a						       =				tmp_path / '''cache'''
    __a						       =				DownloadConfig(cache_dir=_UpperCAmelCase   , extract_compressed_file=_UpperCAmelCase				)
    __a						       =				cached_path(_UpperCAmelCase   , download_config=_UpperCAmelCase				)
    with open(_UpperCAmelCase				) as f:
        __a						       =				f.read()
    with open(_UpperCAmelCase				) as f:
        __a						       =				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      __snake_case	(			_UpperCAmelCase   , _UpperCAmelCase   , _UpperCAmelCase   , _UpperCAmelCase   , _UpperCAmelCase				):
    __a						       =				'''custom_cache'''
    __a						       =				'''custom_extracted_dir'''
    __a						       =				tmp_path / '''custom_extracted_path'''
    if default_extracted:
        __a						       =				('''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				)				)
        __a						       =				custom_extracted_path.parts[-2:] if default_cache_dir else (custom_cache_dir, custom_extracted_dir)

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





def      __snake_case	(			_UpperCAmelCase				):
    # absolute path
    __a						       =				str(Path(_UpperCAmelCase				).resolve()				)
    assert cached_path(_UpperCAmelCase				) == text_file
    # relative path
    __a						       =				str(Path(_UpperCAmelCase				).resolve().relative_to(Path(os.getcwd()				)				)				)
    assert cached_path(_UpperCAmelCase				) == text_file





def      __snake_case	(			_UpperCAmelCase				):
    # absolute path
    __a						       =				str(tmp_path.resolve() / '''__missing_file__.txt'''				)
    with pytest.raises(_UpperCAmelCase				):
        cached_path(_UpperCAmelCase				)
    # relative path
    __a						       =				'''./__missing_file__.txt'''
    with pytest.raises(_UpperCAmelCase				):
        cached_path(_UpperCAmelCase				)





def      __snake_case	(			_UpperCAmelCase				):
    __a						       =				get_from_cache(f'tmp://{tmpfs_file}'				)
    with open(_UpperCAmelCase				) as f:
        __a						       =				f.read()
    assert output_file_content == FILE_CONTENT





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





@patch('''datasets.config.HF_DATASETS_OFFLINE'''   , _UpperCAmelCase				)
def      __snake_case	(			_UpperCAmelCase				):
    __a						       =				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      __snake_case	(			_UpperCAmelCase				):
    __a						       =				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      __snake_case	(			_UpperCAmelCase				):
    __a						       =				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'''				)





