



"""simple docstring"""







import unittest

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



def 	__UpperCAmelCase (       __lowerCamelCase      )				-> Tuple:
		return x + 2





class 			__A			(      unittest.TestCase       ):







		'''simple docstring'''





		def    UpperCAmelCase       (      self		:    Optional[int]		)   ->						int:






				"""simple docstring"""



				lowercase__  :       List[str]												=     "x = 3"
				lowercase__  :       List[str]												=     {}
				lowercase__  :       Tuple												=     evaluate(snake_case__     ,{}     ,state=snake_case__		)
				assert result == 3
				self.assertDictEqual(snake_case__     ,{'''x''': 3}		)

				lowercase__  :       Any												=     "x = y"
				lowercase__  :       List[str]												=     {"y": 5}
				lowercase__  :       Dict												=     evaluate(snake_case__     ,{}     ,state=snake_case__		)
				# evaluate returns the value of the last assignment.
				assert result == 5
				self.assertDictEqual(snake_case__     ,{'''x''': 5, '''y''': 5}		)







		def    UpperCAmelCase       (      self		:    Union[str, Any]		)   ->						Union[str, Any]:






				"""simple docstring"""



				lowercase__  :       int												=     "y = add_two(x)"
				lowercase__  :       Tuple												=     {"x": 3}
				lowercase__  :       Union[str, Any]												=     evaluate(snake_case__     ,{'''add_two''': add_two}     ,state=snake_case__		)
				assert result == 5
				self.assertDictEqual(snake_case__     ,{'''x''': 3, '''y''': 5}		)

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







		def    UpperCAmelCase       (      self		:    List[str]		)   ->						List[Any]:






				"""simple docstring"""



				lowercase__  :       Tuple												=     "x = 3"
				lowercase__  :       List[Any]												=     {}
				lowercase__  :       Tuple												=     evaluate(snake_case__     ,{}     ,state=snake_case__		)
				assert result == 3
				self.assertDictEqual(snake_case__     ,{'''x''': 3}		)







		def    UpperCAmelCase       (      self		:    Dict		)   ->						str:






				"""simple docstring"""



				lowercase__  :       int												=     "test_dict = {'x': x, 'y': add_two(x)}"
				lowercase__  :       List[Any]												=     {"x": 3}
				lowercase__  :       int												=     evaluate(snake_case__     ,{'''add_two''': add_two}     ,state=snake_case__		)
				self.assertDictEqual(snake_case__     ,{'''x''': 3, '''y''': 5}		)
				self.assertDictEqual(snake_case__     ,{'''x''': 3, '''test_dict''': {'''x''': 3, '''y''': 5}}		)







		def    UpperCAmelCase       (      self		:    List[str]		)   ->						List[Any]:






				"""simple docstring"""



				lowercase__  :       int												=     "x = 3\ny = 5"
				lowercase__  :       Dict												=     {}
				lowercase__  :       Union[str, Any]												=     evaluate(snake_case__     ,{}     ,state=snake_case__		)
				# evaluate returns the value of the last assignment.
				assert result == 5
				self.assertDictEqual(snake_case__     ,{'''x''': 3, '''y''': 5}		)







		def    UpperCAmelCase       (      self		:    Union[str, Any]		)   ->						Tuple:






				"""simple docstring"""



				lowercase__  :       Dict												=     "text = f'This is x: {x}.'"
				lowercase__  :       Dict												=     {"x": 3}
				lowercase__  :       Dict												=     evaluate(snake_case__     ,{}     ,state=snake_case__		)
				# evaluate returns the value of the last assignment.
				assert result == "This is x: 3."
				self.assertDictEqual(snake_case__     ,{'''x''': 3, '''text''': '''This is x: 3.'''}		)







		def    UpperCAmelCase       (      self		:    List[Any]		)   ->						Union[str, Any]:






				"""simple docstring"""



				lowercase__  :       List[str]												=     "if x <= 3:\n    y = 2\nelse:\n    y = 5"
				lowercase__  :       Dict												=     {"x": 3}
				lowercase__  :       Dict												=     evaluate(snake_case__     ,{}     ,state=snake_case__		)
				# evaluate returns the value of the last assignment.
				assert result == 2
				self.assertDictEqual(snake_case__     ,{'''x''': 3, '''y''': 2}		)

				lowercase__  :       Optional[Any]												=     {"x": 8}
				lowercase__  :       str												=     evaluate(snake_case__     ,{}     ,state=snake_case__		)
				# evaluate returns the value of the last assignment.
				assert result == 5
				self.assertDictEqual(snake_case__     ,{'''x''': 8, '''y''': 5}		)







		def    UpperCAmelCase       (      self		:    str		)   ->						int:






				"""simple docstring"""



				lowercase__  :       Optional[int]												=     "test_list = [x, add_two(x)]"
				lowercase__  :       Any												=     {"x": 3}
				lowercase__  :       Any												=     evaluate(snake_case__     ,{'''add_two''': add_two}     ,state=snake_case__		)
				self.assertListEqual(snake_case__     ,[3, 5]		)
				self.assertDictEqual(snake_case__     ,{'''x''': 3, '''test_list''': [3, 5]}		)







		def    UpperCAmelCase       (      self		:    str		)   ->						Optional[Any]:






				"""simple docstring"""



				lowercase__  :       str												=     "y = x"
				lowercase__  :       str												=     {"x": 3}
				lowercase__  :       Any												=     evaluate(snake_case__     ,{}     ,state=snake_case__		)
				assert result == 3
				self.assertDictEqual(snake_case__     ,{'''x''': 3, '''y''': 3}		)







		def    UpperCAmelCase       (      self		:    int		)   ->						Optional[int]:






				"""simple docstring"""



				lowercase__  :       Optional[int]												=     "test_list = [x, add_two(x)]\ntest_list[1]"
				lowercase__  :       List[Any]												=     {"x": 3}
				lowercase__  :       List[Any]												=     evaluate(snake_case__     ,{'''add_two''': add_two}     ,state=snake_case__		)
				assert result == 5
				self.assertDictEqual(snake_case__     ,{'''x''': 3, '''test_list''': [3, 5]}		)

				lowercase__  :       Union[str, Any]												=     "test_dict = {'x': x, 'y': add_two(x)}\ntest_dict['y']"
				lowercase__  :       str												=     {"x": 3}
				lowercase__  :       Any												=     evaluate(snake_case__     ,{'''add_two''': add_two}     ,state=snake_case__		)
				assert result == 5
				self.assertDictEqual(snake_case__     ,{'''x''': 3, '''test_dict''': {'''x''': 3, '''y''': 5}}		)







		def    UpperCAmelCase       (      self		:    Union[str, Any]		)   ->						List[str]:






				"""simple docstring"""



				lowercase__  :       List[Any]												=     "x = 0\nfor i in range(3):\n    x = i"
				lowercase__  :       List[Any]												=     {}
				lowercase__  :       Any												=     evaluate(snake_case__     ,{'''range''': range}     ,state=snake_case__		)
				assert result == 2
				self.assertDictEqual(snake_case__     ,{'''x''': 2, '''i''': 2}		)


'''simple docstring'''





import unittest

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







def snake_case_     (					lowercase__		):
  return x + 2






class 							UpperCAmelCase_							(    unittest.TestCase				):

 '''simple docstring'''







 def 							UpperCamelCase  (					self		:  Optional[int] ):



   '''simple docstring'''




   UpperCAmelCase__      :					List[str]				       =							"x = 3"
   UpperCAmelCase__      :					List[str]				       =							{}
   UpperCAmelCase__      :					Tuple				       =							evaluate(snake_case__			,				{}			,				state=snake_case__ )
   assert result == 3
   self.assertDictEqual(snake_case__			,				{"x": 3} )

   UpperCAmelCase__      :					Any				       =							"x = y"
   UpperCAmelCase__      :					List[str]				       =							{"y": 5}
   UpperCAmelCase__      :					Dict				       =							evaluate(snake_case__			,				{}			,				state=snake_case__ )
   # evaluate returns the value of the last assignment.
   assert result == 5
   self.assertDictEqual(snake_case__			,				{"x": 5, "y": 5} )







 def 							UpperCamelCase  (					self		:  Union[str, Any] ):



   '''simple docstring'''




   UpperCAmelCase__      :					int				       =							"y = add_two(x)"
   UpperCAmelCase__      :					Tuple				       =							{"x": 3}
   UpperCAmelCase__      :					Union[str, Any]				       =							evaluate(snake_case__			,				{"add_two": add_two}			,				state=snake_case__ )
   assert result == 5
   self.assertDictEqual(snake_case__			,				{"x": 3, "y": 5} )

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







 def 							UpperCamelCase  (					self		:  List[str] ):



   '''simple docstring'''




   UpperCAmelCase__      :					Tuple				       =							"x = 3"
   UpperCAmelCase__      :					List[Any]				       =							{}
   UpperCAmelCase__      :					Tuple				       =							evaluate(snake_case__			,				{}			,				state=snake_case__ )
   assert result == 3
   self.assertDictEqual(snake_case__			,				{"x": 3} )







 def 							UpperCamelCase  (					self		:  Dict ):



   '''simple docstring'''




   UpperCAmelCase__      :					int				       =							"test_dict = {'x': x, 'y': add_two(x)}"
   UpperCAmelCase__      :					List[Any]				       =							{"x": 3}
   UpperCAmelCase__      :					int				       =							evaluate(snake_case__			,				{"add_two": add_two}			,				state=snake_case__ )
   self.assertDictEqual(snake_case__			,				{"x": 3, "y": 5} )
   self.assertDictEqual(snake_case__			,				{"x": 3, "test_dict": {"x": 3, "y": 5}} )







 def 							UpperCamelCase  (					self		:  List[str] ):



   '''simple docstring'''




   UpperCAmelCase__      :					int				       =							"x = 3\ny = 5"
   UpperCAmelCase__      :					Dict				       =							{}
   UpperCAmelCase__      :					Union[str, Any]				       =							evaluate(snake_case__			,				{}			,				state=snake_case__ )
   # evaluate returns the value of the last assignment.
   assert result == 5
   self.assertDictEqual(snake_case__			,				{"x": 3, "y": 5} )







 def 							UpperCamelCase  (					self		:  Union[str, Any] ):



   '''simple docstring'''




   UpperCAmelCase__      :					Dict				       =							"text = f'This is x: {x}.'"
   UpperCAmelCase__      :					Dict				       =							{"x": 3}
   UpperCAmelCase__      :					Dict				       =							evaluate(snake_case__			,				{}			,				state=snake_case__ )
   # evaluate returns the value of the last assignment.
   assert result == "This is x: 3."
   self.assertDictEqual(snake_case__			,				{"x": 3, "text": "This is x: 3."} )







 def 							UpperCamelCase  (					self		:  List[Any] ):



   '''simple docstring'''




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

   UpperCAmelCase__      :					Optional[Any]				       =							{"x": 8}
   UpperCAmelCase__      :					str				       =							evaluate(snake_case__			,				{}			,				state=snake_case__ )
   # evaluate returns the value of the last assignment.
   assert result == 5
   self.assertDictEqual(snake_case__			,				{"x": 8, "y": 5} )







 def 							UpperCamelCase  (					self		:  str ):



   '''simple docstring'''




   UpperCAmelCase__      :					Optional[int]				       =							"test_list = [x, add_two(x)]"
   UpperCAmelCase__      :					Any				       =							{"x": 3}
   UpperCAmelCase__      :					Any				       =							evaluate(snake_case__			,				{"add_two": add_two}			,				state=snake_case__ )
   self.assertListEqual(snake_case__			,				[3, 5] )
   self.assertDictEqual(snake_case__			,				{"x": 3, "test_list": [3, 5]} )







 def 							UpperCamelCase  (					self		:  str ):



   '''simple docstring'''




   UpperCAmelCase__      :					str				       =							"y = x"
   UpperCAmelCase__      :					str				       =							{"x": 3}
   UpperCAmelCase__      :					Any				       =							evaluate(snake_case__			,				{}			,				state=snake_case__ )
   assert result == 3
   self.assertDictEqual(snake_case__			,				{"x": 3, "y": 3} )







 def 							UpperCamelCase  (					self		:  int ):



   '''simple docstring'''




   UpperCAmelCase__      :					Optional[int]				       =							"test_list = [x, add_two(x)]\ntest_list[1]"
   UpperCAmelCase__      :					List[Any]				       =							{"x": 3}
   UpperCAmelCase__      :					List[Any]				       =							evaluate(snake_case__			,				{"add_two": add_two}			,				state=snake_case__ )
   assert result == 5
   self.assertDictEqual(snake_case__			,				{"x": 3, "test_list": [3, 5]} )

   UpperCAmelCase__      :					Union[str, Any]				       =							"test_dict = {'x': x, 'y': add_two(x)}\ntest_dict['y']"
   UpperCAmelCase__      :					str				       =							{"x": 3}
   UpperCAmelCase__      :					Any				       =							evaluate(snake_case__			,				{"add_two": add_two}			,				state=snake_case__ )
   assert result == 5
   self.assertDictEqual(snake_case__			,				{"x": 3, "test_dict": {"x": 3, "y": 5}} )







 def 							UpperCamelCase  (					self		:  Union[str, Any] ):



   '''simple docstring'''




   UpperCAmelCase__      :					List[Any]				       =							"x = 0\nfor i in range(3):\n    x = i"
   UpperCAmelCase__      :					List[Any]				       =							{}
   UpperCAmelCase__      :					Any				       =							evaluate(snake_case__			,				{"range": range}			,				state=snake_case__ )
   assert result == 2
   self.assertDictEqual(snake_case__			,				{"x": 2, "i": 2} )



