




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


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





class  __lowercase    :
   _a    						=   200
   _a    						=   {"""Content-Length""": """100"""}
   _a    						=   {}







   def 		UpperCamelCase__      (						self   ,				**UpperCamelCase   )					->     List[str]:
     return [bytes(UpperCamelCase   ,				'utf-8'   )]


def     SCREAMING_SNAKE_CASE							(   *a_						:				Union[str, Any]					,       **a_						:				str      ):
  return MockResponse()


@pytest.mark.parametrize('urls_type'					,       [str, list, dict]      )
def     SCREAMING_SNAKE_CASE							(   a_						:				int					,       a_						:				Optional[Any]					,       a_						:				List[str]      ):
  import requests

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

  __a								=       URL
  if issubclass(a_					,       a_      ):
    __a								=       url
  elif issubclass(a_					,       a_      ):
    __a								=       [url]
  elif issubclass(a_					,       a_      ):
    __a								=       {'train': url}
  __a								=       'dummy'
  __a								=       'downloads'
  __a								=       tmp_path
  __a								=       DownloadConfig(
      cache_dir=os.path.join(a_					,       a_      )					,       use_etag=a_					,       )
  __a								=       DownloadManager(dataset_name=a_					,       download_config=a_      )
  __a								=       dl_manager.download(a_      )
  __a								=       urls
  for downloaded_paths in [downloaded_paths]:
    if isinstance(a_					,       a_      ):
      __a								=       [downloaded_paths]
      __a								=       [urls]
    elif isinstance(a_					,       a_      ):
      assert "train" in downloaded_paths.keys()
      __a								=       downloaded_paths.values()
      __a								=       urls.values()
    assert downloaded_paths
    for downloaded_path, input_url in zip(a_					,       a_      ):
      assert downloaded_path == dl_manager.downloaded_paths[input_url]
      __a								=       Path(a_      )
      __a								=       downloaded_path.parts
      assert parts[-1] == HASH
      assert parts[-2] == cache_subdir
      assert downloaded_path.exists()
      __a								=       downloaded_path.read_text()
      assert content == CONTENT
      __a								=       downloaded_path.with_suffix('.json'      )
      assert metadata_downloaded_path.exists()
      __a								=       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							(   a_						:				Optional[Any]					,       a_						:				str					,       a_						:				Optional[Any]      ):
  __a								=       str(a_      )
  if issubclass(a_					,       a_      ):
    __a								=       filename
  elif issubclass(a_					,       a_      ):
    __a								=       [filename]
  elif issubclass(a_					,       a_      ):
    __a								=       {'train': filename}
  __a								=       'dummy'
  __a								=       xz_file.parent
  __a								=       'extracted'
  __a								=       DownloadConfig(
      cache_dir=a_					,       use_etag=a_					,       )
  __a								=       DownloadManager(dataset_name=a_					,       download_config=a_      )
  __a								=       dl_manager.extract(a_      )
  __a								=       paths
  for extracted_paths in [extracted_paths]:
    if isinstance(a_					,       a_      ):
      __a								=       [extracted_paths]
      __a								=       [paths]
    elif isinstance(a_					,       a_      ):
      assert "train" in extracted_paths.keys()
      __a								=       extracted_paths.values()
      __a								=       paths.values()
    assert extracted_paths
    for extracted_path, input_path in zip(a_					,       a_      ):
      assert extracted_path == dl_manager.extracted_paths[input_path]
      __a								=       Path(a_      )
      __a								=       extracted_path.parts
      assert parts[-1] == hash_url_to_filename(a_					,       etag=a_      )
      assert parts[-2] == extracted_subdir
      assert extracted_path.exists()
      __a								=       extracted_path.read_text()
      __a								=       text_file.read_text()
      assert extracted_file_content == expected_file_content


def     SCREAMING_SNAKE_CASE							(   a_						:				List[Any]					,       a_						:				int      ):
  assert path.endswith('.jsonl'      )
  for num_items, line in enumerate(a_					,       start=1      ):
    __a								=       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							(   a_						:				Any					,       a_						:				Union[str, Any]      ):
  __a								=       request.getfixturevalue(a_      )
  __a								=       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     SCREAMING_SNAKE_CASE							(   a_						:				str					,       a_						:				Dict      ):
  __a								=       request.getfixturevalue(a_      )
  __a								=       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     SCREAMING_SNAKE_CASE							(   a_						:				Optional[Any]      ):
  __a								=       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'''


class  __lowercase    :  # Public class to implement a graph







   def __init__(						self   ,				UpperCamelCase   ,				UpperCamelCase   ,				UpperCamelCase   )					->     None:
     __a								=       row
     __a								=       col
     __a								=       graph







   def 		UpperCamelCase__      (						self   ,				UpperCamelCase   ,				UpperCamelCase   ,				UpperCamelCase   )					->     bool:
     return (
         0 <= i < self.ROW
         and 0 <= j < self.COL
         and not visited[i][j]
         and self.graph[i][j]
     )







   def 		UpperCamelCase__      (						self   ,				UpperCamelCase   ,				UpperCamelCase   ,				UpperCamelCase   )					->     None:
     # Checking all 8 elements surrounding nth element
     __a								=       [-1, -1, -1, 0, 0, 1, 1, 1]  # Coordinate order
     __a								=       [-1, 0, 1, -1, 1, -1, 0, 1]
     __a								=       True  # Make those cells visited
     for k in range(8   ):
       if self.is_safe(i + row_nbr[k]   ,				j + col_nbr[k]   ,				UpperCamelCase   ):
         self.diffs(i + row_nbr[k]   ,				j + col_nbr[k]   ,				UpperCamelCase   )







   def 		UpperCamelCase__      (						self   )					->     int:  # And finally, count all islands.
     __a								=       [[False for j in range(self.COL   )] for i in range(self.ROW   )]
     __a								=       0
     for i in range(self.ROW   ):
       for j in range(self.COL   ):
         if visited[i][j] is False and self.graph[i][j] == 1:
           self.diffs(UpperCamelCase   ,				UpperCamelCase   ,				UpperCamelCase   )
           count += 1
     return count



