






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


lowerCamelCase_				: Tuple    	=							'''http://www.mocksite.com/file1.txt'''
lowerCamelCase_				: Any    	=							'''"text": ["foo", "foo"]'''
lowerCamelCase_				: Tuple    	=							'''6d8ce9aa78a471c7477201efbeabd3bb01ac2e7d100a6dc024ba1608361f90a8'''
class    _SCREAMING_SNAKE_CASE							:


			'''simple docstring'''





			__a							:							List[str]					     =					200
			__a							:							List[str]					     =					{"Content-Length": "100"}
			__a							:							List[Any]					     =					{}






			def 				A      (   self							:						Tuple ,      **lowercase							:						str			)							->    Dict:

									'''simple docstring'''







									return [bytes(lowercase ,      """utf-8"""			)]







def 	__magic_name__( *_A						,      **_A					):
						'''simple docstring'''





						return MockResponse()







@pytest.mark.parametrize("""urls_type"""						,      [str, list, dict]					)
def 	__magic_name__( _A						,      _A						,      _A					):
						'''simple docstring'''





						import requests

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

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







@pytest.mark.parametrize("""paths_type"""						,      [str, list, dict]					)
def 	__magic_name__( _A						,      _A						,      _A					):
						'''simple docstring'''





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







def 	__magic_name__( _A						,      _A					):
						'''simple docstring'''





						assert path.endswith(""".jsonl"""					)
						for num_items, line in enumerate(_A						,      start=1					):
												UpperCamelCase__         = 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 	__magic_name__( _A						,      _A					):
						'''simple docstring'''





						UpperCamelCase__         = request.getfixturevalue(_A					)
						UpperCamelCase__         = 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 	__magic_name__( _A						,      _A					):
						'''simple docstring'''





						UpperCamelCase__         = request.getfixturevalue(_A					)
						UpperCamelCase__         = 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 	__magic_name__( _A					):
						'''simple docstring'''





						UpperCamelCase__         = 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

from transformers import Pipeline







def 	__magic_name__( _A					):
						'''simple docstring'''





						UpperCamelCase__         = np.max(_A						,      axis=-1						,      keepdims=_A					)
						UpperCamelCase__         = np.exp(outputs - maxes					)
						return shifted_exp / shifted_exp.sum(axis=-1						,      keepdims=_A					)







class    _SCREAMING_SNAKE_CASE							(		SCREAMING_SNAKE_CASE	):


			'''simple docstring'''





			def 				A      (   self							:						int ,      **lowercase							:						List[Any]			)							->    List[str]:

									'''simple docstring'''







									UpperCamelCase__         = {}
									if "second_text" in kwargs:
															UpperCamelCase__         = kwargs["""second_text"""]
									return preprocess_kwargs, {}, {}






			def 				A      (   self							:						Optional[int] ,      lowercase							:						Union[str, Any] ,      lowercase							:						Any=None			)							->    Optional[int]:

									'''simple docstring'''







									return self.tokenizer(lowercase ,      text_pair=lowercase ,      return_tensors=self.framework			)






			def 				A      (   self							:						Union[str, Any] ,      lowercase							:						Optional[int]			)							->    Any:

									'''simple docstring'''







									return self.model(**lowercase			)







			def 				A      (   self							:						List[str] ,      lowercase							:						Any			)							->    Optional[int]:

									'''simple docstring'''







									UpperCamelCase__         = model_outputs.logits[0].numpy()
									UpperCamelCase__         = softmax(lowercase			)

									UpperCamelCase__         = np.argmax(lowercase			)
									UpperCamelCase__         = self.model.config.idalabel[best_class]
									UpperCamelCase__         = probabilities[best_class].item()
									UpperCamelCase__         = logits.tolist()
									return {"label": label, "score": score, "logits": logits}
