





'''simple docstring'''

import unittest

from transformers.testing_utils import CaptureStdout
from transformers.tools.python_interpreter import evaluate







def 							UpperCAmelCase_    (	lowerCAmelCase_							):

				"""simple docstring"""






				return x + 2


class       UpperCAmelCase (						unittest.TestCase  ):




		def 				UpperCAmelCase__   (self      :	Tuple				)					-> Optional[int]:
						lowercase         = "x = 3"
						lowercase         = {}
						lowercase         = evaluate(A__							,			{}							,			state=A__				)
						assert result == 3
						self.assertDictEqual(A__							,			{"x": 3}				)

						lowercase         = "x = y"
						lowercase         = {"y": 5}
						lowercase         = evaluate(A__							,			{}							,			state=A__				)
						# evaluate returns the value of the last assignment.
						assert result == 5
						self.assertDictEqual(A__							,			{"x": 5, "y": 5}				)




		def 				UpperCAmelCase__   (self      :	Union[str, Any]				)					-> List[Any]:
						lowercase         = "y = add_two(x)"
						lowercase         = {"x": 3}
						lowercase         = evaluate(A__							,			{"add_two": add_two}							,			state=A__				)
						assert result == 5
						self.assertDictEqual(A__							,			{"x": 3, "y": 5}				)

						# Won't work without the tool
						with CaptureStdout() as out:
										lowercase         = evaluate(A__							,			{}							,			state=A__				)
						assert result is None
						assert "tried to execute add_two" in out.out




		def 				UpperCAmelCase__   (self      :	Tuple				)					-> Optional[int]:
						lowercase         = "x = 3"
						lowercase         = {}
						lowercase         = evaluate(A__							,			{}							,			state=A__				)
						assert result == 3
						self.assertDictEqual(A__							,			{"x": 3}				)




		def 				UpperCAmelCase__   (self      :	List[str]				)					-> Dict:
						lowercase         = "test_dict = {'x': x, 'y': add_two(x)}"
						lowercase         = {"x": 3}
						lowercase         = evaluate(A__							,			{"add_two": add_two}							,			state=A__				)
						self.assertDictEqual(A__							,			{"x": 3, "y": 5}				)
						self.assertDictEqual(A__							,			{"x": 3, "test_dict": {"x": 3, "y": 5}}				)




		def 				UpperCAmelCase__   (self      :	List[Any]				)					-> List[Any]:
						lowercase         = "x = 3\ny = 5"
						lowercase         = {}
						lowercase         = evaluate(A__							,			{}							,			state=A__				)
						# evaluate returns the value of the last assignment.
						assert result == 5
						self.assertDictEqual(A__							,			{"x": 3, "y": 5}				)




		def 				UpperCAmelCase__   (self      :	Tuple				)					-> List[str]:
						lowercase         = "text = f'This is x: {x}.'"
						lowercase         = {"x": 3}
						lowercase         = evaluate(A__							,			{}							,			state=A__				)
						# evaluate returns the value of the last assignment.
						assert result == "This is x: 3."
						self.assertDictEqual(A__							,			{"x": 3, "text": "This is x: 3."}				)




		def 				UpperCAmelCase__   (self      :	Dict				)					-> List[Any]:
						lowercase         = "if x <= 3:\n    y = 2\nelse:\n    y = 5"
						lowercase         = {"x": 3}
						lowercase         = evaluate(A__							,			{}							,			state=A__				)
						# evaluate returns the value of the last assignment.
						assert result == 2
						self.assertDictEqual(A__							,			{"x": 3, "y": 2}				)

						lowercase         = {"x": 8}
						lowercase         = evaluate(A__							,			{}							,			state=A__				)
						# evaluate returns the value of the last assignment.
						assert result == 5
						self.assertDictEqual(A__							,			{"x": 8, "y": 5}				)




		def 				UpperCAmelCase__   (self      :	Union[str, Any]				)					-> List[str]:
						lowercase         = "test_list = [x, add_two(x)]"
						lowercase         = {"x": 3}
						lowercase         = evaluate(A__							,			{"add_two": add_two}							,			state=A__				)
						self.assertListEqual(A__							,			[3, 5]				)
						self.assertDictEqual(A__							,			{"x": 3, "test_list": [3, 5]}				)




		def 				UpperCAmelCase__   (self      :	str				)					-> str:
						lowercase         = "y = x"
						lowercase         = {"x": 3}
						lowercase         = evaluate(A__							,			{}							,			state=A__				)
						assert result == 3
						self.assertDictEqual(A__							,			{"x": 3, "y": 3}				)




		def 				UpperCAmelCase__   (self      :	Tuple				)					-> Union[str, Any]:
						lowercase         = "test_list = [x, add_two(x)]\ntest_list[1]"
						lowercase         = {"x": 3}
						lowercase         = evaluate(A__							,			{"add_two": add_two}							,			state=A__				)
						assert result == 5
						self.assertDictEqual(A__							,			{"x": 3, "test_list": [3, 5]}				)

						lowercase         = "test_dict = {'x': x, 'y': add_two(x)}\ntest_dict['y']"
						lowercase         = {"x": 3}
						lowercase         = evaluate(A__							,			{"add_two": add_two}							,			state=A__				)
						assert result == 5
						self.assertDictEqual(A__							,			{"x": 3, "test_dict": {"x": 3, "y": 5}}				)





		def 				UpperCAmelCase__   (self      :	str				)					-> Dict:
						lowercase         = "x = 0\nfor i in range(3):\n    x = i"
						lowercase         = {}
						lowercase         = evaluate(A__							,			{"range": range}							,			state=A__				)
						assert result == 2
						self.assertDictEqual(A__							,			{"x": 2, "i": 2}				)











'''simple docstring'''

import warnings
from contextlib import contextmanager

from ....processing_utils import ProcessorMixin

class       UpperCAmelCase (						_lowercase  ):
		UpperCAmelCase					:	Optional[Any] 			=		'''MCTCTFeatureExtractor'''
		UpperCAmelCase					:	Tuple 			=		'''AutoTokenizer'''




		def __init__(self      :	int							,			A__      :	Tuple							,			A__      :	Union[str, Any]				)					-> Dict:
						super().__init__(A__							,			A__				)
						lowercase         = self.feature_extractor
						lowercase         = False




		def __call__(self      :	Tuple							,			*A__      :	str							,			**A__      :	Dict				)					-> int:
						# For backward compatibility
						if self._in_target_context_manager:
										return self.current_processor(*A__							,			**A__				)

						if "raw_speech" in kwargs:
										warnings.warn("Using `raw_speech` as a keyword argument is deprecated. Use `audio` instead."				)
										lowercase         = kwargs.pop("raw_speech"				)
						else:
										lowercase         = kwargs.pop("audio"							,			A__				)
						lowercase         = kwargs.pop("sampling_rate"							,			A__				)
						lowercase         = kwargs.pop("text"							,			A__				)
						if len(A__				) > 0:
										lowercase         = args[0]
										lowercase         = args[1:]

						if audio is None and text is None:
										raise ValueError("You need to specify either an `audio` or `text` input to process."				)

						if audio is not None:
										lowercase         = self.feature_extractor(A__							,			*A__							,			sampling_rate=A__							,			**A__				)
						if text is not None:
										lowercase         = self.tokenizer(A__							,			**A__				)

						if text is None:
										return inputs
						elif audio is None:
										return encodings
						else:
										lowercase         = encodings["input_ids"]
										return inputs




		def 				UpperCAmelCase__   (self      :	Tuple							,			*A__      :	str							,			**A__      :	str				)					-> str:
						return self.tokenizer.batch_decode(*A__							,			**A__				)




		def 				UpperCAmelCase__   (self      :	Any							,			*A__      :	List[Any]							,			**A__      :	List[str]				)					-> Tuple:
						# For backward compatibility
						if self._in_target_context_manager:
										return self.current_processor.pad(*A__							,			**A__				)

						lowercase         = kwargs.pop("input_features"							,			A__				)
						lowercase         = kwargs.pop("labels"							,			A__				)
						if len(A__				) > 0:
										lowercase         = args[0]
										lowercase         = args[1:]

						if input_features is not None:
										lowercase         = self.feature_extractor.pad(A__							,			*A__							,			**A__				)
						if labels is not None:
										lowercase         = self.tokenizer.pad(A__							,			**A__				)

						if labels is None:
										return input_features
						elif input_features is None:
										return labels
						else:
										lowercase         = labels["input_ids"]
										return input_features




		def 				UpperCAmelCase__   (self      :	Tuple							,			*A__      :	Optional[int]							,			**A__      :	Optional[int]				)					-> Tuple:
						return self.tokenizer.decode(*A__							,			**A__				)





		@contextmanager
		def 				UpperCAmelCase__   (self      :	Optional[Any]				)					-> Union[str, Any]:
						warnings.warn(
						    "`as_target_processor` is deprecated and will be removed in v5 of Transformers. You can process your "
						    "labels by using the argument `text` of the regular `__call__` method (either in the same call as "
						    "your audio inputs, or in a separate call."				)
						lowercase         = True
						lowercase         = self.tokenizer
						yield
						lowercase         = self.feature_extractor
						lowercase         = False




