






"""simple docstring"""
import os
import unittest

from huggingface_hub.utils import are_progress_bars_disabled

import transformers.models.bart.tokenization_bart
from transformers import logging
from transformers.testing_utils import CaptureLogger, mockenv, mockenv_context
from transformers.utils.logging import disable_progress_bar, enable_progress_bar



class      SCREAMING_SNAKE_CASE  (				unittest.TestCase						):





	"""simple docstring"""




	def    lowerCamelCase(self							):
		A_		:						Optional[Any]	    =   logging.get_logger()

		# the current default level is logging.WARNING
		A_		:						Optional[Any]	    =   logging.get_verbosity()

		logging.set_verbosity_error()
		self.assertEqual(logger.getEffectiveLevel()     ,     logging.get_verbosity()							)

		logging.set_verbosity_warning()
		self.assertEqual(logger.getEffectiveLevel()     ,     logging.get_verbosity()							)

		logging.set_verbosity_info()
		self.assertEqual(logger.getEffectiveLevel()     ,     logging.get_verbosity()							)

		logging.set_verbosity_debug()
		self.assertEqual(logger.getEffectiveLevel()     ,     logging.get_verbosity()							)

		# restore to the original level
		logging.set_verbosity(lowerCAmelCase_							)





	def    lowerCamelCase(self							):
		A_		:						List[str]	    =   logging.get_verbosity()

		A_		:						Dict	    =   logging.get_logger("""transformers.models.bart.tokenization_bart"""							)
		A_		:						Tuple	    =   """Testing 1, 2, 3"""

		# should be able to log warnings (if default settings weren't overridden by `pytest --log-level-all`)
		if level_origin <= logging.WARNING:
			with CaptureLogger(lowerCAmelCase_							) as cl:
				logger.warning(lowerCAmelCase_							)
			self.assertEqual(cl.out     ,     msg + """\n"""							)

		# this is setting the level for all of `transformers.*` loggers
		logging.set_verbosity_error()

		# should not be able to log warnings
		with CaptureLogger(lowerCAmelCase_							) as cl:
			logger.warning(lowerCAmelCase_							)
		self.assertEqual(cl.out     ,     """"""							)

		# should be able to log warnings again
		logging.set_verbosity_warning()
		with CaptureLogger(lowerCAmelCase_							) as cl:
			logger.warning(lowerCAmelCase_							)
		self.assertEqual(cl.out     ,     msg + """\n"""							)

		# restore to the original level
		logging.set_verbosity(lowerCAmelCase_							)





	@mockenv(TRANSFORMERS_VERBOSITY="""error"""							)
	def    lowerCamelCase(self							):
		# reset for the env var to take effect, next time some logger call is made
		transformers.utils.logging._reset_library_root_logger()
		# this action activates the env var
		A_		:						Optional[int]	    =   logging.get_logger("""transformers.models.bart.tokenization_bart"""							)

		A_		:						Optional[Any]	    =   os.getenv("""TRANSFORMERS_VERBOSITY"""     ,     lowerCAmelCase_							)
		A_		:						str	    =   logging.log_levels[env_level_str]

		A_		:						str	    =   logging.get_verbosity()
		self.assertEqual(
		    lowerCAmelCase_     ,     lowerCAmelCase_     ,     f"""TRANSFORMERS_VERBOSITY={env_level_str}/{env_level}, but internal verbosity is {current_level}"""     ,     )

		# restore to the original level
		A_		:						List[str]	    =   """"""
		transformers.utils.logging._reset_library_root_logger()





	@mockenv(TRANSFORMERS_VERBOSITY="""super-error"""							)
	def    lowerCamelCase(self							):
		# reset for the env var to take effect, next time some logger call is made
		transformers.utils.logging._reset_library_root_logger()
		A_		:						Tuple	    =   logging.logging.getLogger()
		with CaptureLogger(lowerCAmelCase_							) as cl:
			# this action activates the env var
			logging.get_logger("""transformers.models.bart.tokenization_bart"""							)
		self.assertIn("""Unknown option TRANSFORMERS_VERBOSITY=super-error"""     ,     cl.out							)

		# no need to restore as nothing was changed





	def    lowerCamelCase(self							):
		# testing `logger.warning_advice()`
		transformers.utils.logging._reset_library_root_logger()

		A_		:						Tuple	    =   logging.get_logger("""transformers.models.bart.tokenization_bart"""							)
		A_		:						List[Any]	    =   """Testing 1, 2, 3"""

		with mockenv_context(TRANSFORMERS_NO_ADVISORY_WARNINGS="""1"""							):
			# nothing should be logged as env var disables this method
			with CaptureLogger(lowerCAmelCase_							) as cl:
				logger.warning_advice(lowerCAmelCase_							)
			self.assertEqual(cl.out     ,     """"""							)

		with mockenv_context(TRANSFORMERS_NO_ADVISORY_WARNINGS=""""""							):
			# should log normally as TRANSFORMERS_NO_ADVISORY_WARNINGS is unset
			with CaptureLogger(lowerCAmelCase_							) as cl:
				logger.warning_advice(lowerCAmelCase_							)
			self.assertEqual(cl.out     ,     msg + """\n"""							)






def 			__UpperCamelCase	(		):
	disable_progress_bar()
	assert are_progress_bars_disabled()

	enable_progress_bar()
	assert not are_progress_bars_disabled()









"""simple docstring"""
from ...processing_utils import ProcessorMixin
from ...tokenization_utils_base import BatchEncoding



class      SCREAMING_SNAKE_CASE  (				_SCREAMING_SNAKE_CASE						):





	"""simple docstring"""




	_A       :				Optional[int]    =				["""image_processor""", """tokenizer"""]
	_A       :				str    =				"""AutoImageProcessor"""
	_A       :				Union[str, Any]    =				"""AutoTokenizer"""





	def __init__(self     ,     lowerCAmelCase_     ,     lowerCAmelCase_							):
		super().__init__(lowerCAmelCase_     ,     lowerCAmelCase_							)
		A_		:						Union[str, Any]	    =   self.image_processor





	def __call__(self     ,     lowerCAmelCase_=None     ,     lowerCAmelCase_=None     ,     lowerCAmelCase_=None     ,     **lowerCAmelCase_							):

		if text is None and images is None:
			raise ValueError("""You have to specify either text or images. Both cannot be none."""							)

		if text is not None:
			A_		:						Optional[int]	    =   self.tokenizer(lowerCAmelCase_     ,     return_tensors=lowerCAmelCase_     ,     **lowerCAmelCase_							)

		if images is not None:
			A_		:						List[Any]	    =   self.image_processor(lowerCAmelCase_     ,     return_tensors=lowerCAmelCase_     ,     **lowerCAmelCase_							)

		if text is not None and images is not None:
			A_		:						int	    =   image_features.pixel_values
			return encoding
		elif text is not None:
			return encoding
		else:
			return BatchEncoding(data=dict(**lowerCAmelCase_							)     ,     tensor_type=lowerCAmelCase_							)





	def    lowerCamelCase(self     ,     *lowerCAmelCase_     ,     **lowerCAmelCase_							):
		return self.tokenizer.batch_decode(*lowerCAmelCase_     ,     **lowerCAmelCase_							)





	def    lowerCamelCase(self     ,     *lowerCAmelCase_     ,     **lowerCAmelCase_							):
		return self.tokenizer.decode(*lowerCAmelCase_     ,     **lowerCAmelCase_							)





	@property
	def    lowerCamelCase(self							):
		return ["input_ids", "attention_mask", "pixel_values"]

