





'''simple docstring'''




import json
import os
import unittest

from transformers import OpenAIGPTTokenizer, OpenAIGPTTokenizerFast
from transformers.models.openai.tokenization_openai import VOCAB_FILES_NAMES
from transformers.testing_utils import require_ftfy, require_spacy, require_tokenizers

from ...test_tokenization_common import TokenizerTesterMixin




@require_tokenizers
class      UpperCamelCase__					(					lowercase_						,					unittest.TestCase			):




					"""simple docstring"""
					SCREAMING_SNAKE_CASE__				=	OpenAIGPTTokenizer
					SCREAMING_SNAKE_CASE__				=	OpenAIGPTTokenizerFast
					SCREAMING_SNAKE_CASE__				=	True
					SCREAMING_SNAKE_CASE__				=	False


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

							'''simple docstring'''



							super().setUp()

							# Adapted from Sennrich et al. 2015 and https://github.com/rsennrich/subword-nmt
							SCREAMING_SNAKE_CASE :				str		=			[
							    """l""",
							    """o""",
							    """w""",
							    """e""",
							    """r""",
							    """s""",
							    """t""",
							    """i""",
							    """d""",
							    """n""",
							    """w</w>""",
							    """r</w>""",
							    """t</w>""",
							    """lo""",
							    """low""",
							    """er</w>""",
							    """low</w>""",
							    """lowest</w>""",
							    """newer</w>""",
							    """wider</w>""",
							    """<unk>""",
							]
							SCREAMING_SNAKE_CASE :				Any		=			dict(zip(lowerCamelCase_      ,						range(len(lowerCamelCase_						)						)						)						)
							SCREAMING_SNAKE_CASE :				List[Any]		=			["""#version: 0.2""", """l o""", """lo w""", """e r</w>""", """"""]

							SCREAMING_SNAKE_CASE :				Dict		=			os.path.join(self.tmpdirname      ,						VOCAB_FILES_NAMES["""vocab_file"""]						)
							SCREAMING_SNAKE_CASE :				Optional[int]		=			os.path.join(self.tmpdirname      ,						VOCAB_FILES_NAMES["""merges_file"""]						)
							with open(self.vocab_file      ,						"""w"""						) as fp:
									fp.write(json.dumps(lowerCamelCase_						)						)
							with open(self.merges_file      ,						"""w"""						) as fp:
									fp.write("""\n""".join(lowerCamelCase_						)						)


					def lowerCamelCase_			(						self				:			Tuple      ,						lowerCamelCase_				:			Tuple						):

							'''simple docstring'''



							return "lower newer", "lower newer"


					def lowerCamelCase_			(						self				:			Any						):

							'''simple docstring'''



							SCREAMING_SNAKE_CASE :				Tuple		=			OpenAIGPTTokenizer(self.vocab_file      ,						self.merges_file						)

							SCREAMING_SNAKE_CASE :				str		=			"""lower"""
							SCREAMING_SNAKE_CASE :				Any		=			["""low""", """er</w>"""]
							SCREAMING_SNAKE_CASE :				Union[str, Any]		=			tokenizer.tokenize(lowerCamelCase_						)
							self.assertListEqual(lowerCamelCase_      ,						lowerCamelCase_						)

							SCREAMING_SNAKE_CASE :				str		=			tokens + ["""<unk>"""]
							SCREAMING_SNAKE_CASE :				Dict		=			[14, 15, 20]
							self.assertListEqual(tokenizer.convert_tokens_to_ids(lowerCamelCase_						)      ,						lowerCamelCase_						)


					def lowerCamelCase_			(						self				:			Dict      ,						lowerCamelCase_				:			List[Any]=15						):

							'''simple docstring'''



							for tokenizer, pretrained_name, kwargs in self.tokenizers_list:
									with self.subTest(f'''{tokenizer.__class__.__name__} ({pretrained_name})'''						):
											SCREAMING_SNAKE_CASE :				Dict		=			self.rust_tokenizer_class.from_pretrained(lowerCamelCase_      ,						**lowerCamelCase_						)

											# Simple input
											SCREAMING_SNAKE_CASE :				str		=			"""This is a simple input"""
											SCREAMING_SNAKE_CASE :				Dict		=			["""This is a simple input 1""", """This is a simple input 2"""]
											SCREAMING_SNAKE_CASE :				Optional[int]		=			("""This is a simple input""", """This is a pair""")
											SCREAMING_SNAKE_CASE :				Optional[int]		=			[
											    ("""This is a simple input 1""", """This is a simple input 2"""),
											    ("""This is a simple pair 1""", """This is a simple pair 2"""),
											]

											# Simple input tests
											self.assertRaises(lowerCamelCase_      ,						tokenizer_r.encode      ,						lowerCamelCase_      ,						max_length=lowerCamelCase_      ,						padding="""max_length"""						)

											# Simple input
											self.assertRaises(lowerCamelCase_      ,						tokenizer_r.encode_plus      ,						lowerCamelCase_      ,						max_length=lowerCamelCase_      ,						padding="""max_length"""						)

											# Simple input
											self.assertRaises(
											    lowerCamelCase_      ,						tokenizer_r.batch_encode_plus      ,						lowerCamelCase_      ,						max_length=lowerCamelCase_      ,						padding="""max_length"""      ,						)

											# Pair input
											self.assertRaises(lowerCamelCase_      ,						tokenizer_r.encode      ,						lowerCamelCase_      ,						max_length=lowerCamelCase_      ,						padding="""max_length"""						)

											# Pair input
											self.assertRaises(lowerCamelCase_      ,						tokenizer_r.encode_plus      ,						lowerCamelCase_      ,						max_length=lowerCamelCase_      ,						padding="""max_length"""						)

											# Pair input
											self.assertRaises(
											    lowerCamelCase_      ,						tokenizer_r.batch_encode_plus      ,						lowerCamelCase_      ,						max_length=lowerCamelCase_      ,						padding="""max_length"""      ,						)



					def lowerCamelCase_			(						self				:			List[str]						):

							'''simple docstring'''



							pass







@require_ftfy
@require_spacy
@require_tokenizers
class      UpperCamelCase__					(					lowercase_			):




					"""simple docstring"""
					pass










'''simple docstring'''




import os
import sys
import unittest


__UpperCAmelCase            =       os.path.abspath(os.path.dirname(os.path.dirname(os.path.dirname(__file__))))
sys.path.append(os.path.join(git_repo_path, """utils"""))

import check_dummies  # noqa: E402
from check_dummies import create_dummy_files, create_dummy_object, find_backend, read_init  # noqa: E402


# Align TRANSFORMERS_PATH in check_dummies with the current path
__UpperCAmelCase            =       os.path.join(git_repo_path, """src""", """transformers""")

__UpperCAmelCase            =       """
{0} = None
"""

__UpperCAmelCase            =       """
class {0}(metaclass=DummyObject):
    _backends = {1}

    def __init__(self, *args, **kwargs):
        requires_backends(self, {1})
"""


__UpperCAmelCase            =       """
def {0}(*args, **kwargs):
    requires_backends({0}, {1})
"""




class      UpperCamelCase__					(					unittest.TestCase			):




					"""simple docstring"""


					def lowerCamelCase_			(						self				:			List[str]						):

							'''simple docstring'''



							SCREAMING_SNAKE_CASE :				Dict		=			find_backend("""    _import_structure[\"models.albert\"].append(\"AlbertTokenizerFast\")"""						)
							self.assertIsNone(lowerCamelCase_						)

							SCREAMING_SNAKE_CASE :				str		=			find_backend("""    if not is_tokenizers_available():"""						)
							self.assertEqual(lowerCamelCase_      ,						"""tokenizers"""						)

							SCREAMING_SNAKE_CASE :				Union[str, Any]		=			find_backend("""    if not is_tensorflow_text_available():"""						)
							self.assertEqual(lowerCamelCase_      ,						"""tensorflow_text"""						)

							SCREAMING_SNAKE_CASE :				List[str]		=			find_backend("""    if not (is_sentencepiece_available() and is_tokenizers_available()):"""						)
							self.assertEqual(lowerCamelCase_      ,						"""sentencepiece_and_tokenizers"""						)

							SCREAMING_SNAKE_CASE :				Tuple		=			find_backend(
							    """    if not (is_sentencepiece_available() and is_tensorflow_text_available()):"""						)
							self.assertEqual(lowerCamelCase_      ,						"""sentencepiece_and_tensorflow_text"""						)

							SCREAMING_SNAKE_CASE :				Union[str, Any]		=			find_backend(
							    """    if not (is_sentencepiece_available() and is_tokenizers_available() and is_vision_available()):"""						)
							self.assertEqual(lowerCamelCase_      ,						"""sentencepiece_and_tokenizers_and_vision"""						)


					def lowerCamelCase_			(						self				:			Any						):

							'''simple docstring'''



							SCREAMING_SNAKE_CASE :				Optional[Any]		=			read_init()
							# We don't assert on the exact list of keys to allow for smooth grow of backend-specific objects
							self.assertIn("""torch"""      ,						lowerCamelCase_						)
							self.assertIn("""tensorflow_text"""      ,						lowerCamelCase_						)
							self.assertIn("""sentencepiece_and_tokenizers"""      ,						lowerCamelCase_						)

							# Likewise, we can't assert on the exact content of a key
							self.assertIn("""BertModel"""      ,						objects["""torch"""]						)
							self.assertIn("""TFBertModel"""      ,						objects["""tf"""]						)
							self.assertIn("""FlaxBertModel"""      ,						objects["""flax"""]						)
							self.assertIn("""BertModel"""      ,						objects["""torch"""]						)
							self.assertIn("""TFBertTokenizer"""      ,						objects["""tensorflow_text"""]						)
							self.assertIn("""convert_slow_tokenizer"""      ,						objects["""sentencepiece_and_tokenizers"""]						)


					def lowerCamelCase_			(						self				:			int						):

							'''simple docstring'''



							SCREAMING_SNAKE_CASE :				str		=			create_dummy_object("""CONSTANT"""      ,						"""'torch'"""						)
							self.assertEqual(lowerCamelCase_      ,						"""\nCONSTANT = None\n"""						)

							SCREAMING_SNAKE_CASE :				List[Any]		=			create_dummy_object("""function"""      ,						"""'torch'"""						)
							self.assertEqual(
							    lowerCamelCase_      ,						"""\ndef function(*args, **kwargs):\n    requires_backends(function, 'torch')\n"""						)

							SCREAMING_SNAKE_CASE :				str		=			"""
class FakeClass(metaclass=DummyObject):
    _backends = 'torch'

    def __init__(self, *args, **kwargs):
        requires_backends(self, 'torch')
"""
							SCREAMING_SNAKE_CASE :				Union[str, Any]		=			create_dummy_object("""FakeClass"""      ,						"""'torch'"""						)
							self.assertEqual(lowerCamelCase_      ,						lowerCamelCase_						)



					def lowerCamelCase_			(						self				:			int						):

							'''simple docstring'''



							SCREAMING_SNAKE_CASE :				Union[str, Any]		=			"""# This file is autogenerated by the command `make fix-copies`, do not edit.
from ..utils import DummyObject, requires_backends


CONSTANT = None


def function(*args, **kwargs):
    requires_backends(function, [\"torch\"])


class FakeClass(metaclass=DummyObject):
    _backends = [\"torch\"]

    def __init__(self, *args, **kwargs):
        requires_backends(self, [\"torch\"])
"""
							SCREAMING_SNAKE_CASE :				List[Any]		=			create_dummy_files({"""torch""": ["""CONSTANT""", """function""", """FakeClass"""]}						)
							self.assertEqual(dummy_files["""torch"""]      ,						lowerCamelCase_						)



