


'''simple docstring'''






import random
import unittest

import torch

from diffusers import IFInpaintingPipeline
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 	a       (       __snake_case					,			__snake_case					,			unittest.TestCase    ):
 _lowerCAmelCase	   =		IFInpaintingPipeline
 _lowerCAmelCase	   =		TEXT_GUIDED_IMAGE_INPAINTING_PARAMS - {"width", "height"}
 _lowerCAmelCase	   =		TEXT_GUIDED_IMAGE_INPAINTING_BATCH_PARAMS
 _lowerCAmelCase	   =		PipelineTesterMixin.required_optional_params - {"latents"}
 def 							__UpperCAmelCase						(	self  )   ->							Dict:
      return self._get_dummy_components()
 def 							__UpperCAmelCase						(	self ,			__magic_name__ ,			__magic_name__=0  )   ->							Optional[Any]:
      if str(lowerCamelCase_  ).startswith('mps'  ):
           _a      =							torch.manual_seed(lowerCamelCase_  )
      else:
           _a      =							torch.Generator(device=lowerCamelCase_  ).manual_seed(lowerCamelCase_  )

      _a      =							floats_tensor((1, 3, 32, 32) ,			rng=random.Random(lowerCamelCase_  )  ).to(lowerCamelCase_  )
      _a      =							floats_tensor((1, 3, 32, 32) ,			rng=random.Random(lowerCamelCase_  )  ).to(lowerCamelCase_  )

      _a      =							{
          """prompt""": """A painting of a squirrel eating a burger""",
          """image""": 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 							__UpperCAmelCase						(	self  )   ->							Any:
      self._test_xformers_attention_forwardGenerator_pass(expected_max_diff=1e-3  )
 def 							__UpperCAmelCase						(	self  )   ->							Union[str, Any]:
      self._test_save_load_optional_components()
 @unittest.skipIf(torch_device != 'cuda' ,			reason='float16 requires CUDA'  )
 def 							__UpperCAmelCase						(	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 							__UpperCAmelCase						(	self  )   ->							Optional[Any]:
      self._test_attention_slicing_forward_pass(expected_max_diff=1e-2  )
 def 							__UpperCAmelCase						(	self  )   ->							str:
      self._test_save_load_local()




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





'''simple docstring'''






import pytest
import requests

from datasets.utils.file_utils import http_head

from .utils import OfflineSimulationMode, RequestWouldHangIndefinitelyError, offline






@pytest.mark.integration
def 		_A			()				->					Optional[Any]:




     '''simple docstring'''



     with offline(OfflineSimulationMode.CONNECTION_TIMES_OUT						):
          with pytest.raises(lowerCAmelCase__						):
               requests.request('GET'			,  'https://huggingface.co'						)
          with pytest.raises(requests.exceptions.ConnectTimeout						):
               requests.request('GET'			,  'https://huggingface.co'			,  timeout=1.0						)






@pytest.mark.integration
def 		_A			()				->					Any:




     '''simple docstring'''



     with offline(OfflineSimulationMode.CONNECTION_FAILS						):
          with pytest.raises(requests.exceptions.ConnectionError						):
               requests.request('GET'			,  'https://huggingface.co'						)






def 		_A			()				->					Dict:




     '''simple docstring'''



     with offline(OfflineSimulationMode.HF_DATASETS_OFFLINE_SET_TO_1						):
          with pytest.raises(lowerCAmelCase__						):
               http_head('https://huggingface.co'						)

