


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


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

_lowerCAmelCase  :		List[str]		     =	'file'

@pytest.fixture(scope='session'				)
def 			__UpperCamelCase    (    _A    :				Optional[int]				)    ->      Dict:




	"""simple docstring"""





	lowerCAmelCase					:    Union[str, Any]      							= tmp_path_factory.mktemp('data'				) / (FILE_PATH + '''.zstd''')
	lowerCAmelCase					:    Dict      							= bytes(__A					,   'utf-8'				)
	with zstd.open(__A					,   'wb'				) as f:
		f.write(__A				)
	return path

@pytest.fixture
def 			__UpperCamelCase    (    _A    :				Any				)    ->      int:




	"""simple docstring"""





	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 			__UpperCamelCase    (    _A    :				int					,   _A    :				int					,   _A    :				Any					,   _A    :				List[Any]					,   _A    :				Dict					,   _A    :				Tuple				)    ->      Dict:




	"""simple docstring"""





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




	"""simple docstring"""





	lowerCAmelCase					:    Dict      							= '''custom_cache'''
	lowerCAmelCase					:    int      							= '''custom_extracted_dir'''
	lowerCAmelCase					:    Optional[Any]      							= tmp_path / '''custom_extracted_path'''
	if default_extracted:
		lowerCAmelCase					:    Tuple      							= ('''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				)				)
		lowerCAmelCase					:    List[Any]      							= custom_extracted_path.parts[-2:] if default_cache_dir else (custom_cache_dir, custom_extracted_dir)

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

def 			__UpperCamelCase    (    _A    :				int				)    ->      Any:




	"""simple docstring"""





	lowerCAmelCase					:    Tuple      							= str(Path(__A				).resolve()				)
	assert cached_path(__A				) == text_file
	# relative path
	lowerCAmelCase					:    Optional[Any]      							= str(Path(__A				).resolve().relative_to(Path(os.getcwd()				)				)				)
	assert cached_path(__A				) == text_file

def 			__UpperCamelCase    (    _A    :				Union[str, Any]				)    ->      Optional[Any]:




	"""simple docstring"""





	lowerCAmelCase					:    Optional[int]      							= str(tmp_path.resolve() / '__missing_file__.txt'				)
	with pytest.raises(__A				):
		cached_path(__A				)
	# relative path
	lowerCAmelCase					:    List[str]      							= '''./__missing_file__.txt'''
	with pytest.raises(__A				):
		cached_path(__A				)

def 			__UpperCamelCase    (    _A    :				Optional[Any]				)    ->      Tuple:




	"""simple docstring"""





	lowerCAmelCase					:    Union[str, Any]      							= get_from_cache(F"tmp://{tmpfs_file}"				)
	with open(__A				) as f:
		lowerCAmelCase					:    Optional[int]      							= f.read()
	assert output_file_content == FILE_CONTENT

@patch('datasets.config.HF_DATASETS_OFFLINE'					,   __A				)
def 			__UpperCamelCase    (    )    ->      Dict:




	"""simple docstring"""





	with pytest.raises(__A				):
		cached_path('https://huggingface.co'				)

@patch('datasets.config.HF_DATASETS_OFFLINE'					,   __A				)
def 			__UpperCamelCase    (    _A    :				Tuple				)    ->      Optional[Any]:




	"""simple docstring"""





	lowerCAmelCase					:    Optional[int]      							= 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 			__UpperCamelCase    (    _A    :				Optional[int]				)    ->      Optional[Any]:




	"""simple docstring"""





	lowerCAmelCase					:    str      							= 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 			__UpperCamelCase    (    _A    :				List[str]				)    ->      Any:




	"""simple docstring"""





	lowerCAmelCase					:    Tuple      							= 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'''




import math

def 			__UpperCamelCase    (    _A    :				int = 1_00				)    ->      int:




	"""simple docstring"""





	lowerCAmelCase					:    List[Any]      							= sum(i * i for i in range(1					,   n + 1				)				)
	lowerCAmelCase					:    Optional[Any]      							= int(math.pow(sum(range(1					,   n + 1				)				)					,   2				)				)
	return square_of_sum - sum_of_squares


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