

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


lowerCAmelCase__    :							List[Any]					    =    """http://www.mocksite.com/file1.txt"""
lowerCAmelCase__    :							Union[str, Any]					    =    """\"text\": [\"foo\", \"foo\"]"""
lowerCAmelCase__    :							Dict					    =    """6d8ce9aa78a471c7477201efbeabd3bb01ac2e7d100a6dc024ba1608361f90a8"""




class      a      :






						"""simple docstring"""




						__UpperCAmelCase        =     200
						__UpperCAmelCase        =     {"""Content-Length""": """100"""}
						__UpperCAmelCase        =     {}







						def    __magic_name__				(				self       :   Optional[int]      ,      **snake_case_       :   Any	):



								'''simple docstring'''



								return [bytes(snake_case_      ,      '''utf-8'''	)]





def 						_a							(					*__lowerCAmelCase		:   Optional[Any] ,				**__lowerCAmelCase		:   List[Any]  ):

		"""simple docstring"""

		return MockResponse()




@pytest.mark.parametrize('''urls_type''' ,				[str, list, dict]  )
def 						_a							(					__lowerCAmelCase		:   Dict ,				__lowerCAmelCase		:   Optional[int] ,				__lowerCAmelCase		:   Optional[Any]  ):

		"""simple docstring"""

		import requests

		monkeypatch.setattr(__a ,				'''request''' ,				__a  )

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




@pytest.mark.parametrize('''paths_type''' ,				[str, list, dict]  )
def 						_a							(					__lowerCAmelCase		:   Union[str, Any] ,				__lowerCAmelCase		:   List[Any] ,				__lowerCAmelCase		:   Union[str, Any]  ):

		"""simple docstring"""

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




def 						_a							(					__lowerCAmelCase		:   int ,				__lowerCAmelCase		:   int  ):

		"""simple docstring"""

		assert path.endswith('''.jsonl'''  )
		for num_items, line in enumerate(__a ,				start=1  ):
				snake_case__    :							Union[str, Any]							    =	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 						_a							(					__lowerCAmelCase		:   Any ,				__lowerCAmelCase		:   List[str]  ):

		"""simple docstring"""

		snake_case__    :							Union[str, Any]							    =	request.getfixturevalue(__a  )
		snake_case__    :							Optional[int]							    =	DownloadManager()
		for num_jsonl, (path, file) in enumerate(dl_manager.iter_archive(__a  ) ,				start=1  ):
				_test_jsonl(__a ,				__a  )
		assert num_jsonl == 2




@pytest.mark.parametrize('''archive_nested_jsonl''' ,				['''tar_nested_jsonl_path''', '''zip_nested_jsonl_path''']  )
def 						_a							(					__lowerCAmelCase		:   Tuple ,				__lowerCAmelCase		:   Union[str, Any]  ):

		"""simple docstring"""

		snake_case__    :							List[str]							    =	request.getfixturevalue(__a  )
		snake_case__    :							Any							    =	DownloadManager()
		for num_tar, (path, file) in enumerate(dl_manager.iter_archive(__a  ) ,				start=1  ):
				for num_jsonl, (subpath, subfile) in enumerate(dl_manager.iter_archive(__a  ) ,				start=1  ):
						_test_jsonl(__a ,				__a  )
		assert num_tar == 1
		assert num_jsonl == 2





def 						_a							(					__lowerCAmelCase		:   int  ):

		"""simple docstring"""

		snake_case__    :							Any							    =	DownloadManager()
		for num_file, file in enumerate(dl_manager.iter_files(__a  ) ,				start=1  ):
				assert os.path.basename(__a  ) == ("test.txt" if num_file == 1 else "train.txt")
		assert num_file == 2








"""simple docstring"""







def     UpperCAmelCase_					(				__a   :			int						):




			'''simple docstring'''



			_lowerCamelCase					:					Optional[Any]	       =    int(__a						)
			if decimal in (0, 1):  # Exit cases for the recursion
						return str(__a						)
			_lowerCamelCase       ,							_lowerCamelCase					:					Union[str, Any]	       =    divmod(__a      ,							2						)
			return binary_recursive(__a						) + str(__a						)

def     UpperCAmelCase_					(				__a   :			str						):




			'''simple docstring'''



			_lowerCamelCase					:					int	       =    str(__a						).strip()
			if not number:
						raise ValueError('No input value was provided'						)
			_lowerCamelCase					:					Tuple	       =    '-' if number.startswith('-'						) else ''
			_lowerCamelCase					:					List[Any]	       =    number.lstrip('-'						)
			if not number.isnumeric():
						raise ValueError('Input value is not an integer'						)
			return f"{negative}0b{binary_recursive(int(__a						)						)}"


if __name__ == "__main__":
	from doctest import testmod

	testmod()





