

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






class  UpperCAmelCase__	:






  """simple docstring"""


  a     =      2_00
  a     =      {"Content-Length": "100"}
  a     =      {}






  def    lowercase_	(							self		:	Dict			,     **__lowerCamelCase		:	Tuple      )	->							List[Any]:
       return [bytes(UpperCamelCase__			,     '''utf-8'''      )]



def        UpperCAmelCase_     (		*_A   ,	**_A       ):





     '''simple docstring'''




     return MockResponse()
@pytest.mark.parametrize('''urls_type'''   ,	[str, list, dict]       )
def        UpperCAmelCase_     (		_A   ,	_A   ,	_A       ):





     '''simple docstring'''




     import requests

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

     SCREAMING_SNAKE_CASE__					=					URL
     if issubclass(_lowerCamelCase   ,	_lowerCamelCase       ):
          SCREAMING_SNAKE_CASE__					=					url
     elif issubclass(_lowerCamelCase   ,	_lowerCamelCase       ):
          SCREAMING_SNAKE_CASE__					=					[url]
     elif issubclass(_lowerCamelCase   ,	_lowerCamelCase       ):
          SCREAMING_SNAKE_CASE__					=					{'''train''': url}
     SCREAMING_SNAKE_CASE__					=					'''dummy'''
     SCREAMING_SNAKE_CASE__					=					'''downloads'''
     SCREAMING_SNAKE_CASE__					=					tmp_path
     SCREAMING_SNAKE_CASE__					=					DownloadConfig(
         cache_dir=os.path.join(_lowerCamelCase   ,	_lowerCamelCase       )   ,	use_etag=_lowerCamelCase   ,	)
     SCREAMING_SNAKE_CASE__					=					DownloadManager(dataset_name=_lowerCamelCase   ,	download_config=_lowerCamelCase       )
     SCREAMING_SNAKE_CASE__					=					dl_manager.download(_lowerCamelCase       )
     SCREAMING_SNAKE_CASE__					=					urls
     for downloaded_paths in [downloaded_paths]:
          if isinstance(_lowerCamelCase   ,	_lowerCamelCase       ):
               SCREAMING_SNAKE_CASE__					=					[downloaded_paths]
               SCREAMING_SNAKE_CASE__					=					[urls]
          elif isinstance(_lowerCamelCase   ,	_lowerCamelCase       ):
               assert "train" in downloaded_paths.keys()
               SCREAMING_SNAKE_CASE__					=					downloaded_paths.values()
               SCREAMING_SNAKE_CASE__					=					urls.values()
          assert downloaded_paths
          for downloaded_path, input_url in zip(_lowerCamelCase   ,	_lowerCamelCase       ):
               assert downloaded_path == dl_manager.downloaded_paths[input_url]
               SCREAMING_SNAKE_CASE__					=					Path(_lowerCamelCase       )
               SCREAMING_SNAKE_CASE__					=					downloaded_path.parts
               assert parts[-1] == HASH
               assert parts[-2] == cache_subdir
               assert downloaded_path.exists()
               SCREAMING_SNAKE_CASE__					=					downloaded_path.read_text()
               assert content == CONTENT
               SCREAMING_SNAKE_CASE__					=					downloaded_path.with_suffix('''.json'''       )
               assert metadata_downloaded_path.exists()
               SCREAMING_SNAKE_CASE__					=					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       ):





     '''simple docstring'''




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





     '''simple docstring'''




     assert path.endswith('''.jsonl'''       )
     for num_items, line in enumerate(_lowerCamelCase   ,	start=1       ):
          SCREAMING_SNAKE_CASE__					=					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       ):





     '''simple docstring'''




     SCREAMING_SNAKE_CASE__					=					request.getfixturevalue(_lowerCamelCase       )
     SCREAMING_SNAKE_CASE__					=					DownloadManager()
     for num_jsonl, (path, file) in enumerate(dl_manager.iter_archive(_lowerCamelCase       )   ,	start=1       ):
          _test_jsonl(_lowerCamelCase   ,	_lowerCamelCase       )
     assert num_jsonl == 2
@pytest.mark.parametrize('''archive_nested_jsonl'''   ,	['''tar_nested_jsonl_path''', '''zip_nested_jsonl_path''']       )
def        UpperCAmelCase_     (		_A   ,	_A       ):





     '''simple docstring'''




     SCREAMING_SNAKE_CASE__					=					request.getfixturevalue(_lowerCamelCase       )
     SCREAMING_SNAKE_CASE__					=					DownloadManager()
     for num_tar, (path, file) in enumerate(dl_manager.iter_archive(_lowerCamelCase       )   ,	start=1       ):
          for num_jsonl, (subpath, subfile) in enumerate(dl_manager.iter_archive(_lowerCamelCase       )   ,	start=1       ):
               _test_jsonl(_lowerCamelCase   ,	_lowerCamelCase       )
     assert num_tar == 1
     assert num_jsonl == 2







def        UpperCAmelCase_     (		_A       ):





     '''simple docstring'''




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





from dataclasses import dataclass, field
from typing import ClassVar, Dict

from ..features import Features, Sequence, Value
from .base import TaskTemplate






@dataclass(frozen=A__ )
class  UpperCAmelCase__	( A__ ):






  """simple docstring"""


  a     =      field(default="question-answering-extractive"		,  metadata={"include_in_asdict_even_if_is_default": True} )
  a     =      Features({"question": Value("string" ), "context": Value("string" )} )
  a     =      Features(
      {
          "answers": Sequence(
              {
                  "text": Value("string" ),
                  "answer_start": Value("int32" ),
              } )
      } )
  a     =      "question"
  a     =      "context"
  a     =      "answers"






  @property
  def    lowercase_	(							self		:	Dict      )	->							Dict[str, str]:
       return {self.question_column: "question", self.context_column: "context", self.answers_column: "answers"}


