def test_list_of_str(self): input_str = 'foo, bar blat, gizmo\n' with redirect_stdin(StringIO(input_str)): list_input = GetInput() result = get_list(elem_get_input=list_input) assert (result == ['foo', 'bar blat', 'gizmo'])
def test_get_list(self): input_str = u""" foo, bar, blat """ with redirect_stdin(StringIO(input_str)): result = get_list() print(result) assert (result == ['foo', 'bar', 'blat'])
def test_list_of_yes_no(self): input_str = 'y| yes| n| nyet' yn_get_input = GetInput(convertor=YesNoConvertor()) with redirect_stdin(StringIO(input_str)): result = get_list(prompt='List of yes/no (separated by "|")', elem_get_input=yn_get_input, delimiter='|') assert (result == ['yes', 'yes', 'no', 'no'])
def test_list_of_int(self): input_str = '1,2,3\n' with redirect_stdin(StringIO(input_str)): get_int_list = GetInput(convertor=IntConvertor()) result = get_list( prompt= 'List of integers between 3 and 5 numbers long, separated by ","', elem_get_input=get_int_list) assert (result == [1, 2, 3])
def change_roles(row, action_dict): # an action item to get a new list of roles for the user role_validator = ChoiceValidator(['admin', 'editor', 'user']) prompt_str = 'Enter roles for user {} {}'.format(action_dict['first'], action_dict['last']) result = get_list(prompt=prompt_str, default=action_dict['roles'], elem_validators=role_validator) action_dict['roles'] = set(result) return result
def test_list_of_choices(self): input_str = 'r g b\nr g bl brown' colors = ['red', 'green', 'blue', 'brown'] color_cleaner = ChoiceCleaner(colors) color_validator = ChoiceValidator(colors) color_input = GetInput(cleaners=color_cleaner, validators=color_validator) with redirect_stdin(StringIO(input_str)): result = get_list(elem_get_input=color_input, delimiter=' ') assert (result == ['red', 'green', 'blue', 'brown'])
def test_list_of_three_ints(self): input_str = '1,2\n-1,4,6\n2,4,11\n2, 4, 10' not_1_3_5_validator = NoneOfValidator([1, 3, 5]) zero_to_ten_validator = RangeValidator(0, 10) complex_in_input = GetInput( convertor=IntConvertor(), validators=[zero_to_ten_validator, not_1_3_5_validator]) with redirect_stdin(StringIO(input_str)): result = get_list(elem_get_input=complex_in_input) assert (result == [2, 4, 10])
def test_list_of_three_ints(self): input_str = '1,2\n1,4,6,7,9' with redirect_stdin(StringIO(input_str)): get_int_list = GetInput(convertor=IntConvertor()) len_3_validator = RangeValidator(min_val=3, max_val=5) result = get_list( prompt='List of 3-5 integers (separated by ",")', elem_get_input=get_int_list, validators=len_3_validator, value_error_str='list of values', ) assert (result == [1, 4, 6, 7, 9])