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


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


class     UpperCAmelCase						:



    """simple docstring"""

    _UpperCAmelCase	:Dict						    = 200
    _UpperCAmelCase	:int						    = {"Content-Length": "100"}
    _UpperCAmelCase	:int						    = {}






    def _snake_case			(   self    ,			**_UpperCAmelCase							):
       return [bytes(_UpperCAmelCase    ,			'''utf-8'''							)]



def SCREAMING_SNAKE_CASE__			(   *__UpperCAmelCase       ,    **__UpperCAmelCase )  ->  Union[str, Any]:
   return MockResponse()



@pytest.mark.parametrize('''urls_type'''       ,    [str, list, dict] )
def SCREAMING_SNAKE_CASE__			(   __UpperCAmelCase       ,    __UpperCAmelCase       ,    __UpperCAmelCase )  ->  Optional[int]:
   import requests

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

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



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



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



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




def SCREAMING_SNAKE_CASE__			(   __UpperCAmelCase )  ->  Dict:
   lowercase__:   Optional[int]					=      DownloadManager()
   for num_file, file in enumerate(dl_manager.iter_files(__UpperCAmelCase )       ,    start=1 ):
      assert os.path.basename(__UpperCAmelCase ) == ("test.txt" if num_file == 1 else "train.txt")
   assert num_file == 2

"""simple docstring"""






from collections.abc import Sequence



def SCREAMING_SNAKE_CASE__			(   __UpperCAmelCase       ,    __UpperCAmelCase = False )  ->  float:
   if not arr:
      return 0

   lowercase__:   Any					=      0 if allow_empty_subarrays else float('''-inf''' )
   lowercase__:   Union[str, Any]					=      0.0
   for num in arr:
      lowercase__:   List[str]					=      max(0 if allow_empty_subarrays else num       ,    curr_sum + num )
      lowercase__:   int					=      max(__UpperCAmelCase       ,    __UpperCAmelCase )

   return max_sum


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

       testmod()

       __A			   = [-2, 1, -3, 4, -1, 2, 1, -5, 4]
       print(f'''{max_subarray_sum(nums) = }''')
