





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 collections import deque

from .hash_table import HashTable
class 			UpperCamelCase_		(  _lowerCamelCase					):




					def __init__(		self				,						*lowerCAmelCase_				,						**lowerCAmelCase_  )		->							Any:
										super().__init__(*lowerCAmelCase_				,						**lowerCAmelCase_  )




					def 	lowerCAmelCase			(		self				,						lowerCAmelCase_				,						lowerCAmelCase_  )		->							Optional[int]:
										_snake_case									=				deque([]  ) if self.values[key] is None else self.values[key]
										self.values[key].appendleft(lowerCAmelCase_  )
										_snake_case									=				self.values[key]




					def 	lowerCAmelCase			(		self  )		->							Optional[int]:
										return (
										    sum(self.charge_factor - len(lowerCAmelCase_  ) for slot in self.values  )
										    / self.size_table
										    * self.charge_factor
										)






					def 	lowerCAmelCase			(		self				,						lowerCAmelCase_				,						lowerCAmelCase_=None  )		->							str:
										if not (
										    len(self.values[key]  ) == self.charge_factor and self.values.count(lowerCAmelCase_  ) == 0
										):
															return key
										return super()._collision_resolution(lowerCAmelCase_				,						lowerCAmelCase_  )



