"""simple docstring"""






import unittest

import numpy as np

from transformers import RobertaConfig, 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.roberta.modeling_flax_roberta import (
           FlaxRobertaForCausalLM,
           FlaxRobertaForMaskedLM,
           FlaxRobertaForMultipleChoice,
           FlaxRobertaForQuestionAnswering,
           FlaxRobertaForSequenceClassification,
           FlaxRobertaForTokenClassification,
           FlaxRobertaModel,
       )





class 				_A		( unittest.TestCase			):

      def __init__(		self	, __lowerCAmelCase	, __lowerCAmelCase=13	, __lowerCAmelCase=7	, __lowerCAmelCase=True	, __lowerCAmelCase=True	, __lowerCAmelCase=True	, __lowerCAmelCase=True	, __lowerCAmelCase=99	, __lowerCAmelCase=32	, __lowerCAmelCase=5	, __lowerCAmelCase=4	, __lowerCAmelCase=37	, __lowerCAmelCase="gelu"	, __lowerCAmelCase=0.1	, __lowerCAmelCase=0.1	, __lowerCAmelCase=512	, __lowerCAmelCase=16	, __lowerCAmelCase=2	, __lowerCAmelCase=0.0_2	, __lowerCAmelCase=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        A__ (		self		):







            """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														=			RobertaConfig(
                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=__lowerCAmelCase	, initializer_range=self.initializer_range	, )

            return config, input_ids, token_type_ids, attention_mask

      def        A__ (		self		):







            """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        A__ (		self		):







            """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,
                token_type_ids,
                encoder_hidden_states,
                encoder_attention_mask,
            )






@require_flax
class 				_A		( lowerCAmelCase						,					unittest.TestCase			):
      snake_case__    :     Optional[int]													=			True

      snake_case__    :     List[str]													=			(
          (
              FlaxRobertaModel,
              FlaxRobertaForCausalLM,
              FlaxRobertaForMaskedLM,
              FlaxRobertaForSequenceClassification,
              FlaxRobertaForTokenClassification,
              FlaxRobertaForMultipleChoice,
              FlaxRobertaForQuestionAnswering,
          )
          if is_flax_available()
          else ()
      )

      def        A__ (		self		):







            """simple docstring"""



            lowercase														=			FlaxRobertaModelTester(self		)







      @slow
      def        A__ (		self		):







            """simple docstring"""



            for model_class_name in self.all_model_classes:
                  lowercase														=			model_class_name.from_pretrained("""roberta-base"""	, from_pt=__lowerCAmelCase		)
                  lowercase														=			model(np.ones((1, 1)		)		)
                  self.assertIsNotNone(__lowerCAmelCase		)




"""simple docstring"""






import os
from pathlib import Path
from unittest.mock import patch

import pytest
import zstandard as zstd

from datasets.download.download_config import DownloadConfig
from datasets.utils.file_utils import (
    OfflineModeIsEnabled,
    cached_path,
    fsspec_get,
    fsspec_head,
    ftp_get,
    ftp_head,
    get_from_cache,
    http_get,
    http_head,
)


__lowerCAmelCase					: List[Any]        ="""\
    Text data.
    Second line of data."""

__lowerCAmelCase					: Any        ="""file"""


@pytest.fixture(scope="""session"""	)
def     UpperCAmelCase__ (       lowerCAmelCase__  :str	)				->					Union[str, Any]:
      '''simple docstring'''


      lowercase														=			tmp_path_factory.mktemp("""data"""	) / (FILE_PATH + """.zstd""")
      lowercase														=			bytes(lowerCAmelCase__      ,	"""utf-8"""	)
      with zstd.open(lowerCAmelCase__      ,	"""wb"""	) as f:
            f.write(lowerCAmelCase__	)
      return path


@pytest.fixture
def     UpperCAmelCase__ (       lowerCAmelCase__  :Tuple	)				->					Dict:
      '''simple docstring'''


      with open(os.path.join(tmpfs.local_root_dir      ,	lowerCAmelCase__	)      ,	"""w"""	) as f:
            f.write(lowerCAmelCase__	)
      return FILE_PATH


@pytest.mark.parametrize("""compression_format"""      ,	["""gzip""", """xz""", """zstd"""]	)
def     UpperCAmelCase__ (       lowerCAmelCase__  :Any      ,	lowerCAmelCase__  :Any      ,	lowerCAmelCase__  :List[Any]      ,	lowerCAmelCase__  :Optional[Any]      ,	lowerCAmelCase__  :Any      ,	lowerCAmelCase__  :int	)				->					Union[str, Any]:
      '''simple docstring'''


      lowercase														=			{"""gzip""": gz_file, """xz""": xz_file, """zstd""": zstd_path}
      lowercase														=			input_paths[compression_format]
      lowercase														=			tmp_path / """cache"""
      lowercase														=			DownloadConfig(cache_dir=lowerCAmelCase__      ,	extract_compressed_file=lowerCAmelCase__	)
      lowercase														=			cached_path(lowerCAmelCase__      ,	download_config=lowerCAmelCase__	)
      with open(lowerCAmelCase__	) as f:
            lowercase														=			f.read()
      with open(lowerCAmelCase__	) as f:
            lowercase														=			f.read()
      assert extracted_file_content == expected_file_content


@pytest.mark.parametrize("""default_extracted"""      ,	[True, False]	)
@pytest.mark.parametrize("""default_cache_dir"""      ,	[True, False]	)
def     UpperCAmelCase__ (       lowerCAmelCase__  :Dict      ,	lowerCAmelCase__  :Tuple      ,	lowerCAmelCase__  :Tuple      ,	lowerCAmelCase__  :Union[str, Any]      ,	lowerCAmelCase__  :List[str]	)				->					Any:
      '''simple docstring'''


      lowercase														=			"""custom_cache"""
      lowercase														=			"""custom_extracted_dir"""
      lowercase														=			tmp_path / """custom_extracted_path"""
      if default_extracted:
            lowercase														=			("""downloads""" if default_cache_dir else custom_cache_dir, """extracted""")
      else:
            monkeypatch.setattr("""datasets.config.EXTRACTED_DATASETS_DIR"""      ,	lowerCAmelCase__	)
            monkeypatch.setattr("""datasets.config.EXTRACTED_DATASETS_PATH"""      ,	str(lowerCAmelCase__	)	)
            lowercase														=			custom_extracted_path.parts[-2:] if default_cache_dir else (custom_cache_dir, custom_extracted_dir)

      lowercase														=			xz_file
      lowercase														=			(
          DownloadConfig(extract_compressed_file=lowerCAmelCase__	)
          if default_cache_dir
          else DownloadConfig(cache_dir=tmp_path / custom_cache_dir      ,	extract_compressed_file=lowerCAmelCase__	)
      )
      lowercase														=			cached_path(lowerCAmelCase__      ,	download_config=lowerCAmelCase__	)
      assert Path(lowerCAmelCase__	).parent.parts[-2:] == expected


def     UpperCAmelCase__ (       lowerCAmelCase__  :List[str]	)				->					Tuple:
      '''simple docstring'''


      lowercase														=			str(Path(lowerCAmelCase__	).resolve()	)
      assert cached_path(lowerCAmelCase__	) == text_file
      # relative path
      lowercase														=			str(Path(lowerCAmelCase__	).resolve().relative_to(Path(os.getcwd()	)	)	)
      assert cached_path(lowerCAmelCase__	) == text_file


def     UpperCAmelCase__ (       lowerCAmelCase__  :Any	)				->					List[Any]:
      '''simple docstring'''


      lowercase														=			str(tmp_path.resolve() / """__missing_file__.txt"""	)
      with pytest.raises(lowerCAmelCase__	):
            cached_path(lowerCAmelCase__	)
      # relative path
      lowercase														=			"""./__missing_file__.txt"""
      with pytest.raises(lowerCAmelCase__	):
            cached_path(lowerCAmelCase__	)


def     UpperCAmelCase__ (       lowerCAmelCase__  :Any	)				->					Union[str, Any]:
      '''simple docstring'''


      lowercase														=			get_from_cache(f'tmp://{tmpfs_file}'	)
      with open(lowerCAmelCase__	) as f:
            lowercase														=			f.read()
      assert output_file_content == FILE_CONTENT


@patch("""datasets.config.HF_DATASETS_OFFLINE"""      ,	lowerCAmelCase__	)
def     UpperCAmelCase__ (       )				->					str:
      '''simple docstring'''


      with pytest.raises(lowerCAmelCase__	):
            cached_path("""https://huggingface.co"""	)


@patch("""datasets.config.HF_DATASETS_OFFLINE"""      ,	lowerCAmelCase__	)
def     UpperCAmelCase__ (       lowerCAmelCase__  :Tuple	)				->					Any:
      '''simple docstring'''


      lowercase														=			tmp_path_factory.mktemp("""data"""	) / """file.html"""
      with pytest.raises(lowerCAmelCase__	):
            http_get("""https://huggingface.co"""      ,	temp_file=lowerCAmelCase__	)
      with pytest.raises(lowerCAmelCase__	):
            http_head("""https://huggingface.co"""	)


@patch("""datasets.config.HF_DATASETS_OFFLINE"""      ,	lowerCAmelCase__	)
def     UpperCAmelCase__ (       lowerCAmelCase__  :str	)				->					Any:
      '''simple docstring'''


      lowercase														=			tmp_path_factory.mktemp("""data"""	) / """file.html"""
      with pytest.raises(lowerCAmelCase__	):
            ftp_get("""ftp://huggingface.co"""      ,	temp_file=lowerCAmelCase__	)
      with pytest.raises(lowerCAmelCase__	):
            ftp_head("""ftp://huggingface.co"""	)






@patch("""datasets.config.HF_DATASETS_OFFLINE"""      ,	lowerCAmelCase__	)
def     UpperCAmelCase__ (       lowerCAmelCase__  :Any	)				->					Dict:
      '''simple docstring'''


      lowercase														=			tmp_path_factory.mktemp("""data"""	) / """file.html"""
      with pytest.raises(lowerCAmelCase__	):
            fsspec_get("""s3://huggingface.co"""      ,	temp_file=lowerCAmelCase__	)
      with pytest.raises(lowerCAmelCase__	):
            fsspec_head("""s3://huggingface.co"""	)



