

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


_UpperCAmelCase		:       List[str]						    =	False
try:
					_UpperCAmelCase		:       List[str]						    =	_is_package_available("""google.colab""")
except ModuleNotFoundError:
					pass







@input.register
class 			lowercase    :




				def __init__( self				,       snake_case = None				,       snake_case = []	):
											snake_case_          =   0
											snake_case_          =   choices
											snake_case_          =   prompt
											if sys.platform == "win32":
																		snake_case_          =   '*'
											else:
																		snake_case_          =   '➔ '




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




				def    a							( self				,       snake_case	):
											if index == self.position:
																		forceWrite(F''' {self.arrow_char} '''	)
																		self.write_choice(snake_case	)
											else:
																		forceWrite(F'''    {self.choices[index]}'''	)
											reset_cursor()




				def    a							( self				,       snake_case				,       snake_case = 1	):
											snake_case_          =   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    a							( self	):
											self.move_direction(Direction.UP	)




				@input.mark(KEYMAP['down']	)
				def    a							( self	):
											self.move_direction(Direction.DOWN	)




				@input.mark(KEYMAP['newline']	)
				def    a							( self	):
											move_cursor(len(self.choices	) - self.position				,       'DOWN'	)
											return self.position




				@input.mark(KEYMAP['interrupt']	)
				def    a							( self	):
											move_cursor(len(self.choices	) - self.position				,       'DOWN'	)
											raise KeyboardInterrupt




				@input.mark_multiple(*[KEYMAP[str(snake_case	)] for number in range(10	)]	)
				def    a							( self	):
											snake_case_          =   int(chr(self.current_selection	)	)
											snake_case_          =   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    a							( self				,       snake_case = 0	):
											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'	)
											snake_case_          =   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:
																																							snake_case_          =   int(builtins.input()	)
																																except ValueError:
																																							snake_case_          =   default_choice
																									else:
																																snake_case_          =   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







import os
import sys
import unittest


_UpperCAmelCase		:       str						    =	os.path.abspath(os.path.dirname(os.path.dirname(os.path.dirname(__file__))))
sys.path.append(os.path.join(git_repo_path, """utils"""))

import get_test_info  # noqa: E402
from get_test_info import (  # noqa: E402
    get_model_to_test_mapping,
    get_model_to_tester_mapping,
    get_test_to_tester_mapping,
)


_UpperCAmelCase		:       List[Any]						    =	os.path.join("""tests""", """models""", """bert""", """test_modeling_bert.py""")
_UpperCAmelCase		:       Dict						    =	os.path.join("""tests""", """models""", """blip""", """test_modeling_blip.py""")







class 			lowercase    (	unittest.TestCase      ):




				def    a							( self	):
											snake_case_          =   get_test_to_tester_mapping(snake_case	)
											snake_case_          =   get_test_to_tester_mapping(snake_case	)

											snake_case_          =   {'BertModelTest': 'BertModelTester'}

											snake_case_          =   {
											    'BlipModelTest': 'BlipModelTester',
											    'BlipTextImageModelTest': 'BlipTextImageModelsModelTester',
											    'BlipTextModelTest': 'BlipTextModelTester',
											    'BlipTextRetrievalModelTest': 'BlipTextRetrievalModelTester',
											    'BlipVQAModelTest': 'BlipVQAModelTester',
											    'BlipVisionModelTest': 'BlipVisionModelTester',
											}

											self.assertEqual(get_test_info.to_json(snake_case	)				,       snake_case	)
											self.assertEqual(get_test_info.to_json(snake_case	)				,       snake_case	)




				def    a							( self	):
											snake_case_          =   get_model_to_test_mapping(snake_case	)
											snake_case_          =   get_model_to_test_mapping(snake_case	)

											snake_case_          =   {
											    'BertForMaskedLM': ['BertModelTest'],
											    'BertForMultipleChoice': ['BertModelTest'],
											    'BertForNextSentencePrediction': ['BertModelTest'],
											    'BertForPreTraining': ['BertModelTest'],
											    'BertForQuestionAnswering': ['BertModelTest'],
											    'BertForSequenceClassification': ['BertModelTest'],
											    'BertForTokenClassification': ['BertModelTest'],
											    'BertLMHeadModel': ['BertModelTest'],
											    'BertModel': ['BertModelTest'],
											}

											snake_case_          =   {
											    'BlipForConditionalGeneration': ['BlipTextImageModelTest'],
											    'BlipForImageTextRetrieval': ['BlipTextRetrievalModelTest'],
											    'BlipForQuestionAnswering': ['BlipVQAModelTest'],
											    'BlipModel': ['BlipModelTest'],
											    'BlipTextModel': ['BlipTextModelTest'],
											    'BlipVisionModel': ['BlipVisionModelTest'],
											}

											self.assertEqual(get_test_info.to_json(snake_case	)				,       snake_case	)
											self.assertEqual(get_test_info.to_json(snake_case	)				,       snake_case	)




				def    a							( self	):
											snake_case_          =   get_model_to_tester_mapping(snake_case	)
											snake_case_          =   get_model_to_tester_mapping(snake_case	)

											snake_case_          =   {
											    'BertForMaskedLM': ['BertModelTester'],
											    'BertForMultipleChoice': ['BertModelTester'],
											    'BertForNextSentencePrediction': ['BertModelTester'],
											    'BertForPreTraining': ['BertModelTester'],
											    'BertForQuestionAnswering': ['BertModelTester'],
											    'BertForSequenceClassification': ['BertModelTester'],
											    'BertForTokenClassification': ['BertModelTester'],
											    'BertLMHeadModel': ['BertModelTester'],
											    'BertModel': ['BertModelTester'],
											}

											snake_case_          =   {
											    'BlipForConditionalGeneration': ['BlipTextImageModelsModelTester'],
											    'BlipForImageTextRetrieval': ['BlipTextRetrievalModelTester'],
											    'BlipForQuestionAnswering': ['BlipVQAModelTester'],
											    'BlipModel': ['BlipModelTester'],
											    'BlipTextModel': ['BlipTextModelTester'],
											    'BlipVisionModel': ['BlipVisionModelTester'],
											}

											self.assertEqual(get_test_info.to_json(snake_case	)				,       snake_case	)
											self.assertEqual(get_test_info.to_json(snake_case	)				,       snake_case	)




