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


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







class 			UpperCamelCase						:
   lowercase				=    2_0_0
   lowercase				=    {'Content-Length': '100'}
   lowercase				=    {}
   def      _UpperCAmelCase  (     self	,**__UpperCamelCase     )      -> Optional[int]:


        '''simple docstring'''


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






def      lowercase__(			*__SCREAMING_SNAKE_CASE				:	int	,     **__SCREAMING_SNAKE_CASE				:	Optional[Any] ):
     return MockResponse()



@pytest.mark.parametrize('urls_type'	,     [str, list, dict] )
def      lowercase__(			__SCREAMING_SNAKE_CASE				:	int	,     __SCREAMING_SNAKE_CASE				:	Union[str, Any]	,     __SCREAMING_SNAKE_CASE				:	Union[str, Any] ):
     import requests

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

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



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



def      lowercase__(			__SCREAMING_SNAKE_CASE				:	Optional[int]	,     __SCREAMING_SNAKE_CASE				:	int ):
     assert path.endswith('.jsonl' )
     for num_items, line in enumerate(__SCREAMING_SNAKE_CASE	,     start=1 ):
          lowercase_      :							List[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      lowercase__(			__SCREAMING_SNAKE_CASE				:	Any	,     __SCREAMING_SNAKE_CASE				:	str ):
     lowercase_      :							Union[str, Any]						=      request.getfixturevalue(__SCREAMING_SNAKE_CASE )
     lowercase_      :							List[Any]						=      DownloadManager()
     for num_jsonl, (path, file) in enumerate(dl_manager.iter_archive(__SCREAMING_SNAKE_CASE )	,     start=1 ):
          _test_jsonl(__SCREAMING_SNAKE_CASE	,     __SCREAMING_SNAKE_CASE )
     assert num_jsonl == 2



@pytest.mark.parametrize('archive_nested_jsonl'	,     ['tar_nested_jsonl_path', 'zip_nested_jsonl_path'] )
def      lowercase__(			__SCREAMING_SNAKE_CASE				:	Dict	,     __SCREAMING_SNAKE_CASE				:	Optional[Any] ):
     lowercase_      :							Union[str, Any]						=      request.getfixturevalue(__SCREAMING_SNAKE_CASE )
     lowercase_      :							Optional[int]						=      DownloadManager()
     for num_tar, (path, file) in enumerate(dl_manager.iter_archive(__SCREAMING_SNAKE_CASE )	,     start=1 ):
          for num_jsonl, (subpath, subfile) in enumerate(dl_manager.iter_archive(__SCREAMING_SNAKE_CASE )	,     start=1 ):
               _test_jsonl(__SCREAMING_SNAKE_CASE	,     __SCREAMING_SNAKE_CASE )
     assert num_tar == 1
     assert num_jsonl == 2







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






'''simple docstring'''



def        UpperCAmelCase (    A	:					int					):
							if not isinstance(A       ,		A					):
														SCREAMING_SNAKE_CASE       :   List[str]         =      F"""Input value of [number={number}] must be an integer"""
														raise TypeError(A					)
							if number < 0:
														return False
							SCREAMING_SNAKE_CASE       :   List[str]         =      number * number
							while number > 0:
														if number % 10 != number_square % 10:
																					return False
														number //= 10
														number_square //= 10
							return True


if __name__ == "__main__":
							import doctest

							doctest.testmod()




