



"""simple docstring"""
import pytest

import datasets


# Import fixture modules as plugins
_lowerCAmelCase    :List[str]     =					['tests.fixtures.files', 'tests.fixtures.hub', 'tests.fixtures.fsspec']





def  lowerCamelCase_						(UpperCamelCase__		:		List[Any]     ,       UpperCamelCase__		:		Optional[Any]							):
    # Mark tests as "unit" by default if not marked as "integration" (or already marked as "unit")
    for item in items:
        if any(marker in item.keywords for marker in ['''integration''', '''unit''']							):
            continue
        item.add_marker(pytest.mark.unit							)





def  lowerCamelCase_						(UpperCamelCase__		:		Dict							):
    config.addinivalue_line('''markers'''     ,       '''torchaudio_latest: mark test to run with torchaudio>=0.12'''							)





@pytest.fixture(autouse=UpperCamelCase__							)
def  lowerCamelCase_						(UpperCamelCase__		:		Any     ,       UpperCamelCase__		:		str							):
    # test_hf_cache_home = tmp_path_factory.mktemp("cache")  # TODO: why a cache dir per test function does not work?
    _UpperCAmelCase							:  Union[str, Any]											=    tmp_path_factory.getbasetemp() / '''cache'''
    _UpperCAmelCase							:  Any											=    test_hf_cache_home / '''datasets'''
    _UpperCAmelCase							:  Dict											=    test_hf_cache_home / '''metrics'''
    _UpperCAmelCase							:  Tuple											=    test_hf_cache_home / '''modules'''
    monkeypatch.setattr('''datasets.config.HF_DATASETS_CACHE'''     ,       str(UpperCamelCase__							)							)
    monkeypatch.setattr('''datasets.config.HF_METRICS_CACHE'''     ,       str(UpperCamelCase__							)							)
    monkeypatch.setattr('''datasets.config.HF_MODULES_CACHE'''     ,       str(UpperCamelCase__							)							)
    _UpperCAmelCase							:  Union[str, Any]											=    test_hf_datasets_cache / '''downloads'''
    monkeypatch.setattr('''datasets.config.DOWNLOADED_DATASETS_PATH'''     ,       str(UpperCamelCase__							)							)
    _UpperCAmelCase							:  Union[str, Any]											=    test_hf_datasets_cache / '''downloads''' / '''extracted'''
    monkeypatch.setattr('''datasets.config.EXTRACTED_DATASETS_PATH'''     ,       str(UpperCamelCase__							)							)





@pytest.fixture(autouse=UpperCamelCase__     ,       scope='''session'''							)
def  lowerCamelCase_						():
    datasets.disable_progress_bar()





@pytest.fixture(autouse=UpperCamelCase__							)
def  lowerCamelCase_						(UpperCamelCase__		:		int							):
    # don't take tests into account when counting downloads
    monkeypatch.setattr('''datasets.config.HF_UPDATE_DOWNLOAD_COUNTS'''     ,       UpperCamelCase__							)





@pytest.fixture
def  lowerCamelCase_						(UpperCamelCase__		:		Any							):
    # Required to suppress RemovedIn20Warning when feature(s) are not compatible with SQLAlchemy 2.0
    # To be removed once SQLAlchemy 2.0 supported
    monkeypatch.setattr('''sqlalchemy.util.deprecations.SILENCE_UBER_WARNING'''     ,       UpperCamelCase__							)







"""simple docstring"""
import random
import unittest

import torch

from diffusers import IFImgaImgSuperResolutionPipeline
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_VARIATION_BATCH_PARAMS, TEXT_GUIDED_IMAGE_VARIATION_PARAMS
from ..test_pipelines_common import PipelineTesterMixin
from . import IFPipelineTesterMixin
@skip_mps
class 							_UpperCAmelCase							( a		,a		,unittest.TestCase      ):





     '''simple docstring'''



     a__									=IFImgaImgSuperResolutionPipeline
     a__									=TEXT_GUIDED_IMAGE_VARIATION_PARAMS - {'''width''', '''height'''}
     a__									=TEXT_GUIDED_IMAGE_VARIATION_BATCH_PARAMS.union({'''original_image'''}      )
     a__									=PipelineTesterMixin.required_optional_params - {'''latents'''}





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





     def  __lowerCAmelCase	(					self       ,	A       ,	A=0		)							->					Union[str, Any]:
         if str(A		).startswith('''mps'''		):
             _UpperCAmelCase							:  Any											=    torch.manual_seed(A		)
         else:
             _UpperCAmelCase							:  int											=    torch.Generator(device=A		).manual_seed(A		)

         _UpperCAmelCase							:  str											=    floats_tensor((1, 3, 3_2, 3_2)       ,	rng=random.Random(A		)		).to(A		)
         _UpperCAmelCase							:  Dict											=    floats_tensor((1, 3, 1_6, 1_6)       ,	rng=random.Random(A		)		).to(A		)

         _UpperCAmelCase							:  List[Any]											=    {
             '''prompt''': '''A painting of a squirrel eating a burger''',
             '''image''': image,
             '''original_image''': original_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		)							->					List[Any]:
         self._test_xformers_attention_forwardGenerator_pass(expected_max_diff=1E-3		)





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





     @unittest.skipIf(torch_device != '''cuda'''       ,	reason='''float16 requires CUDA'''		)
     def  __lowerCAmelCase	(					self		)							->					Optional[Any]:
         # 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		)							->					int:
         self._test_attention_slicing_forward_pass(expected_max_diff=1E-2		)





     def  __lowerCAmelCase	(					self		)							->					Union[str, Any]:
         self._test_save_load_local()





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


