

import unittest

import numpy as np

from transformers import BlipTextConfig
from transformers.testing_utils import require_torch, slow, torch_device
from transformers.utils import is_torch_available

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, ids_tensor, random_attention_mask


if is_torch_available():
    import torch

    from transformers import BlipTextModel
    from transformers.models.blip.modeling_blip import BLIP_PRETRAINED_MODEL_ARCHIVE_LIST







class 					__lowerCamelCase							:







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







      def       lowerCAmelCase_       (	self  )		->			Optional[int]:
        snake_case_					= ids_tensor([self.batch_size, self.seq_length]				,    self.vocab_size  )

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

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

        snake_case_					= self.get_config()

        return config, input_ids, input_mask







      def       lowerCAmelCase_       (	self  )		->			Dict:
        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       lowerCAmelCase_       (	self				,    lowerCamelCase				,    lowerCamelCase				,    lowerCamelCase  )		->			Optional[Any]:
        snake_case_					= BlipTextModel(config=lowerCamelCase  )
        model.to(lowerCamelCase  )
        model.eval()
        with torch.no_grad():
          snake_case_					= model(lowerCamelCase				,    attention_mask=lowerCamelCase  )
          snake_case_					= model(lowerCamelCase  )
        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       lowerCAmelCase_       (	self  )		->			Optional[int]:
        snake_case_					= self.prepare_config_and_inputs()
        snake_case_		,							snake_case_		,							snake_case_					= config_and_inputs
        snake_case_					= {"""input_ids""": input_ids, """attention_mask""": input_mask}
        return config, inputs_dict







@require_torch
class 					__lowerCamelCase							(      __snake_case    ,				unittest.TestCase      ):
      lowerCamelCase_      : Optional[int]  			=   (BlipTextModel,) if is_torch_available() else ()
      lowerCamelCase_      : Optional[int]  			=   False
      lowerCamelCase_      : List[str]  			=   False
      lowerCamelCase_      : Dict  			=   False







      def       lowerCAmelCase_       (	self  )		->			int:
        snake_case_					= BlipTextModelTester(self  )
        snake_case_					= ConfigTester(self				,    config_class=lowerCamelCase				,    hidden_size=37  )







      def       lowerCAmelCase_       (	self  )		->			Any:
        self.config_tester.run_common_tests()







      def       lowerCAmelCase_       (	self  )		->			Tuple:
        snake_case_					= self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_model(*lowerCamelCase  )







      def       lowerCAmelCase_       (	self  )		->			Dict:
        pass







      def       lowerCAmelCase_       (	self  )		->			Tuple:
        pass







      @unittest.skip(reason="""Blip does not use inputs_embeds"""  )
      def       lowerCAmelCase_       (	self  )		->			Optional[int]:
        pass







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







      @unittest.skip(reason="""BlipTextModel has no base class and is not available in MODEL_MAPPING"""  )
      def       lowerCAmelCase_       (	self  )		->			List[str]:
        pass







      @slow
      def       lowerCAmelCase_       (	self  )		->			Tuple:
        for model_name in BLIP_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
          snake_case_					= BlipTextModel.from_pretrained(lowerCamelCase  )
          self.assertIsNotNone(lowerCamelCase  )







      def       lowerCAmelCase_       (	self  )		->			Tuple:
        super().test_pt_tf_model_equivalence(allow_missing_keys=lowerCamelCase  )


import unittest

from diffusers import __version__
from diffusers.utils import deprecate







class 					__lowerCamelCase							(      unittest.TestCase      ):
      lowerCamelCase_      : Dict  			=   '.'.join([str(int(__version__.split('.'      )[0]      ) + 1      )] + __version__.split('.'      )[1:]      )
      lowerCamelCase_      : int  			=   '0.0.1'







      def       lowerCAmelCase_       (	self  )		->			Optional[int]:
        snake_case_					= {"""deprecated_arg""": 4}

        with self.assertWarns(lowerCamelCase  ) as warning:
          snake_case_					= deprecate("""deprecated_arg"""				,    self.higher_version				,    """message"""				,    take_from=lowerCamelCase  )

        assert output == 4
        assert (
            str(warning.warning  )
            == f'''The `deprecated_arg` argument is deprecated and will be removed in version {self.higher_version}.'''
            " message"
        )







      def       lowerCAmelCase_       (	self  )		->			List[Any]:
        snake_case_					= {"""deprecated_arg""": 4}

        with self.assertWarns(lowerCamelCase  ) as warning:
          snake_case_					= deprecate(("""deprecated_arg""", self.higher_version, """message""")				,    take_from=lowerCamelCase  )

        assert output == 4
        assert (
            str(warning.warning  )
            == f'''The `deprecated_arg` argument is deprecated and will be removed in version {self.higher_version}.'''
            " message"
        )







      def       lowerCAmelCase_       (	self  )		->			int:
        snake_case_					= {"""deprecated_arg_1""": 4, """deprecated_arg_2""": 8}
        with self.assertWarns(lowerCamelCase  ) as warning:
          snake_case_		,							snake_case_					= deprecate(
              ("""deprecated_arg_1""", self.higher_version, """Hey""")				,    ("""deprecated_arg_2""", self.higher_version, """Hey""")				,    take_from=lowerCamelCase				,    )
        assert output_a == 4
        assert output_a == 8
        assert (
            str(warning.warnings[0].message  )
            == "The `deprecated_arg_1` argument is deprecated and will be removed in version"
            f''' {self.higher_version}. Hey'''
        )
        assert (
            str(warning.warnings[1].message  )
            == "The `deprecated_arg_2` argument is deprecated and will be removed in version"
            f''' {self.higher_version}. Hey'''
        )







      def       lowerCAmelCase_       (	self  )		->			Any:
        snake_case_					= {"""deprecated_arg""": 4}

        with self.assertRaises(lowerCamelCase  ) as error:
          deprecate(("""wrong_arg""", self.higher_version, """message""")				,    take_from=lowerCamelCase  )

        assert "test_deprecate_function_incorrect_arg in" in str(error.exception  )
        assert "line" in str(error.exception  )
        assert "got an unexpected keyword argument `deprecated_arg`" in str(error.exception  )







      def       lowerCAmelCase_       (	self  )		->			Optional[Any]:
        with self.assertWarns(lowerCamelCase  ) as warning:
          deprecate(("""deprecated_arg""", self.higher_version, """message""")  )

        assert (
            str(warning.warning  )
            == f'''`deprecated_arg` is deprecated and will be removed in version {self.higher_version}. message'''
        )







      def       lowerCAmelCase_       (	self  )		->			Any:
        with self.assertWarns(lowerCamelCase  ) as warning:
          deprecate(
              ("""deprecated_arg_1""", self.higher_version, """Hey""")				,    ("""deprecated_arg_2""", self.higher_version, """Hey""")				,    )
        assert (
            str(warning.warnings[0].message  )
            == f'''`deprecated_arg_1` is deprecated and will be removed in version {self.higher_version}. Hey'''
        )
        assert (
            str(warning.warnings[1].message  )
            == f'''`deprecated_arg_2` is deprecated and will be removed in version {self.higher_version}. Hey'''
        )







      def       lowerCAmelCase_       (	self  )		->			Any:







        class 					__lowerCamelCase							:
              lowerCamelCase_      : Dict  			=   5

        with self.assertWarns(lowerCamelCase  ) as warning:
          snake_case_					= deprecate(("""arg""", self.higher_version, """message""")				,    take_from=Args()  )

        assert arg == 5
        assert (
            str(warning.warning  )
            == f'''The `arg` attribute is deprecated and will be removed in version {self.higher_version}. message'''
        )







      def       lowerCAmelCase_       (	self  )		->			Any:







        class 					__lowerCamelCase							:
              lowerCamelCase_      : str  			=   5
              lowerCamelCase_      : List[str]  			=   7

        with self.assertWarns(lowerCamelCase  ) as warning:
          snake_case_		,							snake_case_					= deprecate(
              ("""arg""", self.higher_version, """message""")				,    ("""foo""", self.higher_version, """message""")				,    ("""does not exist""", self.higher_version, """message""")				,    take_from=Args()				,    )

        assert arg_a == 5
        assert arg_a == 7
        assert (
            str(warning.warning  )
            == f'''The `arg` attribute is deprecated and will be removed in version {self.higher_version}. message'''
        )
        assert (
            str(warning.warnings[0].message  )
            == f'''The `arg` attribute is deprecated and will be removed in version {self.higher_version}. message'''
        )
        assert (
            str(warning.warnings[1].message  )
            == f'''The `foo` attribute is deprecated and will be removed in version {self.higher_version}. message'''
        )







      def       lowerCAmelCase_       (	self  )		->			int:
        snake_case_					= {"""deprecated_arg""": 4}

        with self.assertRaises(lowerCamelCase  ) as error:
          deprecate(("""wrong_arg""", self.lower_version, """message""")				,    take_from=lowerCamelCase  )

        assert (
            str(error.exception  )
            == "The deprecation tuple ('wrong_arg', '0.0.1', 'message') should be removed since diffusers' version"
            f''' {__version__} is >= {self.lower_version}'''
        )







      def       lowerCAmelCase_       (	self  )		->			List[Any]:
        with self.assertWarns(lowerCamelCase  ) as warning:
          deprecate(("""deprecated_arg""", self.higher_version, """This message is better!!!""")				,    standard_warn=lowerCamelCase  )

        assert str(warning.warning  ) == "This message is better!!!"







      def       lowerCAmelCase_       (	self  )		->			List[Any]:
        with self.assertWarns(lowerCamelCase  ) as warning:
          deprecate(("""deprecated_arg""", self.higher_version, """This message is better!!!""")				,    standard_warn=lowerCamelCase  )
        assert str(warning.warning  ) == "This message is better!!!"
        assert "diffusers/tests/others/test_utils.py" in warning.filename