



"""simple docstring"""

import json
import os
from pathlib import Path

import pytest

from datasets.download.download_config import DownloadConfig
from datasets.download.download_manager import DownloadManager
from datasets.utils.file_utils import hash_url_to_filename


lowercase__			   =  "http://www.mocksite.com/file1.txt"
lowercase__			   =  "\"text\": [\"foo\", \"foo\"]"
lowercase__			   =  "6d8ce9aa78a471c7477201efbeabd3bb01ac2e7d100a6dc024ba1608361f90a8"




class SCREAMING_SNAKE_CASE__					:
						_lowerCAmelCase							=					2_0_0
						_lowerCAmelCase							=					{"Content-Length": "100"}
						_lowerCAmelCase							=					{}



						def     lowerCAmelCase__(self						,     **_lowercase							):





													'''simple docstring'''

													return [bytes(_lowercase						,     """utf-8"""							)]







def       __magic_name__    (   *_lowerCamelCase				: str  ,       **_lowerCamelCase				: Any					):
							return MockResponse()





@pytest.mark.parametrize("""urls_type"""  ,       [str, list, dict]					)
def       __magic_name__    (   _lowerCamelCase				: List[Any]  ,       _lowerCamelCase				: Any  ,       _lowerCamelCase				: List[str]					):
							import requests

							monkeypatch.setattr(_lowerCamelCase  ,       """request"""  ,       _lowerCamelCase					)

							__a		:		List[str]									=       URL
							if issubclass(_lowerCamelCase  ,       _lowerCamelCase					):
														__a		:		int									=       url
							elif issubclass(_lowerCamelCase  ,       _lowerCamelCase					):
														__a		:		Tuple									=       [url]
							elif issubclass(_lowerCamelCase  ,       _lowerCamelCase					):
														__a		:		List[str]									=       {"""train""": url}
							__a		:		List[str]									=       """dummy"""
							__a		:		Any									=       """downloads"""
							__a		:		Union[str, Any]									=       tmp_path
							__a		:		str									=       DownloadConfig(
							    cache_dir=os.path.join(_lowerCamelCase  ,       _lowerCamelCase					)  ,       use_etag=_lowerCamelCase  ,       )
							__a		:		List[Any]									=       DownloadManager(dataset_name=_lowerCamelCase  ,       download_config=_lowerCamelCase					)
							__a		:		List[str]									=       dl_manager.download(_lowerCamelCase					)
							__a		:		str									=       urls
							for downloaded_paths in [downloaded_paths]:
														if isinstance(_lowerCamelCase  ,       _lowerCamelCase					):
																					__a		:		str									=       [downloaded_paths]
																					__a		:		Dict									=       [urls]
														elif isinstance(_lowerCamelCase  ,       _lowerCamelCase					):
																					assert "train" in downloaded_paths.keys()
																					__a		:		str									=       downloaded_paths.values()
																					__a		:		Union[str, Any]									=       urls.values()
														assert downloaded_paths
														for downloaded_path, input_url in zip(_lowerCamelCase  ,       _lowerCamelCase					):
																					assert downloaded_path == dl_manager.downloaded_paths[input_url]
																					__a		:		List[str]									=       Path(_lowerCamelCase					)
																					__a		:		int									=       downloaded_path.parts
																					assert parts[-1] == HASH
																					assert parts[-2] == cache_subdir
																					assert downloaded_path.exists()
																					__a		:		Any									=       downloaded_path.read_text()
																					assert content == CONTENT
																					__a		:		str									=       downloaded_path.with_suffix(""".json"""					)
																					assert metadata_downloaded_path.exists()
																					__a		:		Dict									=       json.loads(metadata_downloaded_path.read_text()					)
																					assert metadata_content == {"url": URL, "etag": None}





@pytest.mark.parametrize("""paths_type"""  ,       [str, list, dict]					)
def       __magic_name__    (   _lowerCamelCase				: Any  ,       _lowerCamelCase				: Optional[int]  ,       _lowerCamelCase				: str					):
							__a		:		Any									=       str(_lowerCamelCase					)
							if issubclass(_lowerCamelCase  ,       _lowerCamelCase					):
														__a		:		int									=       filename
							elif issubclass(_lowerCamelCase  ,       _lowerCamelCase					):
														__a		:		str									=       [filename]
							elif issubclass(_lowerCamelCase  ,       _lowerCamelCase					):
														__a		:		Tuple									=       {"""train""": filename}
							__a		:		Optional[int]									=       """dummy"""
							__a		:		List[str]									=       xz_file.parent
							__a		:		Union[str, Any]									=       """extracted"""
							__a		:		Optional[int]									=       DownloadConfig(
							    cache_dir=_lowerCamelCase  ,       use_etag=_lowerCamelCase  ,       )
							__a		:		int									=       DownloadManager(dataset_name=_lowerCamelCase  ,       download_config=_lowerCamelCase					)
							__a		:		str									=       dl_manager.extract(_lowerCamelCase					)
							__a		:		Dict									=       paths
							for extracted_paths in [extracted_paths]:
														if isinstance(_lowerCamelCase  ,       _lowerCamelCase					):
																					__a		:		str									=       [extracted_paths]
																					__a		:		int									=       [paths]
														elif isinstance(_lowerCamelCase  ,       _lowerCamelCase					):
																					assert "train" in extracted_paths.keys()
																					__a		:		List[str]									=       extracted_paths.values()
																					__a		:		Union[str, Any]									=       paths.values()
														assert extracted_paths
														for extracted_path, input_path in zip(_lowerCamelCase  ,       _lowerCamelCase					):
																					assert extracted_path == dl_manager.extracted_paths[input_path]
																					__a		:		Optional[int]									=       Path(_lowerCamelCase					)
																					__a		:		str									=       extracted_path.parts
																					assert parts[-1] == hash_url_to_filename(_lowerCamelCase  ,       etag=_lowerCamelCase					)
																					assert parts[-2] == extracted_subdir
																					assert extracted_path.exists()
																					__a		:		Optional[Any]									=       extracted_path.read_text()
																					__a		:		Tuple									=       text_file.read_text()
																					assert extracted_file_content == expected_file_content





def       __magic_name__    (   _lowerCamelCase				: Optional[int]  ,       _lowerCamelCase				: str					):
							assert path.endswith(""".jsonl"""					)
							for num_items, line in enumerate(_lowerCamelCase  ,       start=1					):
														__a		:		Dict									=       json.loads(line.decode("""utf-8"""					)					)
														assert item.keys() == {"col_1", "col_2", "col_3"}
							assert num_items == 4





@pytest.mark.parametrize("""archive_jsonl"""  ,       ["""tar_jsonl_path""", """zip_jsonl_path"""]					)
def       __magic_name__    (   _lowerCamelCase				: List[str]  ,       _lowerCamelCase				: List[Any]					):
							__a		:		Dict									=       request.getfixturevalue(_lowerCamelCase					)
							__a		:		Any									=       DownloadManager()
							for num_jsonl, (path, file) in enumerate(dl_manager.iter_archive(_lowerCamelCase					)  ,       start=1					):
														_test_jsonl(_lowerCamelCase  ,       _lowerCamelCase					)
							assert num_jsonl == 2





@pytest.mark.parametrize("""archive_nested_jsonl"""  ,       ["""tar_nested_jsonl_path""", """zip_nested_jsonl_path"""]					)
def       __magic_name__    (   _lowerCamelCase				: List[Any]  ,       _lowerCamelCase				: List[Any]					):
							__a		:		Dict									=       request.getfixturevalue(_lowerCamelCase					)
							__a		:		int									=       DownloadManager()
							for num_tar, (path, file) in enumerate(dl_manager.iter_archive(_lowerCamelCase					)  ,       start=1					):
														for num_jsonl, (subpath, subfile) in enumerate(dl_manager.iter_archive(_lowerCamelCase					)  ,       start=1					):
																					_test_jsonl(_lowerCamelCase  ,       _lowerCamelCase					)
							assert num_tar == 1
							assert num_jsonl == 2







def       __magic_name__    (   _lowerCamelCase				: Tuple					):
							__a		:		Optional[Any]									=       DownloadManager()
							for num_file, file in enumerate(dl_manager.iter_files(_lowerCamelCase					)  ,       start=1					):
														assert os.path.basename(_lowerCamelCase					) == ("test.txt" if num_file == 1 else "train.txt")
							assert num_file == 2






"""simple docstring"""

from manim import *




class SCREAMING_SNAKE_CASE__					(		__snake_case      ):



						def     lowerCAmelCase__(self							):





													'''simple docstring'''

													__a		:		List[str]									=       Rectangle(height=0.5						,     width=0.5							)
													__a		:		Union[str, Any]									=       Rectangle(height=0.25						,     width=0.25							)
													__a		:		Dict									=       Rectangle(height=0.46						,     width=0.46							).set_stroke(width=0							)

													__a		:		Dict									=       [mem.copy() for i in range(6							)]
													__a		:		str									=       [mem.copy() for i in range(6							)]
													__a		:		Tuple									=       VGroup(*_lowercase							).arrange(_lowercase						,     buff=0							)
													__a		:		List[Any]									=       VGroup(*_lowercase							).arrange(_lowercase						,     buff=0							)
													__a		:		List[Any]									=       VGroup(_lowercase						,     _lowercase							).arrange(_lowercase						,     buff=0							)
													__a		:		Union[str, Any]									=       Text("""CPU"""						,     font_size=24							)
													__a		:		Dict									=       Group(_lowercase						,     _lowercase							).arrange(_lowercase						,     buff=0.5						,     aligned_edge=_lowercase							)
													cpu.move_to([-2.5, -0.5, 0]							)
													self.add(_lowercase							)

													__a		:		Optional[Any]									=       [mem.copy() for i in range(4							)]
													__a		:		Dict									=       VGroup(*_lowercase							).arrange(_lowercase						,     buff=0							)
													__a		:		List[str]									=       Text("""GPU"""						,     font_size=24							)
													__a		:		Any									=       Group(_lowercase						,     _lowercase							).arrange(_lowercase						,     buff=0.5						,     aligned_edge=_lowercase							)
													gpu.move_to([-1, -1, 0]							)
													self.add(_lowercase							)

													__a		:		List[Any]									=       [mem.copy() for i in range(6							)]
													__a		:		Any									=       VGroup(*_lowercase							).arrange(_lowercase						,     buff=0							)

													__a		:		Optional[Any]									=       Text("""Model"""						,     font_size=24							)
													__a		:		Any									=       Group(_lowercase						,     _lowercase							).arrange(_lowercase						,     buff=0.5						,     aligned_edge=_lowercase							)
													model.move_to([3, -1.0, 0]							)
													self.add(_lowercase							)

													__a		:		Tuple									=       []
													__a		:		Tuple									=       []
													__a		:		Optional[int]									=       []

													for i, rect in enumerate(_lowercase							):
																				rect.set_stroke(_lowercase							)

																				__a		:		str									=       Rectangle(height=0.46 / 4						,     width=0.46 / 3							).set_stroke(width=0.0							).set_fill(_lowercase						,     opacity=0.7							)

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

													self.add(*_lowercase						,     *_lowercase						,     *_lowercase							)

													__a		:		Optional[Any]									=       [mem.copy() for i in range(6							)]
													__a		:		Union[str, Any]									=       VGroup(*_lowercase							).arrange(_lowercase						,     buff=0							)

													__a		:		Any									=       Text("""Loaded Checkpoint"""						,     font_size=24							)
													__a		:		str									=       Group(_lowercase						,     _lowercase							).arrange(_lowercase						,     buff=0.5						,     aligned_edge=_lowercase							)
													checkpoint.move_to([3, 0.5, 0]							)

													self.add(_lowercase							)

													__a		:		Dict									=       []
													__a		:		int									=       []

													for i, rect in enumerate(_lowercase							):
																				__a		:		List[str]									=       fill.copy().set_fill(_lowercase						,     opacity=0.7							)
																				target.move_to(_lowercase							)
																				ckpt_arr.append(_lowercase							)

																				__a		:		Union[str, Any]									=       target.copy()
																				if i < 5:
																											cpu_target.move_to(cpu_left_col_base[i + 1]							)
																				else:
																											cpu_target.move_to(cpu_right_col_base[i - 5]							)
																				ckpt_cpu_arr.append(_lowercase							)
													self.add(*_lowercase						,     *_lowercase							)

													__a		:		List[str]									=       Square(side_length=2.2							)
													key.move_to([-5, 2, 0]							)

													__a		:		List[Any]									=       MarkupText(
													    F'''<b>Key:</b>\n\n<span fgcolor=\'{YELLOW}\'>●</span> Empty Model'''						,     font_size=18						,     )

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

													self.add(_lowercase						,     _lowercase							)

													__a		:		str									=       MarkupText(
													    F'''<span fgcolor=\'{BLUE}\'>●</span> Checkpoint'''						,     font_size=18						,     )

													blue_text.next_to(_lowercase						,     DOWN * 2.4						,     aligned_edge=key_text.get_left()							)
													self.add(_lowercase							)

													__a		:		Optional[int]									=       MarkupText(
													    F'''Based on the passed in configuration, weights are stored in\na variety of np.memmaps on disk or to a particular device.'''						,     font_size=24						,     )
													step_a.move_to([2, 2, 0]							)

													__a		:		List[Any]									=       [meta_mem.copy() for i in range(6							)]
													__a		:		Optional[int]									=       [meta_mem.copy() for i in range(6							)]
													__a		:		List[Any]									=       VGroup(*_lowercase							).arrange(_lowercase						,     buff=0							)
													__a		:		List[str]									=       VGroup(*_lowercase							).arrange(_lowercase						,     buff=0							)
													__a		:		Tuple									=       VGroup(_lowercase						,     _lowercase							).arrange(_lowercase						,     buff=0							)
													__a		:		Dict									=       Text("""Disk"""						,     font_size=24							)
													__a		:		Dict									=       Group(_lowercase						,     _lowercase							).arrange(_lowercase						,     buff=0.5						,     aligned_edge=_lowercase							)
													disk.move_to([-4.0, -1.25, 0]							)
													self.play(Write(_lowercase						,     run_time=3							)						,     Write(_lowercase						,     run_time=1							)						,     Create(_lowercase						,     run_time=1							)							)

													__a		:		Optional[Any]									=       []
													for i, rect in enumerate(_lowercase							):
																				__a		:		List[str]									=       rect.copy()
																				target.generate_target()
																				target.target.move_to(disk_left_col_base[i]							).scale(0.5							)
																				animations.append(MoveToTarget(_lowercase						,     run_time=1.5							)							)
													self.play(*_lowercase							)

													self.play(FadeOut(_lowercase							)							)

													__a		:		List[str]									=       MarkupText(F'''Then, the checkpoint is removed from memory\nthrough garbage collection.'''						,     font_size=24							)
													step_a.move_to([2, 2, 0]							)

													self.play(Write(_lowercase						,     run_time=3							)							)

													self.play(
													    FadeOut(_lowercase						,     _lowercase						,     *_lowercase						,     *_lowercase							)						,     )

													self.wait()

