


"""simple docstring"""






from __future__ import annotations

import unittest

import numpy as np

from transformers import BlipTextConfig
from transformers.testing_utils import require_tf, slow
from transformers.utils import is_tf_available

from ...test_configuration_common import ConfigTester
from ...test_modeling_tf_common import TFModelTesterMixin, ids_tensor, random_attention_mask


if is_tf_available():
   import tensorflow as tf

   from transformers import TFBlipTextModel
   from transformers.models.blip.modeling_tf_blip import TF_BLIP_PRETRAINED_MODEL_ARCHIVE_LIST


class 			__lowerCamelCase     :

     '''simple docstring'''


     def __init__(					self			, __UpperCAmelCase			, __UpperCAmelCase=12			, __UpperCAmelCase=7			, __UpperCAmelCase=True			, __UpperCAmelCase=True			, __UpperCAmelCase=True			, __UpperCAmelCase=99			, __UpperCAmelCase=32			, __UpperCAmelCase=32			, __UpperCAmelCase=2			, __UpperCAmelCase=4			, __UpperCAmelCase=37			, __UpperCAmelCase=0.1			, __UpperCAmelCase=0.1			, __UpperCAmelCase=512			, __UpperCAmelCase=0.02			, __UpperCAmelCase=0			, __UpperCAmelCase=None			, )				->							str:
          _a					= parent
          _a					= batch_size
          _a					= seq_length
          _a					= is_training
          _a					= use_input_mask
          _a					= use_labels
          _a					= vocab_size
          _a					= hidden_size
          _a					= projection_dim
          _a					= num_hidden_layers
          _a					= num_attention_heads
          _a					= intermediate_size
          _a					= dropout
          _a					= attention_dropout
          _a					= max_position_embeddings
          _a					= initializer_range
          _a					= scope
          _a					= bos_token_id


     def 							_UpperCAmelCase					(					self							)				->							Union[str, Any]:
          _a					= ids_tensor([self.batch_size, self.seq_length]			, self.vocab_size							)

          _a					= None
          if self.use_input_mask:
               _a					= random_attention_mask([self.batch_size, self.seq_length]							)

          if input_mask is not None:
               _a					= input_mask.numpy()
               _a					= input_mask.shape
               _a					= np.random.randint(1			, seq_length - 1			, size=(batch_size,)							)
               for batch_idx, start_index in enumerate(__UpperCAmelCase							):
                    _a					= 1
                    _a					= 0

          _a					= self.get_config()

          return config, input_ids, tf.convert_to_tensor(__UpperCAmelCase							)


     def 							_UpperCAmelCase					(					self							)				->							Union[str, Any]:
          return BlipTextConfig(
              vocab_size=self.vocab_size			, hidden_size=self.hidden_size			, projection_dim=self.projection_dim			, num_hidden_layers=self.num_hidden_layers			, num_attention_heads=self.num_attention_heads			, intermediate_size=self.intermediate_size			, dropout=self.dropout			, attention_dropout=self.attention_dropout			, max_position_embeddings=self.max_position_embeddings			, initializer_range=self.initializer_range			, bos_token_id=self.bos_token_id			, )


     def 							_UpperCAmelCase					(					self			, __UpperCAmelCase			, __UpperCAmelCase			, __UpperCAmelCase							)				->							Optional[int]:
          _a					= TFBlipTextModel(config=__UpperCAmelCase							)
          _a					= model(__UpperCAmelCase			, attention_mask=__UpperCAmelCase			, training=__UpperCAmelCase							)
          _a					= model(__UpperCAmelCase			, training=__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							)				->							str:
          _a					= self.prepare_config_and_inputs()
          _a					= config_and_inputs
          _a					= {'input_ids': input_ids, 'attention_mask': input_mask}
          return config, inputs_dict







@require_tf
class 			__lowerCamelCase     (    __snake_case     ,    unittest.TestCase ):

     '''simple docstring'''
     A_				:		Optional[int]			=						(TFBlipTextModel,) if is_tf_available() else ()
     A_				:		List[Any]			=						False
     A_				:		List[str]			=						False
     A_				:		Optional[int]			=						False


     def 							_UpperCAmelCase					(					self							)				->							int:
          _a					= BlipTextModelTester(self							)
          _a					= ConfigTester(self			, config_class=__UpperCAmelCase			, hidden_size=37							)


     def 							_UpperCAmelCase					(					self							)				->							List[Any]:
          self.config_tester.run_common_tests()


     def 							_UpperCAmelCase					(					self							)				->							Optional[Any]:
          _a					= self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_model(*__UpperCAmelCase							)


     def 							_UpperCAmelCase					(					self							)				->							Dict:
          pass


     def 							_UpperCAmelCase					(					self							)				->							str:
          pass


     @unittest.skip(reason='''Blip does not use inputs_embeds'''							)
     def 							_UpperCAmelCase					(					self							)				->							str:
          pass


     @unittest.skip(reason='''BlipTextModel has no base class and is not available in MODEL_MAPPING'''							)
     def 							_UpperCAmelCase					(					self							)				->							int:
          pass


     @unittest.skip(reason='''BlipTextModel has no base class and is not available in MODEL_MAPPING'''							)
     def 							_UpperCAmelCase					(					self							)				->							Optional[int]:
          pass


     @slow
     def 							_UpperCAmelCase					(					self							)				->							Optional[int]:
          for model_name in TF_BLIP_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
               _a					= TFBlipTextModel.from_pretrained(__UpperCAmelCase							)
               self.assertIsNotNone(__UpperCAmelCase							)





     def 							_UpperCAmelCase					(					self			, __UpperCAmelCase=True							)				->							List[str]:
          super().test_pt_tf_model_equivalence(allow_missing_keys=__UpperCAmelCase							)


import unittest

from transformers import DonutProcessor


snake_case_			  = '''naver-clova-ix/donut-base'''


class       SCREAMING_SNAKE_CASE__					(unittest.TestCase     ):





    def       snake_case_				(      self):
         lowercase__    :   Dict      =       DonutProcessor.from_pretrained(a)





    def       snake_case_				(      self):
         lowercase__    :   Tuple      =       {
             'name': 'John Doe',
             'age': '99',
             'city': 'Atlanta',
             'state': 'GA',
             'zip': '30301',
             'phone': '123-4567',
             'nicknames': [{'nickname': 'Johnny'}, {'nickname': 'JD'}],
         }

         lowercase__    :   Tuple      =       (
             '<s_name>John Doe</s_name><s_age>99</s_age><s_city>Atlanta</s_city>'
             '<s_state>GA</s_state><s_zip>30301</s_zip><s_phone>123-4567</s_phone>'
             '<s_nicknames><s_nickname>Johnny</s_nickname>'
             '<sep/><s_nickname>JD</s_nickname></s_nicknames>'
         )
         lowercase__    :   str      =       self.processor.tokenajson(a)

         self.assertDictEqual(a						,   a)

