





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







class     __lowerCAmelCase	:
      _lowercase    : List[Any]            =      200
      _lowercase    : str            =      {"Content-Length": "100"}
      _lowercase    : Optional[Any]            =      {}







      def        _lowercase  (   self		,				**lowerCAmelCase__							)       ->						Union[str, Any]:



        '''simple docstring'''




        return [bytes(_UpperCAmelCase		,				"utf-8"							)]
def 					_A	(		*SCREAMING_SNAKE_CASE					:       Any	,	**SCREAMING_SNAKE_CASE					:       str						):





  """simple docstring"""



  return MockResponse()
@pytest.mark.parametrize("urls_type"	,	[str, list, dict]						)
def 					_A	(		SCREAMING_SNAKE_CASE					:       int	,	SCREAMING_SNAKE_CASE					:       Any	,	SCREAMING_SNAKE_CASE					:       str						):





  """simple docstring"""



  import requests

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

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





  """simple docstring"""



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





  """simple docstring"""



  assert path.endswith(".jsonl"						)
  for num_items, line in enumerate(__UpperCAmelCase	,	start=1						):
    a__     : Dict  =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 					_A	(		SCREAMING_SNAKE_CASE					:       Optional[Any]	,	SCREAMING_SNAKE_CASE					:       Any						):





  """simple docstring"""



  a__     : List[Any]  =request.getfixturevalue(__UpperCAmelCase						)
  a__     : Optional[int]  =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 					_A	(		SCREAMING_SNAKE_CASE					:       Tuple	,	SCREAMING_SNAKE_CASE					:       Any						):





  """simple docstring"""



  a__     : Optional[Any]  =request.getfixturevalue(__UpperCAmelCase						)
  a__     : List[Any]  =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 					_A	(		SCREAMING_SNAKE_CASE					:       int						):





  """simple docstring"""



  a__     : List[Any]  =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













from __future__ import annotations

from math import pi

# Define the Reduced Planck Constant ℏ (H bar), speed of light C, value of
# Pi and the function
UpperCAmelCase     :     Union[str, Any]							=	1.054571817E-34  # unit of ℏ : J * s

UpperCAmelCase     :     Union[str, Any]							=	3E8  # unit of c : m * s^-1
def 					_A	(		SCREAMING_SNAKE_CASE					:       float	,	SCREAMING_SNAKE_CASE					:       float	,	SCREAMING_SNAKE_CASE					:       float						):





  """simple docstring"""



  if (force, area, distance).count(0						) != 1:
    raise ValueError("One and only one argument must be 0"						)
  if force < 0:
    raise ValueError("Magnitude of force can not be negative"						)
  if distance < 0:
    raise ValueError("Distance can not be negative"						)
  if area < 0:
    raise ValueError("Area can not be negative"						)
  if force == 0:
    a__     : Tuple  =(REDUCED_PLANCK_CONSTANT * SPEED_OF_LIGHT * pi**2 * area) / (
        240 * (distance) ** 4
    )
    return {"force": force}
  elif area == 0:
    a__     : Any  =(240 * force * (distance) ** 4) / (
        REDUCED_PLANCK_CONSTANT * SPEED_OF_LIGHT * pi**2
    )
    return {"area": area}
  elif distance == 0:
    a__     : List[str]  =(
        (REDUCED_PLANCK_CONSTANT * SPEED_OF_LIGHT * pi**2 * area) / (240 * force)
    ) ** (1 / 4)
    return {"distance": distance}
  raise ValueError("One and only one argument must be 0"						)


# Run doctest
if __name__ == "__main__":
     import doctest

     doctest.testmod()






