


'''simple docstring'''

import random
import unittest

import torch

from diffusers import IFInpaintingSuperResolutionPipeline
from diffusers.utils import floats_tensor
from diffusers.utils.import_utils import is_xformers_available
from diffusers.utils.testing_utils import skip_mps, torch_device

from ..pipeline_params import (
    TEXT_GUIDED_IMAGE_INPAINTING_BATCH_PARAMS,
    TEXT_GUIDED_IMAGE_INPAINTING_PARAMS,
)
from ..test_pipelines_common import PipelineTesterMixin
from . import IFPipelineTesterMixin
@skip_mps
class _lowerCamelCase	(						__lowercase		,					__lowercase		,					unittest.TestCase							):



  '''simple docstring'''







  A_     :      Dict				   =    IFInpaintingSuperResolutionPipeline
  A_     :      str				   =    TEXT_GUIDED_IMAGE_INPAINTING_PARAMS - {"""width""", """height"""}
  A_     :      Dict				   =    TEXT_GUIDED_IMAGE_INPAINTING_BATCH_PARAMS.union({"""original_image"""}							)
  A_     :      Optional[int]				   =    PipelineTesterMixin.required_optional_params - {"""latents"""}







  def        __lowerCAmelCase		( self		:						Tuple      )  ->			List[str]:
   return self._get_superresolution_dummy_components()







  def        __lowerCAmelCase		( self		:						Optional[Any]  ,					_A		:						str  ,					_A		:						int=0      )  ->			Any:
   if str(_a      ).startswith('mps'      ):
    __magic_name__	:   Optional[Any]					     =					torch.manual_seed(_a      )
   else:
    __magic_name__	:   Dict					     =					torch.Generator(device=_a      ).manual_seed(_a      )

   __magic_name__	:   Tuple					     =					floats_tensor((1, 3, 16, 16)  ,					rng=random.Random(_a      )      ).to(_a      )
   __magic_name__	:   int					     =					floats_tensor((1, 3, 32, 32)  ,					rng=random.Random(_a      )      ).to(_a      )
   __magic_name__	:   List[Any]					     =					floats_tensor((1, 3, 32, 32)  ,					rng=random.Random(_a      )      ).to(_a      )

   __magic_name__	:   List[Any]					     =					{
       'prompt': 'A painting of a squirrel eating a burger',
       'image': image,
       'original_image': original_image,
       'mask_image': mask_image,
       'generator': generator,
       'num_inference_steps': 2,
       'output_type': 'numpy',
   }

   return inputs







  @unittest.skipIf(
      torch_device != 'cuda' or not is_xformers_available()  ,					reason='XFormers attention is only available with CUDA and `xformers` installed'  ,					)
  def        __lowerCAmelCase		( self		:						Union[str, Any]      )  ->			Any:
   self._test_xformers_attention_forwardGenerator_pass(expected_max_diff=1E-3      )







  def        __lowerCAmelCase		( self		:						Dict      )  ->			List[Any]:
   self._test_save_load_optional_components()







  @unittest.skipIf(torch_device != 'cuda'  ,					reason='float16 requires CUDA'      )
  def        __lowerCAmelCase		( self		:						List[str]      )  ->			int:
   # Due to non-determinism in save load of the hf-internal-testing/tiny-random-t5 text encoder
   super().test_save_load_floataa(expected_max_diff=1E-1      )







  def        __lowerCAmelCase		( self		:						Tuple      )  ->			Optional[int]:
   self._test_attention_slicing_forward_pass(expected_max_diff=1E-2      )







  def        __lowerCAmelCase		( self		:						Dict      )  ->			List[str]:
   self._test_save_load_local()







  def        __lowerCAmelCase		( self		:						Any      )  ->			List[Any]:
   self._test_inference_batch_single_identical(
       expected_max_diff=1E-2  ,					)



'''simple docstring'''

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

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

import _pytest

from transformers.testing_utils import HfDoctestModule, HfDocTestParser


# allow having multiple repository checkouts and not needing to remember to rerun
# 'pip install -e .[dev]' when switching between checkouts and running tests.
lowerCAmelCase				:Optional[int]        =      abspath(join(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 lowerCamelCase      (      lowerCAmelCase    :     Tuple		):





	"""simple docstring"""







	config.addinivalue_line(
	    'markers'		,		'is_pt_tf_cross_test: mark test to run only when PT and TF interactions are tested'		)
	config.addinivalue_line(
	    'markers'		,		'is_pt_flax_cross_test: mark test to run only when PT and FLAX interactions are tested'		)
	config.addinivalue_line('markers'		,		'is_pipeline_test: mark test to run only when pipelines are tested'		)
	config.addinivalue_line('markers'		,		'is_staging_test: mark test to run only in the staging environment'		)
	config.addinivalue_line('markers'		,		'accelerate_tests: mark test that require accelerate'		)
	config.addinivalue_line('markers'		,		'tool_tests: mark the tool tests that are run on their specific schedule'		)





def lowerCamelCase      (      lowerCAmelCase    :     Any		):





	"""simple docstring"""







	from transformers.testing_utils import pytest_addoption_shared

	pytest_addoption_shared(lowerCAmelCase		)





def lowerCamelCase      (      lowerCAmelCase    :     Dict		):





	"""simple docstring"""







	from transformers.testing_utils import pytest_terminal_summary_main

	__magic_name__	:   Tuple					     =					terminalreporter.config.getoption('--make-reports'		)
	if make_reports:
		pytest_terminal_summary_main(lowerCAmelCase		,		id=lowerCAmelCase		)





def lowerCamelCase      (      lowerCAmelCase    :     List[Any]		,		lowerCAmelCase    :     Tuple		):





	"""simple docstring"""







	if exitstatus == 5:
		__magic_name__	:   Any					     =					0


# Doctest custom flag to ignore output.
lowerCAmelCase				:List[str]        =      doctest.register_optionflag('''IGNORE_RESULT''')

lowerCAmelCase				:Union[str, Any]        =      doctest.OutputChecker
class _lowerCamelCase	(						lowercase__							):



		'''simple docstring'''







		def        __lowerCAmelCase		( self		:						List[str]  ,					_A		:						Tuple  ,					_A		:						Tuple  ,					_A		:						str      )  ->			int:
			if IGNORE_RESULT & optionflags:
				return True
			return OutputChecker.check_output(self  ,					_A  ,					_A  ,					_A      )







lowerCAmelCase				:Optional[Any]        =      CustomOutputChecker
lowerCAmelCase				:int        =      HfDoctestModule





lowerCAmelCase				:Any        =      HfDocTestParser