




'''simple docstring'''







from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_tensorflow_text_available, is_torch_available


A									={
    'configuration_ernie': ['ERNIE_PRETRAINED_CONFIG_ARCHIVE_MAP', 'ErnieConfig', 'ErnieOnnxConfig'],
}

try:
   if not is_torch_available():
      raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
   pass
else:
   A									=[
       'ERNIE_PRETRAINED_MODEL_ARCHIVE_LIST',
       'ErnieForCausalLM',
       'ErnieForMaskedLM',
       'ErnieForMultipleChoice',
       'ErnieForNextSentencePrediction',
       'ErnieForPreTraining',
       'ErnieForQuestionAnswering',
       'ErnieForSequenceClassification',
       'ErnieForTokenClassification',
       'ErnieModel',
       'ErniePreTrainedModel',
   ]

if TYPE_CHECKING:
   from .configuration_ernie import ERNIE_PRETRAINED_CONFIG_ARCHIVE_MAP, ErnieConfig, ErnieOnnxConfig

   try:
      if not is_torch_available():
         raise OptionalDependencyNotAvailable()
   except OptionalDependencyNotAvailable:
      pass
   else:
      from .modeling_ernie import (
          ERNIE_PRETRAINED_MODEL_ARCHIVE_LIST,
          ErnieForCausalLM,
          ErnieForMaskedLM,
          ErnieForMultipleChoice,
          ErnieForNextSentencePrediction,
          ErnieForPreTraining,
          ErnieForQuestionAnswering,
          ErnieForSequenceClassification,
          ErnieForTokenClassification,
          ErnieModel,
          ErniePreTrainedModel,
      )

else:
   import sys

   A									=_LazyModule(__name__, globals()['__file__'], _import_structure, module_spec=__spec__)










'''simple docstring'''







import json
import os
import unittest

from transformers import MgpstrTokenizer
from transformers.models.mgp_str.tokenization_mgp_str import VOCAB_FILES_NAMES
from transformers.testing_utils import require_tokenizers

from ...test_tokenization_common import TokenizerTesterMixin


@require_tokenizers
class     _a						(			__a							,							unittest.TestCase				):
       __a       :  Any            =      MgpstrTokenizer
       __a       :  Optional[Any]            =      False
       __a       :  str            =      {}
       __a       :  Optional[int]            =      False
       def 					A   (			self		:			Dict       ):



           '''simple docstring'''

           super().setUp()

           # fmt: off
           UpperCAmelCase     =	['''[GO]''', '''[s]''', '''0''', '''1''', '''2''', '''3''', '''4''', '''5''', '''6''', '''7''', '''8''', '''9''', '''a''', '''b''', '''c''', '''d''', '''e''', '''f''', '''g''', '''h''', '''i''', '''j''', '''k''', '''l''', '''m''', '''n''', '''o''', '''p''', '''q''', '''r''', '''s''', '''t''', '''u''', '''v''', '''w''', '''x''', '''y''', '''z''']
           # fmt: on
           UpperCAmelCase     =	dict(zip(lowercase     ,       range(len(lowercase       )       )       )       )

           UpperCAmelCase     =	os.path.join(self.tmpdirname     ,       VOCAB_FILES_NAMES['''vocab_file''']       )
           with open(self.vocab_file     ,       '''w'''     ,       encoding='''utf-8'''       ) as fp:
               fp.write(json.dumps(lowercase       ) + '''\n'''       )
       def 					A   (			self		:			int     ,       **lowercase		:			Optional[Any]       ):



           '''simple docstring'''

           return MgpstrTokenizer.from_pretrained(self.tmpdirname     ,       **lowercase       )
       def 					A   (			self		:			int     ,       lowercase		:			str       ):



           '''simple docstring'''

           UpperCAmelCase     =	'''tester'''
           UpperCAmelCase     =	'''tester'''
           return input_text, output_text
       @unittest.skip('''MGP-STR always lower cases letters.'''       )
       def 					A   (			self		:			Optional[int]       ):



           '''simple docstring'''

           pass
       def 					A   (			self		:			int       ):



           '''simple docstring'''

           UpperCAmelCase     =	self.get_tokenizers(do_lower_case=lowercase       )
           for tokenizer in tokenizers:
               with self.subTest(f"{tokenizer.__class__.__name__}"       ):
                   UpperCAmelCase     =	'''[SPECIAL_TOKEN]'''

                   tokenizer.add_special_tokens({'''cls_token''': special_token}       )
                   UpperCAmelCase     =	tokenizer.encode([special_token]     ,       add_special_tokens=lowercase       )
                   self.assertEqual(len(lowercase       )     ,       1       )

                   UpperCAmelCase     =	tokenizer.decode(lowercase     ,       skip_special_tokens=lowercase       )
                   self.assertTrue(special_token not in decoded       )
       def 					A   (			self		:			List[Any]       ):



           '''simple docstring'''

           UpperCAmelCase     =	self.get_tokenizers()
           for tokenizer in tokenizers:
               with self.subTest(f"{tokenizer.__class__.__name__}"       ):
                   UpperCAmelCase ,  UpperCAmelCase     =	self.get_input_output_texts(lowercase       )

                   UpperCAmelCase     =	tokenizer.tokenize(lowercase       )
                   UpperCAmelCase     =	tokenizer.convert_tokens_to_ids(lowercase       )
                   UpperCAmelCase     =	tokenizer.encode(lowercase     ,       add_special_tokens=lowercase       )
                   self.assertListEqual(lowercase     ,       lowercase       )

                   UpperCAmelCase     =	tokenizer.convert_ids_to_tokens(lowercase       )
                   self.assertNotEqual(len(lowercase       )     ,       0       )
                   UpperCAmelCase     =	tokenizer.decode(lowercase       )
                   self.assertIsInstance(lowercase     ,       lowercase       )

                   self.assertEqual(text_a.replace(''' '''     ,       ''''''       )     ,       lowercase       )
       @unittest.skip('''MGP-STR tokenizer only handles one sequence.'''       )
       def 					A   (			self		:			Any       ):



           '''simple docstring'''

           pass







       @unittest.skip('''inputs cannot be pretokenized in MgpstrTokenizer'''       )
       def 					A   (			self		:			str       ):



           '''simple docstring'''

           pass




