
import unittest
from dataclasses import dataclass
from typing import List, Union

import numpy as np
import PIL.Image

from diffusers.utils.outputs import BaseOutput







@dataclass
class 							UpperCAmelCase	(   __lowerCamelCase					):
					a__: Union[List[PIL.Image.Image], np.ndarray]







class 							UpperCAmelCase	(   unittest.TestCase					):

					def        _lowerCAmelCase	(			self      :					int					):
											lowercase       :    List[str]											=  CustomOutput(images=np.random.rand(1 ,      3 ,      4 ,      4					)					)

											# check every way of getting the attribute
											assert isinstance(outputs.images ,      np.ndarray					)
											assert outputs.images.shape == (1, 3, 4, 4)
											assert isinstance(outputs['''images'''] ,      np.ndarray					)
											assert outputs["images"].shape == (1, 3, 4, 4)
											assert isinstance(outputs[0] ,      np.ndarray					)
											assert outputs[0].shape == (1, 3, 4, 4)

											# test with a non-tensor attribute
											lowercase       :    Optional[Any]											=  CustomOutput(images=[PIL.Image.new('''RGB''' ,      (4, 4)					)]					)

											# check every way of getting the attribute
											assert isinstance(outputs.images ,      lowerCAmelCase					)
											assert isinstance(outputs.images[0] ,      PIL.Image.Image					)
											assert isinstance(outputs['''images'''] ,      lowerCAmelCase					)
											assert isinstance(outputs['''images'''][0] ,      PIL.Image.Image					)
											assert isinstance(outputs[0] ,      lowerCAmelCase					)
											assert isinstance(outputs[0][0] ,      PIL.Image.Image					)




					def        _lowerCAmelCase	(			self      :					str					):
											# test output reinitialization with a `dict` for compatibility with `accelerate`
											lowercase       :    Any											=  CustomOutput({'''images''': np.random.rand(1 ,      3 ,      4 ,      4					)}					)

											# check every way of getting the attribute
											assert isinstance(outputs.images ,      np.ndarray					)
											assert outputs.images.shape == (1, 3, 4, 4)
											assert isinstance(outputs['''images'''] ,      np.ndarray					)
											assert outputs["images"].shape == (1, 3, 4, 4)
											assert isinstance(outputs[0] ,      np.ndarray					)
											assert outputs[0].shape == (1, 3, 4, 4)

											# test with a non-tensor attribute
											lowercase       :    Optional[Any]											=  CustomOutput({'''images''': [PIL.Image.new('''RGB''' ,      (4, 4)					)]}					)

											# check every way of getting the attribute
											assert isinstance(outputs.images ,      lowerCAmelCase					)
											assert isinstance(outputs.images[0] ,      PIL.Image.Image					)
											assert isinstance(outputs['''images'''] ,      lowerCAmelCase					)
											assert isinstance(outputs['''images'''][0] ,      PIL.Image.Image					)
											assert isinstance(outputs[0] ,      lowerCAmelCase					)
											assert isinstance(outputs[0][0] ,      PIL.Image.Image					)







snake_case__  							=							"""
# Diffusers installation
! pip install diffusers transformers datasets accelerate
# To install from source instead of the last release, comment the command above and uncomment the following one.
# ! pip install git+https://github.com/huggingface/diffusers.git
"""

snake_case__  							=							[{"""type""": """code""", """content""": INSTALL_CONTENT}]


