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


SCREAMING_SNAKE_CASE_            =    '''\
    Text data.
    Second line of data.'''

SCREAMING_SNAKE_CASE_            =    '''file'''




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






    """simple docstring"""




    UpperCAmelCase          =       tmp_path_factory.mktemp('data'			) / (FILE_PATH + '.zstd')
    UpperCAmelCase          =       bytes(lowerCAmelCase			,					'utf-8'			)
    with zstd.open(lowerCAmelCase			,					'wb'			) as f:
        f.write(lowerCAmelCase			)
    return path




@pytest.fixture
def      lowercase__    (       lowerCAmelCase					:       List[Any]			)			->   str:






    """simple docstring"""




    with open(os.path.join(tmpfs.local_root_dir			,					lowerCAmelCase			)			,					'w'			) as f:
        f.write(lowerCAmelCase			)
    return FILE_PATH




@pytest.mark.parametrize('compression_format'			,					['gzip', 'xz', 'zstd']			)
def      lowercase__    (       lowerCAmelCase					:       int			,					lowerCAmelCase					:       List[str]			,					lowerCAmelCase					:       str			,					lowerCAmelCase					:       List[str]			,					lowerCAmelCase					:       Optional[int]			,					lowerCAmelCase					:       int			)			->   Dict:






    """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=lowerCAmelCase			,					extract_compressed_file=lowerCAmelCase			)
    UpperCAmelCase          =       cached_path(lowerCAmelCase			,					download_config=lowerCAmelCase			)
    with open(lowerCAmelCase			) as f:
        UpperCAmelCase          =       f.read()
    with open(lowerCAmelCase			) 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__    (       lowerCAmelCase					:       Union[str, Any]			,					lowerCAmelCase					:       Union[str, Any]			,					lowerCAmelCase					:       List[str]			,					lowerCAmelCase					:       List[Any]			,					lowerCAmelCase					:       Tuple			)			->   Optional[int]:






    """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'			,					lowerCAmelCase			)
        monkeypatch.setattr('datasets.config.EXTRACTED_DATASETS_PATH'			,					str(lowerCAmelCase			)			)
        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=lowerCAmelCase			)
        if default_cache_dir
        else DownloadConfig(cache_dir=tmp_path / custom_cache_dir			,					extract_compressed_file=lowerCAmelCase			)
    )
    UpperCAmelCase          =       cached_path(lowerCAmelCase			,					download_config=lowerCAmelCase			)
    assert Path(lowerCAmelCase			).parent.parts[-2:] == expected




def      lowercase__    (       lowerCAmelCase					:       Any			)			->   Dict:






    """simple docstring"""




    UpperCAmelCase          =       str(Path(lowerCAmelCase			).resolve()			)
    assert cached_path(lowerCAmelCase			) == text_file
    # relative path
    UpperCAmelCase          =       str(Path(lowerCAmelCase			).resolve().relative_to(Path(os.getcwd()			)			)			)
    assert cached_path(lowerCAmelCase			) == text_file




def      lowercase__    (       lowerCAmelCase					:       Optional[Any]			)			->   Union[str, Any]:






    """simple docstring"""




    UpperCAmelCase          =       str(tmp_path.resolve() / '__missing_file__.txt'			)
    with pytest.raises(lowerCAmelCase			):
        cached_path(lowerCAmelCase			)
    # relative path
    UpperCAmelCase          =       './__missing_file__.txt'
    with pytest.raises(lowerCAmelCase			):
        cached_path(lowerCAmelCase			)




def      lowercase__    (       lowerCAmelCase					:       Union[str, Any]			)			->   Dict:






    """simple docstring"""




    UpperCAmelCase          =       get_from_cache(F"tmp://{tmpfs_file}"			)
    with open(lowerCAmelCase			) as f:
        UpperCAmelCase          =       f.read()
    assert output_file_content == FILE_CONTENT




@patch('datasets.config.HF_DATASETS_OFFLINE'			,					lowerCAmelCase			)
def      lowercase__    (       )			->   Dict:






    """simple docstring"""




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




@patch('datasets.config.HF_DATASETS_OFFLINE'			,					lowerCAmelCase			)
def      lowercase__    (       lowerCAmelCase					:       Tuple			)			->   List[str]:






    """simple docstring"""




    UpperCAmelCase          =       tmp_path_factory.mktemp('data'			) / 'file.html'
    with pytest.raises(lowerCAmelCase			):
        http_get('https://huggingface.co'			,					temp_file=lowerCAmelCase			)
    with pytest.raises(lowerCAmelCase			):
        http_head('https://huggingface.co'			)




@patch('datasets.config.HF_DATASETS_OFFLINE'			,					lowerCAmelCase			)
def      lowercase__    (       lowerCAmelCase					:       List[Any]			)			->   Optional[Any]:






    """simple docstring"""




    UpperCAmelCase          =       tmp_path_factory.mktemp('data'			) / 'file.html'
    with pytest.raises(lowerCAmelCase			):
        ftp_get('ftp://huggingface.co'			,					temp_file=lowerCAmelCase			)
    with pytest.raises(lowerCAmelCase			):
        ftp_head('ftp://huggingface.co'			)







@patch('datasets.config.HF_DATASETS_OFFLINE'			,					lowerCAmelCase			)
def      lowercase__    (       lowerCAmelCase					:       Tuple			)			->   Optional[int]:






    """simple docstring"""




    UpperCAmelCase          =       tmp_path_factory.mktemp('data'			) / 'file.html'
    with pytest.raises(lowerCAmelCase			):
        fsspec_get('s3://huggingface.co'			,					temp_file=lowerCAmelCase			)
    with pytest.raises(lowerCAmelCase			):
        fsspec_head('s3://huggingface.co'			)





"""simple docstring"""

from math import asin, atan, cos, radians, sin, sqrt, tan

SCREAMING_SNAKE_CASE_            =    6_3_7_8_1_3_7.0
SCREAMING_SNAKE_CASE_            =    6_3_5_6_7_5_2.3_1_4_2_4_5
SCREAMING_SNAKE_CASE_            =    637_8137




def      lowercase__    (       lowerCAmelCase					:       float			,					lowerCAmelCase					:       float			,					lowerCAmelCase					:       float			,					lowerCAmelCase					:       float			)			->   float:






    """simple docstring"""




    UpperCAmelCase          =       (AXIS_A - AXIS_B) / AXIS_A
    UpperCAmelCase          =       atan((1 - flattening) * tan(radians(lowerCAmelCase			)			)			)
    UpperCAmelCase          =       atan((1 - flattening) * tan(radians(lowerCAmelCase			)			)			)
    UpperCAmelCase          =       radians(lowerCAmelCase			)
    UpperCAmelCase          =       radians(lowerCAmelCase			)
    # Equation
    UpperCAmelCase          =       sin((phi_a - phi_a) / 2			)
    UpperCAmelCase          =       sin((lambda_a - lambda_a) / 2			)
    # Square both values
    sin_sq_phi *= sin_sq_phi
    sin_sq_lambda *= sin_sq_lambda
    UpperCAmelCase          =       sqrt(sin_sq_phi + (cos(lowerCAmelCase			) * cos(lowerCAmelCase			) * sin_sq_lambda)			)
    return 2 * RADIUS * asin(lowerCAmelCase			)


if __name__ == "__main__":
   import doctest

   doctest.testmod()



