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 __snake_case				:




   def __init__(    self			:				Dict       ,	_lowercase			:				Optional[int]       ,	_lowercase			:				int=12       ,	_lowercase			:				Optional[Any]=7       ,	_lowercase			:				int=True       ,	_lowercase			:				List[Any]=True       ,	_lowercase			:				int=True       ,	_lowercase			:				int=99       ,	_lowercase			:				Union[str, Any]=32       ,	_lowercase			:				Dict=32       ,	_lowercase			:				List[Any]=2       ,	_lowercase			:				Optional[int]=4       ,	_lowercase			:				Optional[Any]=37       ,	_lowercase			:				Union[str, Any]=0.1       ,	_lowercase			:				Tuple=0.1       ,	_lowercase			:				List[Any]=5_12       ,	_lowercase			:				Dict=0.02       ,	_lowercase			:				Dict=0       ,	_lowercase			:				List[str]=None       ,	):



     """simple docstring"""






     SCREAMING_SNAKE_CASE__										=      parent
     SCREAMING_SNAKE_CASE__										=      batch_size
     SCREAMING_SNAKE_CASE__										=      seq_length
     SCREAMING_SNAKE_CASE__										=      is_training
     SCREAMING_SNAKE_CASE__										=      use_input_mask
     SCREAMING_SNAKE_CASE__										=      use_labels
     SCREAMING_SNAKE_CASE__										=      vocab_size
     SCREAMING_SNAKE_CASE__										=      hidden_size
     SCREAMING_SNAKE_CASE__										=      projection_dim
     SCREAMING_SNAKE_CASE__										=      num_hidden_layers
     SCREAMING_SNAKE_CASE__										=      num_attention_heads
     SCREAMING_SNAKE_CASE__										=      intermediate_size
     SCREAMING_SNAKE_CASE__										=      dropout
     SCREAMING_SNAKE_CASE__										=      attention_dropout
     SCREAMING_SNAKE_CASE__										=      max_position_embeddings
     SCREAMING_SNAKE_CASE__										=      initializer_range
     SCREAMING_SNAKE_CASE__										=      scope
     SCREAMING_SNAKE_CASE__										=      bos_token_id




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



     """simple docstring"""






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

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

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

     SCREAMING_SNAKE_CASE__										=      self.get_config()

     return config, input_ids, tf.convert_to_tensor(_lowercase      )




   def 	__a						(    self			:				Tuple      ):



     """simple docstring"""






     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 	__a						(    self			:				Optional[int]       ,	_lowercase			:				int       ,	_lowercase			:				str       ,	_lowercase			:				List[str]      ):



     """simple docstring"""






     SCREAMING_SNAKE_CASE__										=      TFBlipTextModel(config=_lowercase      )
     SCREAMING_SNAKE_CASE__										=      model(_lowercase       ,	attention_mask=_lowercase       ,	training=_lowercase      )
     SCREAMING_SNAKE_CASE__										=      model(_lowercase       ,	training=_lowercase      )
     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 	__a						(    self			:				Optional[int]      ):



     """simple docstring"""






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







@require_tf
class __snake_case				(						lowerCamelCase_   ,		unittest.TestCase		):
   lowerCAmelCase_														=							(TFBlipTextModel,) if is_tf_available() else ()
   lowerCAmelCase_														=							False
   lowerCAmelCase_														=							False
   lowerCAmelCase_														=							False




   def 	__a						(    self			:				Optional[Any]      ):



     """simple docstring"""






     SCREAMING_SNAKE_CASE__										=      BlipTextModelTester(self      )
     SCREAMING_SNAKE_CASE__										=      ConfigTester(self       ,	config_class=_lowercase       ,	hidden_size=37      )




   def 	__a						(    self			:				Any      ):



     """simple docstring"""






     self.config_tester.run_common_tests()




   def 	__a						(    self			:				Tuple      ):



     """simple docstring"""






     SCREAMING_SNAKE_CASE__										=      self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_model(*_lowercase      )




   def 	__a						(    self			:				Optional[Any]      ):



     """simple docstring"""






     pass




   def 	__a						(    self			:				Tuple      ):



     """simple docstring"""






     pass




   @unittest.skip(reason="""Blip does not use inputs_embeds"""      )
   def 	__a						(    self			:				Any      ):



     """simple docstring"""






     pass




   @unittest.skip(reason="""BlipTextModel has no base class and is not available in MODEL_MAPPING"""      )
   def 	__a						(    self			:				Tuple      ):



     """simple docstring"""






     pass




   @unittest.skip(reason="""BlipTextModel has no base class and is not available in MODEL_MAPPING"""      )
   def 	__a						(    self			:				Dict      ):



     """simple docstring"""






     pass




   @slow
   def 	__a						(    self			:				int      ):



     """simple docstring"""






     for model_name in TF_BLIP_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
       SCREAMING_SNAKE_CASE__										=      TFBlipTextModel.from_pretrained(_lowercase      )
       self.assertIsNotNone(_lowercase      )




   def 	__a						(    self			:				Tuple       ,	_lowercase			:				Optional[int]=True      ):



     """simple docstring"""






     super().test_pt_tf_model_equivalence(allow_missing_keys=_lowercase      )

# tests directory-specific settings - this file is run automatically
# by pytest before any tests are run

import sys
import warnings
from os.path import abspath, dirname, join


# allow having multiple repository checkouts and not needing to remember to rerun
# 'pip install -e .[dev]' when switching between checkouts and running tests.
__lowerCamelCase			: Any							   =		abspath(join(dirname(dirname(__file__)), '''src'''))
sys.path.insert(1, git_repo_path)

# silence FutureWarning warnings in tests since often we can't act on them until
# they become normal warnings - i.e. the tests still need to test the current functionality
warnings.simplefilter(action='''ignore''', category=FutureWarning)



def 	__SCREAMING_SNAKE_CASE  (					__UpperCamelCase    :       Optional[int]	)							->					Any:







  """simple docstring"""





  from diffusers.utils.testing_utils import pytest_addoption_shared

  pytest_addoption_shared(__UpperCamelCase	)






def 	__SCREAMING_SNAKE_CASE  (					__UpperCamelCase    :       Dict	)							->					Optional[Any]:







  """simple docstring"""





  from diffusers.utils.testing_utils import pytest_terminal_summary_main

  SCREAMING_SNAKE_CASE__										=      terminalreporter.config.getoption("""--make-reports"""	)
  if make_reports:
    pytest_terminal_summary_main(__UpperCamelCase ,     id=__UpperCamelCase	)
