


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


lowercase   :						Optional[Any]								=			'\\n    Text data.\n    Second line of data.'

lowercase   :						Union[str, Any]								=			'file'
@pytest.fixture(scope="session"       )
def      __a	(							A__       )						->			int:
  lowerCAmelCase											=	tmp_path_factory.mktemp("data"       ) / (FILE_PATH + ".zstd")
  lowerCAmelCase											=	bytes(UpperCamelCase__						,       "utf-8"       )
  with zstd.open(UpperCamelCase__						,       "wb"       ) as f:
    f.write(UpperCamelCase__       )
  return path
@pytest.fixture
def      __a	(							A__       )						->			Any:







  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      __a	(							A__						,       A__						,       A__						,       A__						,       A__						,       A__       )						->			Tuple:
  lowerCAmelCase											=	{"gzip": gz_file, "xz": xz_file, "zstd": zstd_path}
  lowerCAmelCase											=	input_paths[compression_format]
  lowerCAmelCase											=	tmp_path / "cache"
  lowerCAmelCase											=	DownloadConfig(cache_dir=UpperCamelCase__						,       extract_compressed_file=UpperCamelCase__       )
  lowerCAmelCase											=	cached_path(UpperCamelCase__						,       download_config=UpperCamelCase__       )
  with open(UpperCamelCase__       ) as f:
    lowerCAmelCase											=	f.read()
  with open(UpperCamelCase__       ) as f:
    lowerCAmelCase											=	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      __a	(							A__						,       A__						,       A__						,       A__						,       A__       )						->			Dict:
  lowerCAmelCase											=	"custom_cache"
  lowerCAmelCase											=	"custom_extracted_dir"
  lowerCAmelCase											=	tmp_path / "custom_extracted_path"
  if default_extracted:
    lowerCAmelCase											=	("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__       )       )
    lowerCAmelCase											=	custom_extracted_path.parts[-2:] if default_cache_dir else (custom_cache_dir, custom_extracted_dir)

  lowerCAmelCase											=	xz_file
  lowerCAmelCase											=	(
      DownloadConfig(extract_compressed_file=UpperCamelCase__       )
      if default_cache_dir
      else DownloadConfig(cache_dir=tmp_path / custom_cache_dir						,       extract_compressed_file=UpperCamelCase__       )
  )
  lowerCAmelCase											=	cached_path(UpperCamelCase__						,       download_config=UpperCamelCase__       )
  assert Path(UpperCamelCase__       ).parent.parts[-2:] == expected
def      __a	(							A__       )						->			Union[str, Any]:
  lowerCAmelCase											=	str(Path(UpperCamelCase__       ).resolve()       )
  assert cached_path(UpperCamelCase__       ) == text_file
  # relative path
  lowerCAmelCase											=	str(Path(UpperCamelCase__       ).resolve().relative_to(Path(os.getcwd()       )       )       )
  assert cached_path(UpperCamelCase__       ) == text_file
def      __a	(							A__       )						->			Dict:
  lowerCAmelCase											=	str(tmp_path.resolve() / "__missing_file__.txt"       )
  with pytest.raises(UpperCamelCase__       ):
    cached_path(UpperCamelCase__       )
  # relative path
  lowerCAmelCase											=	"./__missing_file__.txt"
  with pytest.raises(UpperCamelCase__       ):
    cached_path(UpperCamelCase__       )
def      __a	(							A__       )						->			int:
  lowerCAmelCase											=	get_from_cache(f"tmp://{tmpfs_file}"       )
  with open(UpperCamelCase__       ) as f:
    lowerCAmelCase											=	f.read()
  assert output_file_content == FILE_CONTENT
@patch("datasets.config.HF_DATASETS_OFFLINE"						,       UpperCamelCase__       )
def      __a	(							)						->			Dict:







  with pytest.raises(UpperCamelCase__       ):
    cached_path("https://huggingface.co"       )
@patch("datasets.config.HF_DATASETS_OFFLINE"						,       UpperCamelCase__       )
def      __a	(							A__       )						->			Optional[Any]:
  lowerCAmelCase											=	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      __a	(							A__       )						->			Dict:
  lowerCAmelCase											=	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      __a	(							A__       )						->			List[Any]:
  lowerCAmelCase											=	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"       )






"""simple docstring"""

def lowerCAmelCase_   (					UpperCamelCase__						:			list					, UpperCamelCase__						:			int					, UpperCamelCase__						:			int = 0					, UpperCamelCase__						:			int = 0			):






 """simple docstring"""







 __lowercase						=						right or len(UpperCamelCase__			) - 1
 if left > right:
  return -1
 elif list_data[left] == key:
  return left
 elif list_data[right] == key:
  return right
 else:
  return search(UpperCamelCase__					, UpperCamelCase__					, left + 1					, right - 1			)


if __name__ == "__main__":
       import doctest

       doctest.testmod()
