


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__				     =		"\\n    Text data.\n    Second line of data."

lowercase__				     =		"file"






@pytest.fixture(scope="session"				)
def __UpperCamelCase   (			__lowerCamelCase		: List[str]				)      ->     List[str]:







     '''simple docstring'''






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






@pytest.fixture
def __UpperCamelCase   (			__lowerCamelCase		: Optional[Any]				)      ->     Tuple:







     '''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 __UpperCamelCase   (			__lowerCamelCase		: Any      ,  __lowerCamelCase		: Any      ,  __lowerCamelCase		: int      ,  __lowerCamelCase		: Any      ,  __lowerCamelCase		: List[Any]      ,  __lowerCamelCase		: Optional[Any]				)      ->     str:







     '''simple docstring'''






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







     '''simple docstring'''






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






def __UpperCamelCase   (			__lowerCamelCase		: int				)      ->     Optional[int]:







     '''simple docstring'''






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






def __UpperCamelCase   (			__lowerCamelCase		: List[Any]				)      ->     Optional[Any]:







     '''simple docstring'''






     _a						=		str(tmp_path.resolve() / "__missing_file__.txt"				)
     with pytest.raises(lowerCAmelCase__				):
          cached_path(lowerCAmelCase__				)
     # relative path
     _a						=		"./__missing_file__.txt"
     with pytest.raises(lowerCAmelCase__				):
          cached_path(lowerCAmelCase__				)






def __UpperCamelCase   (			__lowerCamelCase		: Any				)      ->     Tuple:







     '''simple docstring'''






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






@patch("datasets.config.HF_DATASETS_OFFLINE"      ,  lowerCAmelCase__				)
def __UpperCamelCase   (			)      ->     Union[str, Any]:







     '''simple docstring'''






     with pytest.raises(lowerCAmelCase__				):
          cached_path("https://huggingface.co"				)






@patch("datasets.config.HF_DATASETS_OFFLINE"      ,  lowerCAmelCase__				)
def __UpperCamelCase   (			__lowerCamelCase		: str				)      ->     Optional[Any]:







     '''simple docstring'''






     _a						=		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 __UpperCamelCase   (			__lowerCamelCase		: str				)      ->     Any:







     '''simple docstring'''






     _a						=		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 __UpperCamelCase   (			__lowerCamelCase		: Any				)      ->     Dict:







     '''simple docstring'''






     _a						=		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 manim import *





class 						__SCREAMING_SNAKE_CASE					(      lowerCamelCase__ ):






     def  a_					(			self		)       ->    str:
          _a						=		Rectangle(height=0.5     ,							width=0.5		)
          _a						=		Rectangle(height=0.46     ,							width=0.46		).set_stroke(width=0		)

          _a						=		[mem.copy() for i in range(6		)]
          _a						=		[mem.copy() for i in range(6		)]
          _a						=		VGroup(*__UpperCamelCase		).arrange(__UpperCamelCase     ,							buff=0		)
          _a						=		VGroup(*__UpperCamelCase		).arrange(__UpperCamelCase     ,							buff=0		)
          _a						=		VGroup(__UpperCamelCase     ,							__UpperCamelCase		).arrange(__UpperCamelCase     ,							buff=0		)
          _a						=		Text("CPU"     ,							font_size=24		)
          _a						=		Group(__UpperCamelCase     ,							__UpperCamelCase		).arrange(__UpperCamelCase     ,							buff=0.5     ,							aligned_edge=__UpperCamelCase		)
          cpu.move_to([-2.5, -0.5, 0]		)
          self.add(__UpperCamelCase		)

          _a						=		[mem.copy() for i in range(1		)]
          _a						=		VGroup(*__UpperCamelCase		).arrange(__UpperCamelCase     ,							buff=0		)
          _a						=		Text("GPU"     ,							font_size=24		)
          _a						=		Group(__UpperCamelCase     ,							__UpperCamelCase		).arrange(__UpperCamelCase     ,							buff=0.5     ,							aligned_edge=__UpperCamelCase		)
          gpu.align_to(__UpperCamelCase     ,							__UpperCamelCase		)
          gpu.set_x(gpu.get_x() - 1		)

          self.add(__UpperCamelCase		)

          _a						=		[mem.copy() for i in range(6		)]
          _a						=		VGroup(*__UpperCamelCase		).arrange(__UpperCamelCase     ,							buff=0		)

          _a						=		Text("Model"     ,							font_size=24		)
          _a						=		Group(__UpperCamelCase     ,							__UpperCamelCase		).arrange(__UpperCamelCase     ,							buff=0.5     ,							aligned_edge=__UpperCamelCase		)
          model.move_to([3, -1.0, 0]		)

          self.play(
              Create(__UpperCamelCase     ,							run_time=1		)     ,							Create(__UpperCamelCase     ,							run_time=1		)     ,							Create(__UpperCamelCase     ,							run_time=1		)     ,							)

          _a						=		MarkupText(
              f"First, an empty model skeleton is loaded\ninto <span fgcolor='{YELLOW}'>memory</span> without using much RAM."     ,							font_size=24     ,							)

          _a						=		Square(side_length=2.2		)
          key.move_to([-5, 2, 0]		)

          _a						=		MarkupText(
              f"<b>Key:</b>\n\n<span fgcolor='{YELLOW}'>●</span> Empty Model"     ,							font_size=18     ,							)

          key_text.move_to([-5, 2.4, 0]		)

          step_a.move_to([2, 2, 0]		)
          self.play(Write(__UpperCamelCase     ,							run_time=2.5		)     ,							Write(__UpperCamelCase		)     ,							Write(__UpperCamelCase		)		)

          self.add(__UpperCamelCase		)

          _a						=		[]
          _a						=		[]
          _a						=		[]
          for i, rect in enumerate(__UpperCamelCase		):
               _a						=		Rectangle(height=0.46     ,							width=0.46		).set_stroke(width=0.0		).set_fill(__UpperCamelCase     ,							opacity=0.7		)
               cpu_target.move_to(__UpperCamelCase		)
               cpu_target.generate_target()
               _a						=		0.46 / 4
               _a						=		0.46 / 3

               if i == 0:
                    cpu_target.target.next_to(cpu_left_col_base[0].get_corner(DOWN + LEFT		)     ,							buff=0.02     ,							direction=__UpperCamelCase		)
                    cpu_target.target.set_x(cpu_target.target.get_x() + 0.1		)
               elif i == 3:
                    cpu_target.target.next_to(cpu_targs[0].target     ,							direction=__UpperCamelCase     ,							buff=0.0		)
               else:
                    cpu_target.target.next_to(cpu_targs[i - 1].target     ,							direction=__UpperCamelCase     ,							buff=0.0		)
               cpu_targs.append(__UpperCamelCase		)

               first_animations.append(rect.animate(run_time=0.5		).set_stroke(__UpperCamelCase		)		)
               second_animations.append(MoveToTarget(__UpperCamelCase     ,							run_time=1.5		)		)

          self.play(*__UpperCamelCase		)
          self.play(*__UpperCamelCase		)

          self.wait()

