New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gsoc: Numbers to letters #4390

Merged
merged 2 commits into from Jun 26, 2017
Jump to file or symbol
Failed to load files and symbols.
+40 −31
Diff settings

Always

Just for now

Viewing a subset of changes. View all
Prev

Change the input: Numbers to letters

  • Loading branch information...
Nosferatul committed Jun 22, 2017
commit 8a25983187966a60a810756c200ece1d9bb59607
@@ -559,23 +559,26 @@ def choose_action(console_printer, actions):
:return: Return choice of action of user.
"""
while True:
console_printer.print(format_lines('{}'.format('*0: Do nothing'),
console_printer.print(format_lines('Do (N)othing',
symbol='['))
for i, action in enumerate(actions, 1):
console_printer.print(format_lines('{:>2}: {}'.format(
i, action.desc), symbol='['))
try:
line = format_lines(STR_ENTER_NUMBER, symbol='[')
choice = input(line)
if not choice:
console_printer.print(format_lines('{}'.format(
action.desc), symbol='['))
line = format_lines(STR_ENTER_NUMBER, symbol='[')
choice = input(line)
if not choice:
return 0
choice = str(choice)
if choice.isalpha():
choice = choice.upper()
choice = '(' + choice + ')'
if choice == '(N)':
return 0
choice = int(choice)
if 0 <= choice <= len(actions):
return choice
except ValueError:
pass
for i, action in enumerate(actions, 1):
if choice in action.desc:
return i
console_printer.print(format_lines(
'Please enter a valid letter.', symbol='['))
@@ -103,7 +103,7 @@ def test_caching_results(self):
"""
with bear_test_module(), \
prepare_file(['a=(5,6)'], None) as (lines, filename):
with simulate_console_inputs('0'):
with simulate_console_inputs('n'):
retval, stdout, stderr = execute_coala(
coala.main,
'coala',
@@ -153,7 +153,7 @@ def test_caching_multi_results(self):
"""
filename = 'tests/misc/test_caching_multi_results/'
with bear_test_module():
with simulate_console_inputs('0'):
with simulate_console_inputs('n'):
retval, stdout, stderr = execute_coala(
coala.main,
'coala',
@@ -45,7 +45,9 @@
class TestAction(ResultAction):
def apply(self, result, original_file_dict, file_diff_dict, param):
pass
"""
Test (A)ction
"""
class TestBear(Bear):
@@ -173,27 +175,27 @@ def test_require_settings(self):
self.assertRaises(TypeError, acquire_settings,
self.log_printer, 0, curr_section)
with simulate_console_inputs(0, 1, 2) as generator:
with simulate_console_inputs('n', 'a', 'o') as generator:
self.assertEqual(acquire_settings(self.log_printer,
{'setting': ['help text',
'SomeBear']},
curr_section),
{'setting': 0})
{'setting': 'n'})
self.assertEqual(acquire_settings(self.log_printer,
{'setting': ['help text',
'SomeBear',
'AnotherBear']},
curr_section),
{'setting': 1})
{'setting': 'a'})
self.assertEqual(acquire_settings(self.log_printer,
{'setting': ['help text',
'SomeBear',
'AnotherBear',
'YetAnotherBear']},
curr_section),
{'setting': 2})
{'setting': 'o'})
self.assertEqual(generator.last_input, 2)
@@ -260,7 +262,7 @@ def test_print_result(self):
'illegal value',
{})
with simulate_console_inputs(0):
with simulate_console_inputs('n'):
print_result(self.console_printer,
self.section,
self.file_diff_dict,
@@ -283,9 +285,9 @@ def test_print_result(self):
# param
with simulate_console_inputs('INVALID',
-1,
1,
0,
3) as input_generator:
'a',
'n',
'm') as input_generator:
curr_section = Section('')
print_section_beginning(self.console_printer, curr_section)
print_result(self.console_printer,
@@ -307,12 +309,16 @@ def test_print_result(self):
TestAction().get_metadata(),
failed_actions=set())
self.assertEqual(input_generator.last_input, 4)
self.assertEqual(str(section), " {param : '3'}")
self.assertEqual(str(section), " {param : 'm'}")
self.assertEqual(name, 'TestAction')
# Check if the user is asked for the parameter only the first time.
# Use OpenEditorAction that needs this parameter (editor command).
with simulate_console_inputs(1, 'test_editor', 0, 1, 0) as generator:
with simulate_console_inputs('o',
'test_editor',
'n',
'o',
'n') as generator:
OpenEditorAction.is_applicable = staticmethod(lambda *args: True)
patch_result = Result('origin', 'msg', diffs={testfile_path: diff})
@@ -353,7 +359,7 @@ def test_acquire_actions_and_apply(self):
diff = Diff(file_dict[testfile_path])
diff.delete_line(2)
diff.change_line(3, '3\n', '3_changed\n')
with simulate_console_inputs(1, 0) as generator, \
with simulate_console_inputs('a', 'n') as generator, \
retrieve_stdout() as sio:
ApplyPatchAction.is_applicable = staticmethod(
lambda *args: True)
@@ -378,7 +384,7 @@ def apply(*args, **kwargs):
ApplyPatchAction.is_applicable = staticmethod(lambda *args: True)
cli_actions = [ApplyPatchAction(), InvalidateTestAction()]
with simulate_console_inputs(2, 1, 0) as generator, \
with simulate_console_inputs('a', 'o', 'n') as generator, \
retrieve_stdout() as sio:
acquire_actions_and_apply(self.console_printer,
Section(''),
@@ -393,7 +399,7 @@ def apply(*args, **kwargs):
self.assertNotIn(action_fail, sio.getvalue())
apply_path_desc = ApplyPatchAction().get_metadata().desc
self.assertEqual(sio.getvalue().count(apply_path_desc), 1)
self.assertEqual(sio.getvalue().count(apply_path_desc), 3)
ApplyPatchAction.is_applicable = old_applypatch_is_applicable
@@ -404,7 +410,7 @@ def test_ask_for_actions_and_apply(self):
[action.get_metadata()], {'TestAction': action},
failed_actions, Result('origin', 'message'), {}, {}]
with simulate_console_inputs(1, 'param1', 1, 'param2') as generator:
with simulate_console_inputs('a', 'param1', 'a', 'param2') as generator:
action.apply = unittest.mock.Mock(side_effect=AssertionError)
ask_for_action_and_apply(*args)
self.assertEqual(generator.last_input, 1)
ProTip! Use n and p to navigate between commits in a pull request.