
"""simple docstring"""






import unittest

from transformers import is_torch_available
from transformers.testing_utils import require_torch


if is_torch_available():
				import torch

				from transformers.generation import DisjunctiveConstraint




@require_torch
class 			_SCREAMING_SNAKE_CASE					(			unittest.TestCase							):






			def  __lowerCAmelCase (					self       )			->     List[str]:
						# For consistency across different places the DisjunctiveConstraint is called,
						# dc.token_ids is a list of integers. It is also initialized only by integers.

						lowerCAmelCase_    :str			     =  [[1, 2, 4], [1, 2, 3, 4]]
						lowerCAmelCase_    :str			     =  DisjunctiveConstraint(__A       )
						self.assertTrue(isinstance(dc.token_ids       ,   __A       )       )

						with self.assertRaises(__A       ):
									DisjunctiveConstraint(torch.LongTensor([[1, 2, 4], [1, 2, 3]]       )       )

						with self.assertRaises(__A       ):
									DisjunctiveConstraint([torch.LongTensor([1, 2, 4]       ), torch.LongTensor([1, 2, 3, 4, 5]       )]       )






			def  __lowerCAmelCase (					self       )			->     int:
						# We can't have constraints that are complete subsets of another. This leads to a preverse
						# interpretation of "constraint fulfillment": does generating [1,2,3] fulfill the constraint?
						# It would mean that it generated [1,2] which fulfills it, but it's in the middle of potentially
						# fulfilling [1,2,3,4]. If we believe that [1,2,3] does fulfill the constraint, then the algorithm
						# will necessarily never reach [1,2,3,4], giving users a false sense of control (better to just not allow it).
						lowerCAmelCase_    :Dict			     =  [[1, 2], [1, 2, 3, 4]]

						with self.assertRaises(__A       ):
									DisjunctiveConstraint(__A       )  # fails here






			def  __lowerCAmelCase (					self       )			->     Dict:
						lowerCAmelCase_    :Optional[Any]			     =  [[1, 2, 3], [1, 2, 4]]

						lowerCAmelCase_    :Union[str, Any]			     =  DisjunctiveConstraint(__A       )

						lowerCAmelCase_     ,       lowerCAmelCase_     ,       lowerCAmelCase_    :str			     =  dc.update(1       )
						lowerCAmelCase_    :List[str]			     =  stepped is True and completed is False and reset is False
						self.assertTrue(__A       )
						self.assertTrue(not dc.completed       )
						self.assertTrue(dc.current_seq == [1]       )

						lowerCAmelCase_     ,       lowerCAmelCase_     ,       lowerCAmelCase_    :Dict			     =  dc.update(2       )
						lowerCAmelCase_    :int			     =  stepped is True and completed is False and reset is False
						self.assertTrue(__A       )
						self.assertTrue(not dc.completed       )
						self.assertTrue(dc.current_seq == [1, 2]       )

						lowerCAmelCase_     ,       lowerCAmelCase_     ,       lowerCAmelCase_    :Union[str, Any]			     =  dc.update(3       )
						lowerCAmelCase_    :List[str]			     =  stepped is True and completed is True and reset is False
						self.assertTrue(__A       )
						self.assertTrue(dc.completed       )  # Completed!
						self.assertTrue(dc.current_seq == [1, 2, 3]       )






			def  __lowerCAmelCase (					self       )			->     str:
						lowerCAmelCase_    :Any			     =  [[1, 2, 3], [1, 2, 4, 5], [1, 2, 5]]

						lowerCAmelCase_    :str			     =  DisjunctiveConstraint(__A       )

						lowerCAmelCase_     ,       lowerCAmelCase_     ,       lowerCAmelCase_    :Optional[int]			     =  dc.update(1       )
						self.assertTrue(not dc.completed       )
						self.assertTrue(dc.current_seq == [1]       )

						lowerCAmelCase_     ,       lowerCAmelCase_     ,       lowerCAmelCase_    :Optional[Any]			     =  dc.update(2       )
						self.assertTrue(not dc.completed       )
						self.assertTrue(dc.current_seq == [1, 2]       )

						lowerCAmelCase_     ,       lowerCAmelCase_     ,       lowerCAmelCase_    :Any			     =  dc.update(4       )
						self.assertTrue(not dc.completed       )
						self.assertTrue(dc.current_seq == [1, 2, 4]       )

						lowerCAmelCase_     ,       lowerCAmelCase_     ,       lowerCAmelCase_    :str			     =  dc.update(5       )
						self.assertTrue(dc.completed       )  # Completed!
						self.assertTrue(dc.current_seq == [1, 2, 4, 5]       )

						dc.reset()

						lowerCAmelCase_     ,       lowerCAmelCase_     ,       lowerCAmelCase_    :List[str]			     =  dc.update(1       )
						self.assertTrue(not dc.completed       )
						self.assertTrue(dc.remaining() == 3       )
						self.assertTrue(dc.current_seq == [1]       )

						lowerCAmelCase_     ,       lowerCAmelCase_     ,       lowerCAmelCase_    :Any			     =  dc.update(2       )
						self.assertTrue(not dc.completed       )
						self.assertTrue(dc.remaining() == 2       )
						self.assertTrue(dc.current_seq == [1, 2]       )

						lowerCAmelCase_     ,       lowerCAmelCase_     ,       lowerCAmelCase_    :Dict			     =  dc.update(5       )
						self.assertTrue(dc.completed       )  # Completed!
						self.assertTrue(dc.remaining() == 0       )
						self.assertTrue(dc.current_seq == [1, 2, 5]       )








import logging
import os
from logging import (
    CRITICAL,  # NOQA
    DEBUG,  # NOQA
    ERROR,  # NOQA
    FATAL,  # NOQA
    INFO,  # NOQA
    NOTSET,  # NOQA
    WARN,  # NOQA
    WARNING,  # NOQA
)
from typing import Optional

from tqdm import auto as tqdm_lib


lowercase__       ={
    'debug': logging.DEBUG,
    'info': logging.INFO,
    'warning': logging.WARNING,
    'error': logging.ERROR,
    'critical': logging.CRITICAL,
}

lowercase__       =logging.WARNING




def    __UpperCamelCase     (				):
 __a :  Optional[Any]						=  os.getenv('''DATASETS_VERBOSITY'''  ,   lowerCAmelCase__  )
 if env_level_str:
  if env_level_str in log_levels:
   return log_levels[env_level_str]
  else:
   logging.getLogger().warning(
       f"Unknown option DATASETS_VERBOSITY={env_level_str}, "
       f"has to be one of: { ', '.join(log_levels.keys()  ) }"  )
 return _default_log_level




def    __UpperCamelCase     (				):
 return __name__.split('''.'''  )[0]




def    __UpperCamelCase     (				):
 return logging.getLogger(_get_library_name()  )




def    __UpperCamelCase     (				):
 # Apply our default configuration to the library root logger.
 __a :  str						=  _get_library_root_logger()
 library_root_logger.setLevel(_get_default_logging_level()  )




def    __UpperCamelCase     (				):
 __a :  Any						=  _get_library_root_logger()
 library_root_logger.setLevel(logging.NOTSET  )




def    __UpperCamelCase     (				lowerCAmelCase__							:				Optional[str] = None  ):
 if name is None:
  __a :  Union[str, Any]						=  _get_library_name()
 return logging.getLogger(lowerCAmelCase__  )




def    __UpperCamelCase     (				):
 return _get_library_root_logger().getEffectiveLevel()




def    __UpperCamelCase     (				lowerCAmelCase__							:				int  ):
 _get_library_root_logger().setLevel(lowerCAmelCase__  )




def    __UpperCamelCase     (				):
 return set_verbosity(lowerCAmelCase__  )




def    __UpperCamelCase     (				):
 return set_verbosity(lowerCAmelCase__  )




def    __UpperCamelCase     (				):
 return set_verbosity(lowerCAmelCase__  )




def    __UpperCamelCase     (				):
 return set_verbosity(lowerCAmelCase__  )




def    __UpperCamelCase     (				):
 __a :  Union[str, Any]						=  False




def    __UpperCamelCase     (				):
 __a :  Tuple						=  True


# Configure the library root logger at the module level (singleton-like)
_configure_library_root_logger()



class 		UpperCamelCase__  :
   def __init__(self :					str					,				*snake_case_ :					str					,				**snake_case_ :					Union[str, Any]   ):  # pylint: disable=unused-argument
    __a :  Optional[Any]						=  args[0] if args else None
   def __iter__(self :					List[str]   ):
    return iter(self._iterator   )
   def __getattr__(self :					str					,				snake_case_ :					Optional[Any]   ):

    def empty_fn(*snake_case_ :					int					,				**snake_case_ :					int   ):  # pylint: disable=unused-argument
     return

    return empty_fn
   def __enter__(self :					Union[str, Any]   ):
    return self







   def __exit__(self :					str					,				snake_case_ :					List[str]					,				snake_case_ :					int					,				snake_case_ :					Optional[Any]   ):
    return





lowercase__       =True



class 		UpperCamelCase__  :
   def __call__(self :					Tuple					,				*snake_case_ :					str					,				snake_case_ :					str=False					,				**snake_case_ :					Dict   ):
    if _tqdm_active and not disable:
     return tqdm_lib.tqdm(*snake_case_					,				**snake_case_   )
    else:
     return EmptyTqdm(*snake_case_					,				**snake_case_   )
   def       lowerCAmelCase			(self :					Optional[Any]					,				*snake_case_ :					Union[str, Any]					,				**snake_case_ :					Optional[Any]   ):
    __a :  List[Any]						=  None
    if _tqdm_active:
     return tqdm_lib.tqdm.set_lock(*snake_case_					,				**snake_case_   )







   def       lowerCAmelCase			(self :					str   ):
    if _tqdm_active:
     return tqdm_lib.tqdm.get_lock()





lowercase__       =_tqdm_cls()




def    __UpperCamelCase     (				):
 global _tqdm_active
 return bool(_tqdm_active  )




def    __UpperCamelCase     (				):
 global _tqdm_active
 __a :  Dict						=  True




def    __UpperCamelCase     (				):
 global _tqdm_active
 __a :  Union[str, Any]						=  False
