


import unittest

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







def        SCREAMING_SNAKE_CASE_						(			__A :			Tuple				)	->		List[str]:

       """simple docstring"""

       return x + 2
class  SCREAMING_SNAKE_CASE__  (				unittest.TestCase			):
      def        SCREAMING_SNAKE_CASE							(       self				:       Tuple     )		->			Dict:
             a_					:		Union[str, Any]							=  'x = 3'
             a_					:		str							=  {}
             a_					:		Optional[int]							=  evaluate(SCREAMING_SNAKE_CASE__     ,							{}     ,							state=SCREAMING_SNAKE_CASE__     )
             assert result == 3
             self.assertDictEqual(SCREAMING_SNAKE_CASE__     ,							{'x': 3}     )

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

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

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

             a_					:		str							=  'test_dict = {\'x\': x, \'y\': add_two(x)}\ntest_dict[\'y\']'
             a_					:		List[str]							=  {'x': 3}
             a_					:		Optional[int]							=  evaluate(SCREAMING_SNAKE_CASE__     ,							{'add_two': add_two}     ,							state=SCREAMING_SNAKE_CASE__     )
             assert result == 5
             self.assertDictEqual(SCREAMING_SNAKE_CASE__     ,							{'x': 3, 'test_dict': {'x': 3, 'y': 5}}     )

      def        SCREAMING_SNAKE_CASE							(       self				:       Union[str, Any]     )		->			Union[str, Any]:
             a_					:		int							=  'x = 0\nfor i in range(3):\n    x = i'
             a_					:		Optional[int]							=  {}
             a_					:		List[str]							=  evaluate(SCREAMING_SNAKE_CASE__     ,							{'range': range}     ,							state=SCREAMING_SNAKE_CASE__     )
             assert result == 2
             self.assertDictEqual(SCREAMING_SNAKE_CASE__     ,							{'x': 2, 'i': 2}     )



import builtins
import sys

from ...utils.imports import _is_package_available
from . import cursor, input
from .helpers import Direction, clear_line, forceWrite, linebreak, move_cursor, reset_cursor, writeColor
from .keymap import KEYMAP


a_    					=       False
try:
   a_    					=       _is_package_available('google.colab')
except ModuleNotFoundError:
   pass





@input.register
class 		_lowercase						:

 def __init__( self	:							Dict   ,      snake_case	:							str = None   ,      snake_case	:							list = []			)   ->						Union[str, Any]:

  """simple docstring"""





  UpperCamelCase_					:						Any =					0
  UpperCamelCase_					:						Optional[Any] =					choices
  UpperCamelCase_					:						Any =					prompt
  if sys.platform == "win32":
   UpperCamelCase_					:						Optional[Any] =					'*'
  else:
   UpperCamelCase_					:						str =					'➔ '

 def 						SCREAMING_SNAKE_CASE__   ( self	:							Optional[int]   ,      snake_case	:							List[str]   ,      snake_case	:							str = ""			)   ->						List[Any]:

  """simple docstring"""





  if sys.platform != "win32":
   writeColor(self.choices[index]   ,      3_2   ,      snake_case			)
  else:
   forceWrite(self.choices[index]   ,      snake_case			)

 def 						SCREAMING_SNAKE_CASE__   ( self	:							List[str]   ,      snake_case	:							int			)   ->						List[Any]:

  """simple docstring"""





  if index == self.position:
   forceWrite(f" {self.arrow_char} "			)
   self.write_choice(snake_case			)
  else:
   forceWrite(f"    {self.choices[index]}"			)
  reset_cursor()

 def 						SCREAMING_SNAKE_CASE__   ( self	:							Any   ,      snake_case	:							Direction   ,      snake_case	:							int = 1			)   ->						List[str]:

  """simple docstring"""





  UpperCamelCase_					:						Any =					self.position
  if direction == Direction.DOWN:
   if self.position + 1 >= len(self.choices			):
    return
   self.position += num_spaces
  else:
   if self.position - 1 < 0:
    return
   self.position -= num_spaces
  clear_line()
  self.print_choice(snake_case			)
  move_cursor(snake_case   ,      direction.name			)
  self.print_choice(self.position			)

 @input.mark(KEYMAP['up']			)
 def 						SCREAMING_SNAKE_CASE__   ( self	:							Optional[int]			)   ->						List[Any]:

  """simple docstring"""





  self.move_direction(Direction.UP			)

 @input.mark(KEYMAP['down']			)
 def 						SCREAMING_SNAKE_CASE__   ( self	:							Optional[int]			)   ->						Optional[Any]:

  """simple docstring"""





  self.move_direction(Direction.DOWN			)

 @input.mark(KEYMAP['newline']			)
 def 						SCREAMING_SNAKE_CASE__   ( self	:							str			)   ->						Optional[int]:

  """simple docstring"""





  move_cursor(len(self.choices			) - self.position   ,      'DOWN'			)
  return self.position

 @input.mark(KEYMAP['interrupt']			)
 def 						SCREAMING_SNAKE_CASE__   ( self	:							Optional[Any]			)   ->						Optional[Any]:

  """simple docstring"""





  move_cursor(len(self.choices			) - self.position   ,      'DOWN'			)
  raise KeyboardInterrupt

 @input.mark_multiple(*[KEYMAP[str(snake_case			)] for number in range(1_0			)]			)
 def 						SCREAMING_SNAKE_CASE__   ( self	:							int			)   ->						Dict:

  """simple docstring"""





  UpperCamelCase_					:						List[Any] =					int(chr(self.current_selection			)			)
  UpperCamelCase_					:						Optional[int] =					index - self.position
  if index == self.position:
   return
  if index < len(self.choices			):
   if self.position > index:
    self.move_direction(Direction.UP   ,      -movement			)
   elif self.position < index:
    self.move_direction(Direction.DOWN   ,      snake_case			)
   else:
    return
  else:
   return


 def 						SCREAMING_SNAKE_CASE__   ( self	:							List[Any]   ,      snake_case	:							int = 0			)   ->						Union[str, Any]:

  """simple docstring"""





  if self.prompt:
   linebreak()
   forceWrite(self.prompt   ,      '\n'			)
   if in_colab:
    forceWrite('Please input a choice index (starting from 0), and press enter'   ,      '\n'			)
   else:
    forceWrite('Please select a choice using the arrow or number keys, and selecting with enter'   ,      '\n'			)
  UpperCamelCase_					:						Optional[int] =					default_choice
  for i in range(len(self.choices			)			):
   self.print_choice(snake_case			)
   forceWrite('\n'			)
  move_cursor(len(self.choices			) - self.position   ,      'UP'			)
  with cursor.hide():
   while True:
    if in_colab:
     try:
      UpperCamelCase_					:						Tuple =					int(builtins.input()			)
     except ValueError:
      UpperCamelCase_					:						Tuple =					default_choice
    else:
     UpperCamelCase_					:						Optional[Any] =					self.handle_input()
    if choice is not None:
     reset_cursor()
     for _ in range(len(self.choices			) + 1			):
      move_cursor(1   ,      'UP'			)
      clear_line()
     self.write_choice(snake_case   ,      '\n'			)
     return choice



