


"""simple docstring"""

import unittest

import numpy as np

from transformers import BertConfig, is_flax_available
from transformers.testing_utils import require_flax, slow

from ...test_modeling_flax_common import FlaxModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask


if is_flax_available():
       from transformers.models.bert.modeling_flax_bert import (
           FlaxBertForMaskedLM,
           FlaxBertForMultipleChoice,
           FlaxBertForNextSentencePrediction,
           FlaxBertForPreTraining,
           FlaxBertForQuestionAnswering,
           FlaxBertForSequenceClassification,
           FlaxBertForTokenClassification,
           FlaxBertModel,
       )





class  lowerCamelCase__    (		unittest.TestCase     ):
      def __init__(		self						:						str   ,							A_						:						Optional[Any]   ,							A_						:						Dict=1_3   ,							A_						:						Union[str, Any]=7   ,							A_						:						Dict=True   ,							A_						:						List[str]=True   ,							A_						:						List[Any]=True   ,							A_						:						List[Any]=True   ,							A_						:						Optional[int]=9_9   ,							A_						:						Optional[Any]=3_2   ,							A_						:						Tuple=5   ,							A_						:						List[str]=4   ,							A_						:						List[Any]=3_7   ,							A_						:						int="gelu"   ,							A_						:						List[str]=0.1   ,							A_						:						List[Any]=0.1   ,							A_						:						List[str]=5_1_2   ,							A_						:						Optional[int]=1_6   ,							A_						:						List[Any]=2   ,							A_						:						Any=0.02   ,							A_						:						Union[str, Any]=4   ,							):






       '''simple docstring'''


       __lowercase						=						parent
       __lowercase						=						batch_size
       __lowercase						=						seq_length
       __lowercase						=						is_training
       __lowercase						=						use_attention_mask
       __lowercase						=						use_token_type_ids
       __lowercase						=						use_labels
       __lowercase						=						vocab_size
       __lowercase						=						hidden_size
       __lowercase						=						num_hidden_layers
       __lowercase						=						num_attention_heads
       __lowercase						=						intermediate_size
       __lowercase						=						hidden_act
       __lowercase						=						hidden_dropout_prob
       __lowercase						=						attention_probs_dropout_prob
       __lowercase						=						max_position_embeddings
       __lowercase						=						type_vocab_size
       __lowercase						=						type_sequence_label_size
       __lowercase						=						initializer_range
       __lowercase						=						num_choices
      def SCREAMING_SNAKE_CASE_						(		self						:						Tuple				):






       '''simple docstring'''


       __lowercase						=						ids_tensor([self.batch_size, self.seq_length]   ,							self.vocab_size				)

       __lowercase						=						None
       if self.use_attention_mask:
        __lowercase						=						random_attention_mask([self.batch_size, self.seq_length]				)

       __lowercase						=						None
       if self.use_token_type_ids:
        __lowercase						=						ids_tensor([self.batch_size, self.seq_length]   ,							self.type_vocab_size				)

       __lowercase						=						BertConfig(
           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   ,							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=A_   ,							initializer_range=self.initializer_range   ,							)

       return config, input_ids, token_type_ids, attention_mask
      def SCREAMING_SNAKE_CASE_						(		self						:						Union[str, Any]				):






       '''simple docstring'''


       __lowercase						=						self.prepare_config_and_inputs()
       __lowercase				,		__lowercase				,		__lowercase				,		__lowercase						=						config_and_inputs
       __lowercase						=						{"""input_ids""": input_ids, """token_type_ids""": token_type_ids, """attention_mask""": attention_mask}
       return config, inputs_dict






      def SCREAMING_SNAKE_CASE_						(		self						:						Optional[Any]				):






       '''simple docstring'''


       __lowercase						=						self.prepare_config_and_inputs()
       __lowercase				,		__lowercase				,		__lowercase				,		__lowercase						=						config_and_inputs

       __lowercase						=						True
       __lowercase						=						floats_tensor([self.batch_size, self.seq_length, self.hidden_size]				)
       __lowercase						=						ids_tensor([self.batch_size, self.seq_length]   ,							vocab_size=2				)

       return (
           config,
           input_ids,
           attention_mask,
           encoder_hidden_states,
           encoder_attention_mask,
       )






@require_flax
class  lowerCamelCase__    (		_a      , unittest.TestCase     ):
      a			:  Tuple           =		True

      a			:  Optional[int]           =		(
          (
              FlaxBertModel,
              FlaxBertForPreTraining,
              FlaxBertForMaskedLM,
              FlaxBertForMultipleChoice,
              FlaxBertForQuestionAnswering,
              FlaxBertForNextSentencePrediction,
              FlaxBertForSequenceClassification,
              FlaxBertForTokenClassification,
              FlaxBertForQuestionAnswering,
          )
          if is_flax_available()
          else ()
      )
      def SCREAMING_SNAKE_CASE_						(		self						:						Dict				):






       '''simple docstring'''


       __lowercase						=						FlaxBertModelTester(self				)






      @slow
      def SCREAMING_SNAKE_CASE_						(		self						:						str				):






       '''simple docstring'''


       __lowercase						=						FlaxBertModel.from_pretrained("""bert-base-cased"""				)
       __lowercase						=						model(np.ones((1, 1)				)				)
       self.assertIsNotNone(A_				)




"""simple docstring"""

import pytest
import requests

from datasets.utils.file_utils import http_head

from .utils import OfflineSimulationMode, RequestWouldHangIndefinitelyError, offline


@pytest.mark.integration
def lowerCAmelCase_   (					):






 """simple docstring"""







 with offline(OfflineSimulationMode.CONNECTION_TIMES_OUT			):
  with pytest.raises(UpperCamelCase__			):
   requests.request("""GET"""					, """https://huggingface.co"""			)
  with pytest.raises(requests.exceptions.ConnectTimeout			):
   requests.request("""GET"""					, """https://huggingface.co"""					, timeout=1.0			)


@pytest.mark.integration
def lowerCAmelCase_   (					):






 """simple docstring"""







 with offline(OfflineSimulationMode.CONNECTION_FAILS			):
  with pytest.raises(requests.exceptions.ConnectionError			):
   requests.request("""GET"""					, """https://huggingface.co"""			)


def lowerCAmelCase_   (					):






 """simple docstring"""







 with offline(OfflineSimulationMode.HF_DATASETS_OFFLINE_SET_TO_1			):
  with pytest.raises(UpperCamelCase__			):
   http_head("""https://huggingface.co"""			)
