



'''simple docstring'''





import unittest

import numpy as np

from transformers.testing_utils import require_torch, require_vision
from transformers.utils import is_torch_available, is_vision_available

from ...test_image_processing_common import ImageProcessingSavingTestMixin


if is_torch_available():
   import torch

if is_vision_available():
   from PIL import Image

   from transformers import TvltImageProcessor

def 	a_					(							_lowerCAmelCase	,_lowerCAmelCase=10	,_lowerCAmelCase=10	,_lowerCAmelCase=False	,_lowerCAmelCase=False	)				->				Any:
  __lowerCamelCase	:	Union[str, Any]   	=			[]
  for i in range(image_processor_tester.num_frames	):
    video.append(np.random.randint(255	,size=(image_processor_tester.num_channels, width, height)	,dtype=np.uinta	)	)

  if not numpify and not torchify:
    # PIL expects the channel dimension as last dimension
    __lowerCamelCase	:	List[str]   	=			[Image.fromarray(np.moveaxis(_lowerCAmelCase	,0	,-1	)	) for frame in video]

  if torchify:
    __lowerCamelCase	:	Any   	=			[torch.from_numpy(_lowerCAmelCase	) for frame in video]

  return video

def 	a_					(							_lowerCAmelCase	,_lowerCAmelCase=False	,_lowerCAmelCase=False	,_lowerCAmelCase=False	)				->				Dict:
  assert not (numpify and torchify), "You cannot specify both numpy and PyTorch tensors at the same time"

  __lowerCamelCase	:	List[Any]   	=			[]
  for i in range(image_processor_tester.batch_size	):
    if equal_resolution:
      __lowerCamelCase	:	int   	=			image_processor_tester.max_resolution
    else:
      __lowerCamelCase	,__lowerCamelCase	:	int   	=			np.random.choice(
          np.arange(image_processor_tester.min_resolution	,image_processor_tester.max_resolution	)	,2	)
      __lowerCamelCase	:	int   	=			prepare_video(
          image_processor_tester=_lowerCAmelCase	,width=_lowerCAmelCase	,height=_lowerCAmelCase	,numpify=_lowerCAmelCase	,torchify=_lowerCAmelCase	,)
    video_inputs.append(_lowerCAmelCase	)

  return video_inputs






class  lowerCamelCase_   (    unittest.TestCase					):
  """simple docstring"""




  def __init__(			self				:     Optional[Any]      ,     _a				:     Any      ,     _a				:     Any=7      ,     _a				:     List[Any]=3      ,     _a				:     Dict=4      ,     _a				:     Optional[int]=18      ,     _a				:     Dict=30      ,     _a				:     Tuple=400      ,     _a				:     Any=True      ,     _a				:     Optional[Any]=None      ,     _a				:     List[Any]=True      ,     _a				:     Tuple=[0.5, 0.5, 0.5]      ,     _a				:     Optional[Any]=[0.5, 0.5, 0.5]      ,     _a				:     Union[str, Any]=True      ,     _a				:     int=None      ,     ) -> List[str]:
    __lowerCamelCase	:	Union[str, Any]   	=			size if size is not None else {'shortest_edge': 18}
    __lowerCamelCase	:	List[Any]   	=			crop_size if crop_size is not None else {'height': 18, 'width': 18}

    __lowerCamelCase	:	List[str]   	=			parent
    __lowerCamelCase	:	Optional[int]   	=			batch_size
    __lowerCamelCase	:	Dict   	=			num_channels
    __lowerCamelCase	:	str   	=			num_frames
    __lowerCamelCase	:	Dict   	=			image_size
    __lowerCamelCase	:	Dict   	=			min_resolution
    __lowerCamelCase	:	List[Any]   	=			max_resolution
    __lowerCamelCase	:	Tuple   	=			do_resize
    __lowerCamelCase	:	Dict   	=			size
    __lowerCamelCase	:	int   	=			do_normalize
    __lowerCamelCase	:	Any   	=			image_mean
    __lowerCamelCase	:	Dict   	=			image_std
    __lowerCamelCase	:	List[str]   	=			do_center_crop
    __lowerCamelCase	:	int   	=			crop_size




  def 						_lowercase					(			self				:     List[str]       ) -> Optional[Any]:
    return {
        "image_mean": self.image_mean,
        "image_std": self.image_std,
        "do_normalize": self.do_normalize,
        "do_resize": self.do_resize,
        "size": self.size,
        "do_center_crop": self.do_center_crop,
        "crop_size": self.crop_size,
    }






@require_torch
@require_vision
class  lowerCamelCase_   (    SCREAMING_SNAKE_CASE_       ,       unittest.TestCase					):
  """simple docstring"""




  a_							 =TvltImageProcessor if is_vision_available() else None




  def 						_lowercase					(			self				:     Optional[int]       ) -> Tuple:
    __lowerCamelCase	:	str   	=			TvltImageProcessorTester(self       )




  @property
  def 						_lowercase					(			self				:     Union[str, Any]       ) -> Any:
    return self.image_processor_tester.prepare_image_processor_dict()




  def 						_lowercase					(			self				:     List[str]       ) -> Any:
    __lowerCamelCase	:	str   	=			self.image_processing_class(**self.image_processor_dict       )
    self.assertTrue(hasattr(_a      ,     'image_mean'       )       )
    self.assertTrue(hasattr(_a      ,     'image_std'       )       )
    self.assertTrue(hasattr(_a      ,     'do_normalize'       )       )
    self.assertTrue(hasattr(_a      ,     'do_resize'       )       )
    self.assertTrue(hasattr(_a      ,     'do_center_crop'       )       )
    self.assertTrue(hasattr(_a      ,     'size'       )       )




  def 						_lowercase					(			self				:     Union[str, Any]       ) -> Any:
    # Initialize image_processor
    __lowerCamelCase	:	List[Any]   	=			self.image_processing_class(**self.image_processor_dict       )
    # create random PIL videos
    __lowerCamelCase	:	int   	=			prepare_video_inputs(self.image_processor_tester      ,     equal_resolution=_a       )
    for video in video_inputs:
      self.assertIsInstance(_a      ,     _a       )
      self.assertIsInstance(video[0]      ,     Image.Image       )

    # Test not batched input
    __lowerCamelCase	:	List[str]   	=			image_processor(video_inputs[0]      ,     return_tensors='pt'       ).pixel_values
    self.assertEqual(
        encoded_videos.shape      ,     (
            1,
            self.image_processor_tester.num_frames,
            self.image_processor_tester.num_channels,
            self.image_processor_tester.crop_size['height'],
            self.image_processor_tester.crop_size['width'],
        )      ,     )

    # Test batched
    __lowerCamelCase	:	Dict   	=			image_processor(_a      ,     return_tensors='pt'       ).pixel_values
    self.assertEqual(
        encoded_videos.shape      ,     (
            self.image_processor_tester.batch_size,
            self.image_processor_tester.num_frames,
            self.image_processor_tester.num_channels,
            self.image_processor_tester.crop_size['height'],
            self.image_processor_tester.crop_size['width'],
        )      ,     )




  def 						_lowercase					(			self				:     Tuple       ) -> int:
    # Initialize image_processor
    __lowerCamelCase	:	Optional[Any]   	=			self.image_processing_class(**self.image_processor_dict       )
    # create random numpy tensors
    __lowerCamelCase	:	Union[str, Any]   	=			prepare_video_inputs(self.image_processor_tester      ,     equal_resolution=_a      ,     numpify=_a       )
    for video in video_inputs:
      self.assertIsInstance(_a      ,     _a       )
      self.assertIsInstance(video[0]      ,     np.ndarray       )

    # Test not batched input
    __lowerCamelCase	:	List[Any]   	=			image_processor(video_inputs[0]      ,     return_tensors='pt'       ).pixel_values
    self.assertEqual(
        encoded_videos.shape      ,     (
            1,
            self.image_processor_tester.num_frames,
            self.image_processor_tester.num_channels,
            self.image_processor_tester.crop_size['height'],
            self.image_processor_tester.crop_size['width'],
        )      ,     )

    # Test batched
    __lowerCamelCase	:	Optional[int]   	=			image_processor(_a      ,     return_tensors='pt'       ).pixel_values
    self.assertEqual(
        encoded_videos.shape      ,     (
            self.image_processor_tester.batch_size,
            self.image_processor_tester.num_frames,
            self.image_processor_tester.num_channels,
            self.image_processor_tester.crop_size['height'],
            self.image_processor_tester.crop_size['width'],
        )      ,     )




  def 						_lowercase					(			self				:     Union[str, Any]       ) -> int:
    # Initialize image_processor
    __lowerCamelCase	:	Any   	=			self.image_processing_class(**self.image_processor_dict       )
    # create random PyTorch tensors
    __lowerCamelCase	:	Union[str, Any]   	=			prepare_video_inputs(self.image_processor_tester      ,     equal_resolution=_a      ,     torchify=_a       )
    for video in video_inputs:
      self.assertIsInstance(_a      ,     _a       )
      self.assertIsInstance(video[0]      ,     torch.Tensor       )

    # Test not batched input
    __lowerCamelCase	:	str   	=			image_processor(video_inputs[0]      ,     return_tensors='pt'       ).pixel_values
    self.assertEqual(
        encoded_videos.shape      ,     (
            1,
            self.image_processor_tester.num_frames,
            self.image_processor_tester.num_channels,
            self.image_processor_tester.crop_size['height'],
            self.image_processor_tester.crop_size['width'],
        )      ,     )

    # Test batched
    __lowerCamelCase	:	Dict   	=			image_processor(_a      ,     return_tensors='pt'       ).pixel_values
    self.assertEqual(
        encoded_videos.shape      ,     (
            self.image_processor_tester.batch_size,
            self.image_processor_tester.num_frames,
            self.image_processor_tester.num_channels,
            self.image_processor_tester.crop_size['height'],
            self.image_processor_tester.crop_size['width'],
        )      ,     )











'''simple docstring'''





import unittest

from diffusers import __version__
from diffusers.utils import deprecate






class  lowerCamelCase_   (    unittest.TestCase					):
  """simple docstring"""




  a_							 =""".""".join([str(int(__version__.split("""."""					)[0]					) + 1					)] + __version__.split("""."""					)[1:]					)
  a_							 ="""0.0.1"""




  def 						_lowercase					(			self				:     Optional[Any]       ) -> int:
    __lowerCamelCase	:	Any   	=			{'deprecated_arg': 4}

    with self.assertWarns(_a       ) as warning:
      __lowerCamelCase	:	Optional[int]   	=			deprecate('deprecated_arg'      ,     self.higher_version      ,     'message'      ,     take_from=_a       )

    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 						_lowercase					(			self				:     Union[str, Any]       ) -> Optional[int]:
    __lowerCamelCase	:	int   	=			{'deprecated_arg': 4}

    with self.assertWarns(_a       ) as warning:
      __lowerCamelCase	:	Optional[Any]   	=			deprecate(('deprecated_arg', self.higher_version, 'message')      ,     take_from=_a       )

    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 						_lowercase					(			self				:     int       ) -> Optional[Any]:
    __lowerCamelCase	:	Optional[int]   	=			{'deprecated_arg_1': 4, 'deprecated_arg_2': 8}
    with self.assertWarns(_a       ) as warning:
      __lowerCamelCase	,__lowerCamelCase	:	Any   	=			deprecate(
          ('deprecated_arg_1', self.higher_version, 'Hey')      ,     ('deprecated_arg_2', self.higher_version, 'Hey')      ,     take_from=_a      ,     )
    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 						_lowercase					(			self				:     str       ) -> Optional[Any]:
    __lowerCamelCase	:	Optional[int]   	=			{'deprecated_arg': 4}

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

    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 						_lowercase					(			self				:     Optional[Any]       ) -> Union[str, Any]:
    with self.assertWarns(_a       ) 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 						_lowercase					(			self				:     Optional[Any]       ) -> Union[str, Any]:
    with self.assertWarns(_a       ) 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 						_lowercase					(			self				:     Union[str, Any]       ) -> Dict:






    class  lowerCamelCase_   :
      """simple docstring"""




      a_							 =5

    with self.assertWarns(_a       ) as warning:
      __lowerCamelCase	:	int   	=			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 						_lowercase					(			self				:     Dict       ) -> Union[str, Any]:






    class  lowerCamelCase_   :
      """simple docstring"""




      a_							 =5
      a_							 =7

    with self.assertWarns(_a       ) as warning:
      __lowerCamelCase	,__lowerCamelCase	:	List[str]   	=			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 						_lowercase					(			self				:     Union[str, Any]       ) -> List[str]:
    __lowerCamelCase	:	Union[str, Any]   	=			{'deprecated_arg': 4}

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

    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 						_lowercase					(			self				:     Optional[int]       ) -> str:
    with self.assertWarns(_a       ) as warning:
      deprecate(('deprecated_arg', self.higher_version, 'This message is better!!!')      ,     standard_warn=_a       )

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




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






