





import unittest

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





def 						lowerCamelCase__     (     UpperCamelCase__			:       Dict						)			-> Optional[Any]:



					'''simple docstring'''




					return x + 2




class 			UpperCamelCase_		(  unittest.TestCase					):




					def 	lowerCAmelCase			(		self  )		->							List[str]:
										_snake_case									=				'x = 3'
										_snake_case									=				{}
										_snake_case									=				evaluate(lowerCAmelCase_				,						{}				,						state=lowerCAmelCase_  )
										assert result == 3
										self.assertDictEqual(lowerCAmelCase_				,						{'x': 3}  )

										_snake_case									=				'x = y'
										_snake_case									=				{'y': 5}
										_snake_case									=				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  )		->							Any:
										_snake_case									=				'y = add_two(x)'
										_snake_case									=				{'x': 3}
										_snake_case									=				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:
															_snake_case									=				evaluate(lowerCAmelCase_				,						{}				,						state=lowerCAmelCase_  )
										assert result is None
										assert "tried to execute add_two" in out.out




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




					def 	lowerCAmelCase			(		self  )		->							Optional[int]:
										_snake_case									=				'test_dict = {\'x\': x, \'y\': add_two(x)}'
										_snake_case									=				{'x': 3}
										_snake_case									=				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  )		->							Optional[Any]:
										_snake_case									=				'x = 3\ny = 5'
										_snake_case									=				{}
										_snake_case									=				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  )		->							Optional[Any]:
										_snake_case									=				'text = f\'This is x: {x}.\''
										_snake_case									=				{'x': 3}
										_snake_case									=				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  )		->							List[Any]:
										_snake_case									=				'if x <= 3:\n    y = 2\nelse:\n    y = 5'
										_snake_case									=				{'x': 3}
										_snake_case									=				evaluate(lowerCAmelCase_				,						{}				,						state=lowerCAmelCase_  )
										# evaluate returns the value of the last assignment.
										assert result == 2
										self.assertDictEqual(lowerCAmelCase_				,						{'x': 3, 'y': 2}  )

										_snake_case									=				{'x': 8}
										_snake_case									=				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:
										_snake_case									=				'test_list = [x, add_two(x)]'
										_snake_case									=				{'x': 3}
										_snake_case									=				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  )		->							int:
										_snake_case									=				'y = x'
										_snake_case									=				{'x': 3}
										_snake_case									=				evaluate(lowerCAmelCase_				,						{}				,						state=lowerCAmelCase_  )
										assert result == 3
										self.assertDictEqual(lowerCAmelCase_				,						{'x': 3, 'y': 3}  )




					def 	lowerCAmelCase			(		self  )		->							Tuple:
										_snake_case									=				'test_list = [x, add_two(x)]\ntest_list[1]'
										_snake_case									=				{'x': 3}
										_snake_case									=				evaluate(lowerCAmelCase_				,						{'add_two': add_two}				,						state=lowerCAmelCase_  )
										assert result == 5
										self.assertDictEqual(lowerCAmelCase_				,						{'x': 3, 'test_list': [3, 5]}  )

										_snake_case									=				'test_dict = {\'x\': x, \'y\': add_two(x)}\ntest_dict[\'y\']'
										_snake_case									=				{'x': 3}
										_snake_case									=				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  )		->							Tuple:
										_snake_case									=				'x = 0\nfor i in range(3):\n    x = i'
										_snake_case									=				{}
										_snake_case									=				evaluate(lowerCAmelCase_				,						{'range': range}				,						state=lowerCAmelCase_  )
										assert result == 2
										self.assertDictEqual(lowerCAmelCase_				,						{'x': 2, 'i': 2}  )










from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available


UpperCAmelCase_      							=     {
    """configuration_luke""": ["""LUKE_PRETRAINED_CONFIG_ARCHIVE_MAP""", """LukeConfig"""],
    """tokenization_luke""": ["""LukeTokenizer"""],
}

try:
					if not is_torch_available():
										raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
					pass
else:
					UpperCAmelCase_      							=     [
					    """LUKE_PRETRAINED_MODEL_ARCHIVE_LIST""",
					    """LukeForEntityClassification""",
					    """LukeForEntityPairClassification""",
					    """LukeForEntitySpanClassification""",
					    """LukeForMultipleChoice""",
					    """LukeForQuestionAnswering""",
					    """LukeForSequenceClassification""",
					    """LukeForTokenClassification""",
					    """LukeForMaskedLM""",
					    """LukeModel""",
					    """LukePreTrainedModel""",
					]


if TYPE_CHECKING:
					from .configuration_luke import LUKE_PRETRAINED_CONFIG_ARCHIVE_MAP, LukeConfig
					from .tokenization_luke import LukeTokenizer

					try:
										if not is_torch_available():
															raise OptionalDependencyNotAvailable()
					except OptionalDependencyNotAvailable:
										pass
					else:
										from .modeling_luke import (
										    LUKE_PRETRAINED_MODEL_ARCHIVE_LIST,
										    LukeForEntityClassification,
										    LukeForEntityPairClassification,
										    LukeForEntitySpanClassification,
										    LukeForMaskedLM,
										    LukeForMultipleChoice,
										    LukeForQuestionAnswering,
										    LukeForSequenceClassification,
										    LukeForTokenClassification,
										    LukeModel,
										    LukePreTrainedModel,
										)

else:
					import sys

					UpperCAmelCase_      							=     _LazyModule(__name__, globals()["""__file__"""], _import_structure, module_spec=__spec__)



