





import unittest

from transformers import MobileBertConfig, is_torch_available
from transformers.models.auto import get_values
from transformers.testing_utils import require_sentencepiece, require_tokenizers, require_torch, slow, torch_device

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
      import torch

      from transformers import (
          MODEL_FOR_PRETRAINING_MAPPING,
          MobileBertForMaskedLM,
          MobileBertForMultipleChoice,
          MobileBertForNextSentencePrediction,
          MobileBertForPreTraining,
          MobileBertForQuestionAnswering,
          MobileBertForSequenceClassification,
          MobileBertForTokenClassification,
          MobileBertModel,
      )



class        _lowerCAmelCase    :


  '''simple docstring'''







  def __init__(      self      :					Dict      ,				UpperCamelCase      :					List[Any]      ,				UpperCamelCase      :					List[Any]=13      ,				UpperCamelCase      :					Tuple=7      ,				UpperCamelCase      :					str=True      ,				UpperCamelCase      :					Optional[int]=True      ,				UpperCamelCase      :					Optional[Any]=True      ,				UpperCamelCase      :					List[str]=True      ,				UpperCamelCase      :					Union[str, Any]=99      ,				UpperCamelCase      :					Optional[Any]=64      ,				UpperCamelCase      :					int=32      ,				UpperCamelCase      :					int=5      ,				UpperCamelCase      :					str=4      ,				UpperCamelCase      :					str=37      ,				UpperCamelCase      :					Tuple="gelu"      ,				UpperCamelCase      :					List[Any]=0.1      ,				UpperCamelCase      :					Any=0.1      ,				UpperCamelCase      :					Optional[Any]=5_12      ,				UpperCamelCase      :					str=16      ,				UpperCamelCase      :					Optional[int]=2      ,				UpperCamelCase      :					str=0.02      ,				UpperCamelCase      :					Dict=3      ,				UpperCamelCase      :					Dict=4      ,				UpperCamelCase      :					Any=None      ,				):


    '''simple docstring'''





    _snake_case   :				int														=	parent
    _snake_case   :				int														=	batch_size
    _snake_case   :				Tuple														=	seq_length
    _snake_case   :				int														=	is_training
    _snake_case   :				Dict														=	use_input_mask
    _snake_case   :				Any														=	use_token_type_ids
    _snake_case   :				int														=	use_labels
    _snake_case   :				str														=	vocab_size
    _snake_case   :				int														=	hidden_size
    _snake_case   :				List[str]														=	embedding_size
    _snake_case   :				int														=	num_hidden_layers
    _snake_case   :				Union[str, Any]														=	num_attention_heads
    _snake_case   :				Optional[Any]														=	intermediate_size
    _snake_case   :				Tuple														=	hidden_act
    _snake_case   :				str														=	hidden_dropout_prob
    _snake_case   :				Union[str, Any]														=	attention_probs_dropout_prob
    _snake_case   :				str														=	max_position_embeddings
    _snake_case   :				Optional[int]														=	type_vocab_size
    _snake_case   :				List[str]														=	type_sequence_label_size
    _snake_case   :				Optional[Any]														=	initializer_range
    _snake_case   :				List[str]														=	num_labels
    _snake_case   :				Tuple														=	num_choices
    _snake_case   :				Union[str, Any]														=	scope







  def UpperCamelCase_ (      self      :					List[Any]							):


    '''simple docstring'''





    _snake_case   :				Tuple														=	ids_tensor([self.batch_size, self.seq_length]      ,				self.vocab_size							)

    _snake_case   :				List[str]														=	None
    if self.use_input_mask:
      _snake_case   :				Any														=	random_attention_mask([self.batch_size, self.seq_length]							)

    _snake_case   :				Union[str, Any]														=	None
    if self.use_token_type_ids:
      _snake_case   :				Union[str, Any]														=	ids_tensor([self.batch_size, self.seq_length]      ,				self.type_vocab_size							)

    _snake_case   :				int														=	None
    _snake_case   :				Any														=	None
    _snake_case   :				List[str]														=	None
    if self.use_labels:
      _snake_case   :				int														=	ids_tensor([self.batch_size]      ,				self.type_sequence_label_size							)
      _snake_case   :				Optional[Any]														=	ids_tensor([self.batch_size, self.seq_length]      ,				self.num_labels							)
      _snake_case   :				Dict														=	ids_tensor([self.batch_size]      ,				self.num_choices							)

    _snake_case   :				Union[str, Any]														=	self.get_config()

    return config, input_ids, token_type_ids, input_mask, sequence_labels, token_labels, choice_labels







  def UpperCamelCase_ (      self      :					str							):


    '''simple docstring'''





    return MobileBertConfig(
        vocab_size=self.vocab_size      ,				hidden_size=self.hidden_size      ,				num_hidden_layers=self.num_hidden_layers      ,				num_attention_heads=self.num_attention_heads      ,				intermediate_size=self.intermediate_size      ,				embedding_size=self.embedding_size      ,				hidden_act=self.hidden_act      ,				hidden_dropout_prob=self.hidden_dropout_prob      ,				attention_probs_dropout_prob=self.attention_probs_dropout_prob      ,				max_position_embeddings=self.max_position_embeddings      ,				type_vocab_size=self.type_vocab_size      ,				is_decoder=UpperCamelCase      ,				initializer_range=self.initializer_range      ,				)







  def UpperCamelCase_ (      self      :					Dict      ,				UpperCamelCase      :					Any      ,				UpperCamelCase      :					Union[str, Any]      ,				UpperCamelCase      :					Optional[int]      ,				UpperCamelCase      :					int      ,				UpperCamelCase      :					Optional[int]      ,				UpperCamelCase      :					Tuple      ,				UpperCamelCase      :					str							):


    '''simple docstring'''





    _snake_case   :				List[Any]														=	MobileBertModel(config=UpperCamelCase							)
    model.to(UpperCamelCase							)
    model.eval()
    _snake_case   :				Union[str, Any]														=	model(UpperCamelCase      ,				attention_mask=UpperCamelCase      ,				token_type_ids=UpperCamelCase							)
    _snake_case   :				Optional[Any]														=	model(UpperCamelCase      ,				token_type_ids=UpperCamelCase							)
    _snake_case   :				Optional[int]														=	model(UpperCamelCase							)

    self.parent.assertEqual(result.last_hidden_state.shape      ,				(self.batch_size, self.seq_length, self.hidden_size)							)
    self.parent.assertEqual(result.pooler_output.shape      ,				(self.batch_size, self.hidden_size)							)







  def UpperCamelCase_ (      self      :					Optional[int]      ,				UpperCamelCase      :					Optional[Any]      ,				UpperCamelCase      :					Any      ,				UpperCamelCase      :					Any      ,				UpperCamelCase      :					Optional[Any]      ,				UpperCamelCase      :					int      ,				UpperCamelCase      :					Any      ,				UpperCamelCase      :					List[Any]							):


    '''simple docstring'''





    _snake_case   :				List[str]														=	MobileBertForMaskedLM(config=UpperCamelCase							)
    model.to(UpperCamelCase							)
    model.eval()
    _snake_case   :				Optional[int]														=	model(UpperCamelCase      ,				attention_mask=UpperCamelCase      ,				token_type_ids=UpperCamelCase      ,				labels=UpperCamelCase							)
    self.parent.assertEqual(result.logits.shape      ,				(self.batch_size, self.seq_length, self.vocab_size)							)







  def UpperCamelCase_ (      self      :					Any      ,				UpperCamelCase      :					str      ,				UpperCamelCase      :					Any      ,				UpperCamelCase      :					Optional[Any]      ,				UpperCamelCase      :					Optional[Any]      ,				UpperCamelCase      :					Optional[Any]      ,				UpperCamelCase      :					str      ,				UpperCamelCase      :					int							):


    '''simple docstring'''





    _snake_case   :				str														=	MobileBertForNextSentencePrediction(config=UpperCamelCase							)
    model.to(UpperCamelCase							)
    model.eval()
    _snake_case   :				str														=	model(
        UpperCamelCase      ,				attention_mask=UpperCamelCase      ,				token_type_ids=UpperCamelCase      ,				labels=UpperCamelCase      ,				)
    self.parent.assertEqual(result.logits.shape      ,				(self.batch_size, 2)							)







  def UpperCamelCase_ (      self      :					List[Any]      ,				UpperCamelCase      :					Optional[Any]      ,				UpperCamelCase      :					Optional[int]      ,				UpperCamelCase      :					Dict      ,				UpperCamelCase      :					str      ,				UpperCamelCase      :					int      ,				UpperCamelCase      :					int      ,				UpperCamelCase      :					Union[str, Any]							):


    '''simple docstring'''





    _snake_case   :				List[Any]														=	MobileBertForPreTraining(config=UpperCamelCase							)
    model.to(UpperCamelCase							)
    model.eval()
    _snake_case   :				Any														=	model(
        UpperCamelCase      ,				attention_mask=UpperCamelCase      ,				token_type_ids=UpperCamelCase      ,				labels=UpperCamelCase      ,				next_sentence_label=UpperCamelCase      ,				)
    self.parent.assertEqual(result.prediction_logits.shape      ,				(self.batch_size, self.seq_length, self.vocab_size)							)
    self.parent.assertEqual(result.seq_relationship_logits.shape      ,				(self.batch_size, 2)							)







  def UpperCamelCase_ (      self      :					Optional[int]      ,				UpperCamelCase      :					List[Any]      ,				UpperCamelCase      :					Any      ,				UpperCamelCase      :					Any      ,				UpperCamelCase      :					Union[str, Any]      ,				UpperCamelCase      :					List[Any]      ,				UpperCamelCase      :					Optional[int]      ,				UpperCamelCase      :					str							):


    '''simple docstring'''





    _snake_case   :				List[str]														=	MobileBertForQuestionAnswering(config=UpperCamelCase							)
    model.to(UpperCamelCase							)
    model.eval()
    _snake_case   :				Union[str, Any]														=	model(
        UpperCamelCase      ,				attention_mask=UpperCamelCase      ,				token_type_ids=UpperCamelCase      ,				start_positions=UpperCamelCase      ,				end_positions=UpperCamelCase      ,				)
    self.parent.assertEqual(result.start_logits.shape      ,				(self.batch_size, self.seq_length)							)
    self.parent.assertEqual(result.end_logits.shape      ,				(self.batch_size, self.seq_length)							)







  def UpperCamelCase_ (      self      :					Dict      ,				UpperCamelCase      :					Optional[int]      ,				UpperCamelCase      :					Union[str, Any]      ,				UpperCamelCase      :					Any      ,				UpperCamelCase      :					Any      ,				UpperCamelCase      :					Dict      ,				UpperCamelCase      :					Union[str, Any]      ,				UpperCamelCase      :					List[Any]							):


    '''simple docstring'''





    _snake_case   :				Optional[int]														=	self.num_labels
    _snake_case   :				Union[str, Any]														=	MobileBertForSequenceClassification(UpperCamelCase							)
    model.to(UpperCamelCase							)
    model.eval()
    _snake_case   :				Any														=	model(UpperCamelCase      ,				attention_mask=UpperCamelCase      ,				token_type_ids=UpperCamelCase      ,				labels=UpperCamelCase							)
    self.parent.assertEqual(result.logits.shape      ,				(self.batch_size, self.num_labels)							)







  def UpperCamelCase_ (      self      :					str      ,				UpperCamelCase      :					Optional[int]      ,				UpperCamelCase      :					int      ,				UpperCamelCase      :					Dict      ,				UpperCamelCase      :					Dict      ,				UpperCamelCase      :					Dict      ,				UpperCamelCase      :					Tuple      ,				UpperCamelCase      :					Optional[int]							):


    '''simple docstring'''





    _snake_case   :				int														=	self.num_labels
    _snake_case   :				Any														=	MobileBertForTokenClassification(config=UpperCamelCase							)
    model.to(UpperCamelCase							)
    model.eval()
    _snake_case   :				List[Any]														=	model(UpperCamelCase      ,				attention_mask=UpperCamelCase      ,				token_type_ids=UpperCamelCase      ,				labels=UpperCamelCase							)
    self.parent.assertEqual(result.logits.shape      ,				(self.batch_size, self.seq_length, self.num_labels)							)







  def UpperCamelCase_ (      self      :					str      ,				UpperCamelCase      :					Union[str, Any]      ,				UpperCamelCase      :					Union[str, Any]      ,				UpperCamelCase      :					str      ,				UpperCamelCase      :					int      ,				UpperCamelCase      :					Optional[int]      ,				UpperCamelCase      :					Any      ,				UpperCamelCase      :					Union[str, Any]							):


    '''simple docstring'''





    _snake_case   :				str														=	self.num_choices
    _snake_case   :				Union[str, Any]														=	MobileBertForMultipleChoice(config=UpperCamelCase							)
    model.to(UpperCamelCase							)
    model.eval()
    _snake_case   :				Optional[int]														=	input_ids.unsqueeze(1							).expand(-1      ,				self.num_choices      ,				-1							).contiguous()
    _snake_case   :				Dict														=	token_type_ids.unsqueeze(1							).expand(-1      ,				self.num_choices      ,				-1							).contiguous()
    _snake_case   :				List[Any]														=	input_mask.unsqueeze(1							).expand(-1      ,				self.num_choices      ,				-1							).contiguous()
    _snake_case   :				Optional[int]														=	model(
        UpperCamelCase      ,				attention_mask=UpperCamelCase      ,				token_type_ids=UpperCamelCase      ,				labels=UpperCamelCase      ,				)
    self.parent.assertEqual(result.logits.shape      ,				(self.batch_size, self.num_choices)							)







  def UpperCamelCase_ (      self      :					int							):


    '''simple docstring'''





    _snake_case   :				Optional[int]														=	self.prepare_config_and_inputs()
    (
        (
        _snake_case
    )							,					(
        _snake_case
    )							,					(
        _snake_case
    )							,					(
        _snake_case
    )							,					(
        _snake_case
    )							,					(
        _snake_case
    )							,					(
        _snake_case
    )							,					
    )   :				Tuple														=	config_and_inputs
    _snake_case   :				List[Any]														=	{'input_ids': input_ids, 'token_type_ids': token_type_ids, 'attention_mask': input_mask}
    return config, inputs_dict




@require_torch
class        _lowerCAmelCase    (			UpperCAmelCase_							,    UpperCAmelCase_							,    unittest.TestCase							):


  '''simple docstring'''
  a_							:       int      					=(
      (
          MobileBertModel,
          MobileBertForMaskedLM,
          MobileBertForMultipleChoice,
          MobileBertForNextSentencePrediction,
          MobileBertForPreTraining,
          MobileBertForQuestionAnswering,
          MobileBertForSequenceClassification,
          MobileBertForTokenClassification,
      )
      if is_torch_available()
      else ()
  )
  a_							:       List[Any]      					=(
      {
          """feature-extraction""": MobileBertModel,
          """fill-mask""": MobileBertForMaskedLM,
          """question-answering""": MobileBertForQuestionAnswering,
          """text-classification""": MobileBertForSequenceClassification,
          """token-classification""": MobileBertForTokenClassification,
          """zero-shot""": MobileBertForSequenceClassification,
      }
      if is_torch_available()
      else {}
  )
  a_							:       str      					=True







  def UpperCamelCase_ (      self      :					Any      ,				UpperCamelCase      :					List[Any]      ,				UpperCamelCase      :					List[str]      ,				UpperCamelCase      :					Optional[int]=False							):


    '''simple docstring'''





    _snake_case   :				Any														=	super()._prepare_for_class(UpperCamelCase      ,				UpperCamelCase      ,				return_labels=UpperCamelCase							)

    if return_labels:
      if model_class in get_values(UpperCamelCase							):
        _snake_case   :				int														=	torch.zeros(
            (self.model_tester.batch_size, self.model_tester.seq_length)      ,				dtype=torch.long      ,				device=UpperCamelCase							)
        _snake_case   :				Any														=	torch.zeros(
            self.model_tester.batch_size      ,				dtype=torch.long      ,				device=UpperCamelCase							)
    return inputs_dict







  def UpperCamelCase_ (      self      :					List[str]							):


    '''simple docstring'''





    _snake_case   :				Optional[Any]														=	MobileBertModelTester(self							)
    _snake_case   :				int														=	ConfigTester(self      ,				config_class=UpperCamelCase      ,				hidden_size=37							)







  def UpperCamelCase_ (      self      :					Dict							):


    '''simple docstring'''





    self.config_tester.run_common_tests()







  def UpperCamelCase_ (      self      :					Optional[int]							):


    '''simple docstring'''





    _snake_case   :				Optional[int]														=	self.model_tester.prepare_config_and_inputs()
    self.model_tester.create_and_check_mobilebert_model(*UpperCamelCase							)







  def UpperCamelCase_ (      self      :					Optional[int]							):


    '''simple docstring'''





    _snake_case   :				Dict														=	self.model_tester.prepare_config_and_inputs()
    self.model_tester.create_and_check_mobilebert_for_masked_lm(*UpperCamelCase							)







  def UpperCamelCase_ (      self      :					Dict							):


    '''simple docstring'''





    _snake_case   :				List[Any]														=	self.model_tester.prepare_config_and_inputs()
    self.model_tester.create_and_check_mobilebert_for_multiple_choice(*UpperCamelCase							)







  def UpperCamelCase_ (      self      :					Optional[Any]							):


    '''simple docstring'''





    _snake_case   :				Optional[int]														=	self.model_tester.prepare_config_and_inputs()
    self.model_tester.create_and_check_mobilebert_for_next_sequence_prediction(*UpperCamelCase							)







  def UpperCamelCase_ (      self      :					Union[str, Any]							):


    '''simple docstring'''





    _snake_case   :				List[Any]														=	self.model_tester.prepare_config_and_inputs()
    self.model_tester.create_and_check_mobilebert_for_pretraining(*UpperCamelCase							)







  def UpperCamelCase_ (      self      :					Optional[int]							):


    '''simple docstring'''





    _snake_case   :				Any														=	self.model_tester.prepare_config_and_inputs()
    self.model_tester.create_and_check_mobilebert_for_question_answering(*UpperCamelCase							)







  def UpperCamelCase_ (      self      :					int							):


    '''simple docstring'''





    _snake_case   :				Any														=	self.model_tester.prepare_config_and_inputs()
    self.model_tester.create_and_check_mobilebert_for_sequence_classification(*UpperCamelCase							)







  def UpperCamelCase_ (      self      :					Any							):


    '''simple docstring'''





    _snake_case   :				Optional[int]														=	self.model_tester.prepare_config_and_inputs()
    self.model_tester.create_and_check_mobilebert_for_token_classification(*UpperCamelCase							)




def     lowerCamelCase_	(      lowerCAmelCase:	Any				)->		str:
  return torch.tensor(
      lowerCAmelCase    ,							dtype=torch.long    ,							device=lowerCAmelCase    ,							)


lowerCAmelCase_						   =    1E-3







@require_torch
@require_sentencepiece
@require_tokenizers
class        _lowerCAmelCase    (			unittest.TestCase							):


  '''simple docstring'''







  @slow
  def UpperCamelCase_ (      self      :					Tuple							):


    '''simple docstring'''





    _snake_case   :				str														=	MobileBertModel.from_pretrained('google/mobilebert-uncased'							).to(UpperCamelCase							)
    _snake_case   :				Optional[Any]														=	_long_tensor([[1_01, 71_10, 10_05, 10_56, 20_23, 1_13_33, 1_74_13, 10_29, 1_02]]							)
    with torch.no_grad():
      _snake_case   :				Optional[int]														=	model(UpperCamelCase							)[0]
    _snake_case   :				Optional[Any]														=	torch.Size((1, 9, 5_12)							)
    self.assertEqual(output.shape      ,				UpperCamelCase							)
    _snake_case   :				int														=	torch.tensor(
        [
            [
                [-2.4_7_3_6_5_2_6e0_7, 8.2_6_9_1_6_5_6e0_4, 1.6_5_2_1_8_3_8e0_5],
                [-5.7_5_4_1_7_0_4e-0_1, 3.9_0_5_6_0_2_2e0_0, 4.4_0_1_1_5_0_7e0_0],
                [2.6_0_4_7_3_5_9e0_0, 1.5_6_7_7_6_5_2e0_0, -1.7_3_2_4_1_8_8e-0_1],
            ]
        ]      ,				device=UpperCamelCase      ,				)

    # MobileBERT results range from 10e0 to 10e8. Even a 0.0000001% difference with a value of 10e8 results in a
    # ~1 difference, it's therefore not a good idea to measure using addition.
    # Here, we instead divide the expected result with the result in order to obtain ~1. We then check that the
    # result is held between bounds: 1 - TOLERANCE < expected_result / result < 1 + TOLERANCE
    _snake_case   :				int														=	torch.all((expected_slice / output[..., :3, :3]) >= 1 - TOLERANCE							)
    _snake_case   :				int														=	torch.all((expected_slice / output[..., :3, :3]) <= 1 + TOLERANCE							)

    self.assertTrue(lower_bound and upper_bound							)











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_						   =    """http://www.mocksite.com/file1.txt"""
lowerCAmelCase_						   =    """\"text\": [\"foo\", \"foo\"]"""
lowerCAmelCase_						   =    """6d8ce9aa78a471c7477201efbeabd3bb01ac2e7d100a6dc024ba1608361f90a8"""



class        _lowerCAmelCase    :


  '''simple docstring'''
  a_							:       int      					=200
  a_							:       List[str]      					={"""Content-Length""": """100"""}
  a_							:       Tuple      					={}







  def UpperCamelCase_ (      self      :					Any      ,				**UpperCamelCase      :					Any							):


    '''simple docstring'''





    return [bytes(UpperCamelCase      ,				'utf-8'							)]




def     lowerCamelCase_	(      *lowerCAmelCase:	Tuple    ,							**lowerCAmelCase:	Tuple				)->		str:
  return MockResponse()


@pytest.mark.parametrize('urls_type'    ,							[str, list, dict]				)
def     lowerCamelCase_	(      lowerCAmelCase:	Union[str, Any]    ,							lowerCAmelCase:	Optional[Any]    ,							lowerCAmelCase:	Dict				)->		Optional[Any]:
  import requests

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

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


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


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




