
"""simple docstring"""


import unittest

from diffusers import __version__
from diffusers.utils import deprecate







class 		lowerCamelCase__					(					unittest.TestCase				):





			'''simple docstring'''
			lowerCamelCase  					=		'''.'''.join([str(int(__version__.split('''.'''				)[0]				) + 1				)] + __version__.split('''.'''				)[1:]				)
			lowerCamelCase  					=		'''0.0.1'''



			def 					_lowerCAmelCase		(							self  ) ->     Optional[int]:
				_lowerCAmelCase								={"""deprecated_arg""": 4}

				with self.assertWarns(__UpperCAmelCase  ) as warning:
					_lowerCAmelCase								=deprecate("""deprecated_arg"""     ,     self.higher_version     ,     """message"""     ,     take_from=__UpperCAmelCase  )

				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 					_lowerCAmelCase		(							self  ) ->     Tuple:
				_lowerCAmelCase								={"""deprecated_arg""": 4}

				with self.assertWarns(__UpperCAmelCase  ) as warning:
					_lowerCAmelCase								=deprecate(("""deprecated_arg""", self.higher_version, """message""")     ,     take_from=__UpperCAmelCase  )

				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 					_lowerCAmelCase		(							self  ) ->     List[Any]:
				_lowerCAmelCase								={"""deprecated_arg_1""": 4, """deprecated_arg_2""": 8}
				with self.assertWarns(__UpperCAmelCase  ) as warning:
					_lowerCAmelCase						,							_lowerCAmelCase								=deprecate(
					    ("""deprecated_arg_1""", self.higher_version, """Hey""")     ,     ("""deprecated_arg_2""", self.higher_version, """Hey""")     ,     take_from=__UpperCAmelCase     ,     )
				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 					_lowerCAmelCase		(							self  ) ->     Dict:
				_lowerCAmelCase								={"""deprecated_arg""": 4}

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

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







				class 		lowerCamelCase__					:





							'''simple docstring'''
							lowerCamelCase  					=		5

				with self.assertWarns(__UpperCAmelCase  ) as warning:
					_lowerCAmelCase								=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 					_lowerCAmelCase		(							self  ) ->     Any:







				class 		lowerCamelCase__					:





							'''simple docstring'''
							lowerCamelCase  					=		5
							lowerCamelCase  					=		7

				with self.assertWarns(__UpperCAmelCase  ) as warning:
					_lowerCAmelCase						,							_lowerCAmelCase								=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 					_lowerCAmelCase		(							self  ) ->     str:
				_lowerCAmelCase								={"""deprecated_arg""": 4}

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

				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 					_lowerCAmelCase		(							self  ) ->     List[str]:
				with self.assertWarns(__UpperCAmelCase  ) as warning:
					deprecate(("""deprecated_arg""", self.higher_version, """This message is better!!!""")     ,     standard_warn=__UpperCAmelCase  )

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



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





"""simple docstring"""


import enum
import inspect
import warnings
from functools import wraps
from typing import Callable, Optional

from .logging import get_logger


__A       						=       set()
__A       						=       get_logger(__name__)



def     _lowerCamelCase(__UpperCamelCase = None       )				-> Optional[Any]:

	def decorator(__UpperCamelCase       ):
		global _emitted_deprecation_warnings

		if inspect.isclass(__UpperCamelCase       ):
			_lowerCAmelCase								=deprecated_class_or_function.__init__
			_lowerCAmelCase								=deprecated_class_or_function.__name__
		else:
			_lowerCAmelCase								=deprecated_class_or_function
			_lowerCAmelCase								=deprecated_function.__name__
			# Support deprecating __init__ class method: class name instead
			_lowerCAmelCase								=name if name != """__init__""" else deprecated_function.__qualname__.split("""."""       )[-2]

		_lowerCAmelCase								=(
		    F'''{name} is deprecated and will be removed in the next major version of datasets.''' + F''' {help_message}'''
		    if help_message
		    else """"""
		)

		@wraps(__UpperCamelCase       )
		def wrapper(*__UpperCamelCase    , **__UpperCamelCase       ):
			_lowerCAmelCase								=hash(__UpperCamelCase       )
			if func_hash not in _emitted_deprecation_warnings:
				warnings.warn(__UpperCamelCase    , category=__UpperCamelCase    , stacklevel=2       )
				_emitted_deprecation_warnings.add(__UpperCamelCase       )
			return deprecated_function(*__UpperCamelCase    , **__UpperCamelCase       )

		_lowerCAmelCase								="""deprecated"""

		if inspect.isclass(__UpperCamelCase       ):
			_lowerCAmelCase								=wrapper
			return deprecated_class_or_function
		else:
			return wrapper

	return decorator







class 		lowerCamelCase__					(					enum.EnumMeta				):





			'''simple docstring'''



			def __getattribute__(							cls     ,     __UpperCAmelCase  ) ->     Optional[int]:
				_lowerCAmelCase								=super().__getattribute__(__UpperCAmelCase  )
				if isinstance(__UpperCAmelCase     ,     enum.Enum  ) and obj._on_access:
					obj._on_access()
				return obj



			def __getitem__(							cls     ,     __UpperCAmelCase  ) ->     List[str]:
				_lowerCAmelCase								=super().__getitem__(__UpperCAmelCase  )
				if member._on_access:
					member._on_access()
				return member



			def __call__(							cls     ,     __UpperCAmelCase     ,     __UpperCAmelCase=None     ,     *, __UpperCAmelCase=None     ,     __UpperCAmelCase=None     ,     __UpperCAmelCase=None     ,     __UpperCAmelCase=1  ) ->     Optional[Any]:
				_lowerCAmelCase								=super().__call__(__UpperCAmelCase     ,     __UpperCAmelCase     ,     module=__UpperCAmelCase     ,     qualname=__UpperCAmelCase     ,     type=__UpperCAmelCase     ,     start=__UpperCAmelCase  )
				if isinstance(__UpperCAmelCase     ,     enum.Enum  ) and obj._on_access:
					obj._on_access()
				return obj







class 		lowerCamelCase__					(					enum.Enum ,	metaclass=__magic_name__				):





			'''simple docstring'''



			def __new__(							cls     ,     __UpperCAmelCase  ) ->     Optional[int]:
				_lowerCAmelCase								=object.__new__(cls  )
				_lowerCAmelCase								=value
				_lowerCAmelCase								=member.deprecate
				return member



			@property
			def 					_lowerCAmelCase		(							self  ) ->     List[Any]:
				return ""



			def 					_lowerCAmelCase		(							self  ) ->     Tuple:
				_lowerCAmelCase								=f''' {self.help_message}''' if self.help_message else """"""
				warnings.warn(
				    f'''\'{self.__objclass__.__name__}\' is deprecated and will be removed in the next major version of datasets.'''
				    + help_message     ,     __UpperCAmelCase     ,     stacklevel=3     ,     )



