

"""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_     :			Union[str, Any]	  =			'''http://www.mocksite.com/file1.txt'''
SCREAMING_SNAKE_CASE_     :			List[Any]	  =			'''"text": ["foo", "foo"]'''
SCREAMING_SNAKE_CASE_     :			Union[str, Any]	  =			'''6d8ce9aa78a471c7477201efbeabd3bb01ac2e7d100a6dc024ba1608361f90a8'''


class 		_A       :
      __a								=	200
      __a								=	{'Content-Length': '100'}
      __a								=	{}





      def 					_lowerCamelCase  (  self    ,						**SCREAMING_SNAKE_CASE__		)   ->					str:
         return [bytes(SCREAMING_SNAKE_CASE__    ,						"utf-8"		)]






def     UpperCAmelCase__   (				*A__	,    **A__   )      ->      Tuple:




   """simple docstring"""
   return MockResponse()



@pytest.mark.parametrize("urls_type"	,    [str, list, dict]   )
def     UpperCAmelCase__   (				A__	,    A__	,    A__   )      ->      List[str]:




   """simple docstring"""
   import requests

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

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



@pytest.mark.parametrize("paths_type"	,    [str, list, dict]   )
def     UpperCAmelCase__   (				A__	,    A__	,    A__   )      ->      Dict:




   """simple docstring"""
   lowerCamelCase__						=			str(A__   )
   if issubclass(A__	,    A__   ):
      lowerCamelCase__						=			filename
   elif issubclass(A__	,    A__   ):
      lowerCamelCase__						=			[filename]
   elif issubclass(A__	,    A__   ):
      lowerCamelCase__						=			{"train": filename}
   lowerCamelCase__						=			"dummy"
   lowerCamelCase__						=			xz_file.parent
   lowerCamelCase__						=			"extracted"
   lowerCamelCase__						=			DownloadConfig(
       cache_dir=A__	,    use_etag=A__	,    )
   lowerCamelCase__						=			DownloadManager(dataset_name=A__	,    download_config=A__   )
   lowerCamelCase__						=			dl_manager.extract(A__   )
   lowerCamelCase__						=			paths
   for extracted_paths in [extracted_paths]:
      if isinstance(A__	,    A__   ):
         lowerCamelCase__						=			[extracted_paths]
         lowerCamelCase__						=			[paths]
      elif isinstance(A__	,    A__   ):
         assert "train" in extracted_paths.keys()
         lowerCamelCase__						=			extracted_paths.values()
         lowerCamelCase__						=			paths.values()
      assert extracted_paths
      for extracted_path, input_path in zip(A__	,    A__   ):
         assert extracted_path == dl_manager.extracted_paths[input_path]
         lowerCamelCase__						=			Path(A__   )
         lowerCamelCase__						=			extracted_path.parts
         assert parts[-1] == hash_url_to_filename(A__	,    etag=A__   )
         assert parts[-2] == extracted_subdir
         assert extracted_path.exists()
         lowerCamelCase__						=			extracted_path.read_text()
         lowerCamelCase__						=			text_file.read_text()
         assert extracted_file_content == expected_file_content



def     UpperCAmelCase__   (				A__	,    A__   )      ->      str:




   """simple docstring"""
   assert path.endswith(".jsonl"   )
   for num_items, line in enumerate(A__	,    start=1   ):
      lowerCamelCase__						=			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     UpperCAmelCase__   (				A__	,    A__   )      ->      str:




   """simple docstring"""
   lowerCamelCase__						=			request.getfixturevalue(A__   )
   lowerCamelCase__						=			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     UpperCAmelCase__   (				A__	,    A__   )      ->      List[str]:




   """simple docstring"""
   lowerCamelCase__						=			request.getfixturevalue(A__   )
   lowerCamelCase__						=			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     UpperCAmelCase__   (				A__   )      ->      str:




   """simple docstring"""
   lowerCamelCase__						=			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"""




import numpy as np



def 	UpperCAmelCase__   (				A__   )      ->      np.array:




   """simple docstring"""
   return 1 / (1 + np.exp(-vector   ))


if __name__ == "__main__":
     import doctest

     doctest.testmod()




