


'''simple docstring'''





import unittest

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






def 						UpperCAmelCase__(				_SCREAMING_SNAKE_CASE					: int ):






			"""simple docstring"""




			return x + 2






class 						a__					(					unittest.TestCase   ):





			'''simple docstring'''

			def 					lowerCAmelCase     (  self							:			Any	)      ->		Optional[int]:
						__A=	'x = 3'
						__A=	{}
						__A=	evaluate(lowerCAmelCase_			,    {}			,    state=lowerCAmelCase_	)
						assert result == 3
						self.assertDictEqual(lowerCAmelCase_			,    {'x': 3}	)

						__A=	'x = y'
						__A=	{'y': 5}
						__A=	evaluate(lowerCAmelCase_			,    {}			,    state=lowerCAmelCase_	)
						# evaluate returns the value of the last assignment.
						assert result == 5
						self.assertDictEqual(lowerCAmelCase_			,    {'x': 5, 'y': 5}	)
			def 					lowerCAmelCase     (  self							:			List[Any]	)      ->		Optional[int]:
						__A=	'y = add_two(x)'
						__A=	{'x': 3}
						__A=	evaluate(lowerCAmelCase_			,    {'add_two': add_two}			,    state=lowerCAmelCase_	)
						assert result == 5
						self.assertDictEqual(lowerCAmelCase_			,    {'x': 3, 'y': 5}	)

						# Won't work without the tool
						with CaptureStdout() as out:
									__A=	evaluate(lowerCAmelCase_			,    {}			,    state=lowerCAmelCase_	)
						assert result is None
						assert "tried to execute add_two" in out.out
			def 					lowerCAmelCase     (  self							:			Union[str, Any]	)      ->		Optional[int]:
						__A=	'x = 3'
						__A=	{}
						__A=	evaluate(lowerCAmelCase_			,    {}			,    state=lowerCAmelCase_	)
						assert result == 3
						self.assertDictEqual(lowerCAmelCase_			,    {'x': 3}	)
			def 					lowerCAmelCase     (  self							:			List[Any]	)      ->		Optional[Any]:
						__A=	'test_dict = {\'x\': x, \'y\': add_two(x)}'
						__A=	{'x': 3}
						__A=	evaluate(lowerCAmelCase_			,    {'add_two': add_two}			,    state=lowerCAmelCase_	)
						self.assertDictEqual(lowerCAmelCase_			,    {'x': 3, 'y': 5}	)
						self.assertDictEqual(lowerCAmelCase_			,    {'x': 3, 'test_dict': {'x': 3, 'y': 5}}	)
			def 					lowerCAmelCase     (  self							:			List[str]	)      ->		Dict:
						__A=	'x = 3\ny = 5'
						__A=	{}
						__A=	evaluate(lowerCAmelCase_			,    {}			,    state=lowerCAmelCase_	)
						# evaluate returns the value of the last assignment.
						assert result == 5
						self.assertDictEqual(lowerCAmelCase_			,    {'x': 3, 'y': 5}	)
			def 					lowerCAmelCase     (  self							:			Any	)      ->		Any:
						__A=	'text = f\'This is x: {x}.\''
						__A=	{'x': 3}
						__A=	evaluate(lowerCAmelCase_			,    {}			,    state=lowerCAmelCase_	)
						# evaluate returns the value of the last assignment.
						assert result == "This is x: 3."
						self.assertDictEqual(lowerCAmelCase_			,    {'x': 3, 'text': 'This is x: 3.'}	)
			def 					lowerCAmelCase     (  self							:			Optional[Any]	)      ->		List[Any]:
						__A=	'if x <= 3:\n    y = 2\nelse:\n    y = 5'
						__A=	{'x': 3}
						__A=	evaluate(lowerCAmelCase_			,    {}			,    state=lowerCAmelCase_	)
						# evaluate returns the value of the last assignment.
						assert result == 2
						self.assertDictEqual(lowerCAmelCase_			,    {'x': 3, 'y': 2}	)

						__A=	{'x': 8}
						__A=	evaluate(lowerCAmelCase_			,    {}			,    state=lowerCAmelCase_	)
						# evaluate returns the value of the last assignment.
						assert result == 5
						self.assertDictEqual(lowerCAmelCase_			,    {'x': 8, 'y': 5}	)
			def 					lowerCAmelCase     (  self							:			Any	)      ->		List[Any]:
						__A=	'test_list = [x, add_two(x)]'
						__A=	{'x': 3}
						__A=	evaluate(lowerCAmelCase_			,    {'add_two': add_two}			,    state=lowerCAmelCase_	)
						self.assertListEqual(lowerCAmelCase_			,    [3, 5]	)
						self.assertDictEqual(lowerCAmelCase_			,    {'x': 3, 'test_list': [3, 5]}	)
			def 					lowerCAmelCase     (  self							:			List[str]	)      ->		Optional[int]:
						__A=	'y = x'
						__A=	{'x': 3}
						__A=	evaluate(lowerCAmelCase_			,    {}			,    state=lowerCAmelCase_	)
						assert result == 3
						self.assertDictEqual(lowerCAmelCase_			,    {'x': 3, 'y': 3}	)
			def 					lowerCAmelCase     (  self							:			Tuple	)      ->		Tuple:
						__A=	'test_list = [x, add_two(x)]\ntest_list[1]'
						__A=	{'x': 3}
						__A=	evaluate(lowerCAmelCase_			,    {'add_two': add_two}			,    state=lowerCAmelCase_	)
						assert result == 5
						self.assertDictEqual(lowerCAmelCase_			,    {'x': 3, 'test_list': [3, 5]}	)

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

			def 					lowerCAmelCase     (  self							:			List[str]	)      ->		Dict:
						__A=	'x = 0\nfor i in range(3):\n    x = i'
						__A=	{}
						__A=	evaluate(lowerCAmelCase_			,    {'range': range}			,    state=lowerCAmelCase_	)
						assert result == 2
						self.assertDictEqual(lowerCAmelCase_			,    {'x': 2, 'i': 2}	)







'''simple docstring'''





from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_flax_available,
    is_tf_available,
    is_tokenizers_available,
    is_torch_available,
    is_vision_available,
)


UpperCAmelCase__  			=				{
    '''configuration_owlvit''': [
        '''OWLVIT_PRETRAINED_CONFIG_ARCHIVE_MAP''',
        '''OwlViTConfig''',
        '''OwlViTOnnxConfig''',
        '''OwlViTTextConfig''',
        '''OwlViTVisionConfig''',
    ],
    '''processing_owlvit''': ['''OwlViTProcessor'''],
}


try:
					if not is_vision_available():
										raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
					pass
else:
					UpperCAmelCase__  			=				['''OwlViTFeatureExtractor''']
					UpperCAmelCase__  			=				['''OwlViTImageProcessor''']

try:
					if not is_torch_available():
										raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
					pass
else:
					UpperCAmelCase__  			=				[
					    '''OWLVIT_PRETRAINED_MODEL_ARCHIVE_LIST''',
					    '''OwlViTModel''',
					    '''OwlViTPreTrainedModel''',
					    '''OwlViTTextModel''',
					    '''OwlViTVisionModel''',
					    '''OwlViTForObjectDetection''',
					]

if TYPE_CHECKING:
					from .configuration_owlvit import (
					    OWLVIT_PRETRAINED_CONFIG_ARCHIVE_MAP,
					    OwlViTConfig,
					    OwlViTOnnxConfig,
					    OwlViTTextConfig,
					    OwlViTVisionConfig,
					)
					from .processing_owlvit import OwlViTProcessor

					try:
										if not is_vision_available():
															raise OptionalDependencyNotAvailable()
					except OptionalDependencyNotAvailable:
										pass
					else:
										from .feature_extraction_owlvit import OwlViTFeatureExtractor
										from .image_processing_owlvit import OwlViTImageProcessor

					try:
										if not is_torch_available():
															raise OptionalDependencyNotAvailable()
					except OptionalDependencyNotAvailable:
										pass
					else:
										from .modeling_owlvit import (
										    OWLVIT_PRETRAINED_MODEL_ARCHIVE_LIST,
										    OwlViTForObjectDetection,
										    OwlViTModel,
										    OwlViTPreTrainedModel,
										    OwlViTTextModel,
										    OwlViTVisionModel,
										)

else:
					import sys

					UpperCAmelCase__  			=				_LazyModule(__name__, globals()['''__file__'''], _import_structure, module_spec=__spec__)



