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: Add Do (N)othing Action #4629

Merged
merged 1 commit into from Aug 14, 2017
Jump to file or symbol
Failed to load files and symbols.
+78 −16
Diff settings

Always

Just for now

Add Do (N)othing Action

Closes #4628
  • Loading branch information...
Nosferatul committed Aug 8, 2017
commit a6c376f054da150e2d29a90997a03ddd3ec7dba0
View
@@ -11,6 +11,7 @@
from coalib.output.Logging import CounterHandler
from coalib.processes.Processing import execute_section, simplify_section_result
from coalib.settings.ConfigurationGathering import gather_configuration
from coalib.results.result_actions.DoNothingAction import DoNothingAction
from coalib.results.result_actions.ShowPatchAction import ShowPatchAction
from coalib.results.result_actions.ApplyPatchAction import ApplyPatchAction
from coalib.results.result_actions.IgnoreResultAction import IgnoreResultAction
@@ -34,7 +35,8 @@ def do_nothing(*args):
def provide_all_actions():
return ['Do (N)othing', ShowPatchAction().get_metadata().desc,
return [DoNothingAction().get_metadata().desc,
ShowPatchAction().get_metadata().desc,
ApplyPatchAction().get_metadata().desc,
IgnoreResultAction().get_metadata().desc,
OpenEditorAction().get_metadata().desc,
@@ -17,6 +17,7 @@
from coalib.results.result_actions.ApplyPatchAction import ApplyPatchAction
from coalib.results.result_actions.OpenEditorAction import OpenEditorAction
from coalib.results.result_actions.IgnoreResultAction import IgnoreResultAction
from coalib.results.result_actions.DoNothingAction import DoNothingAction
from coalib.results.result_actions.ChainPatchAction import ChainPatchAction
from coalib.results.result_actions.ShowAppliedPatchesAction import (
ShowAppliedPatchesAction)
@@ -628,18 +629,17 @@ def choose_action(console_printer, actions, apply_single=False):
If it's not selected, has a value of False.
:return: Return choice of action of user.
"""
actions.insert(0, DoNothingAction().get_metadata())
if apply_single:
if apply_single == 'Do (N)othing':
return 0
for i, action in enumerate(actions, 1):
for i, action in enumerate(actions, 0):
if apply_single == action.desc:
return i
return 0
else:
while True:
color_letter(console_printer, '[ ] *0. Do (N)othing')
for i, action in enumerate(actions, 1):
color_letter(console_printer, format_lines('{:>2}. {}'.format(
for i, action in enumerate(actions, 0):
output = '{:>2}. {}' if i != 0 else '*{}. {}'
color_letter(console_printer, format_lines(output.format(
i, action.desc), symbol='['))
line = format_lines(STR_ENTER_NUMBER, symbol='[')
@@ -651,9 +651,7 @@ def choose_action(console_printer, actions, apply_single=False):
if choice.isalpha():
choice = choice.upper()
choice = '(' + choice + ')'
if choice == '(N)':
return 0
for i, action in enumerate(actions, 1):
for i, action in enumerate(actions, 0):
if choice in action.desc:
return i
elif choice.isnumeric():
@@ -688,7 +686,7 @@ def print_actions(console_printer, section, actions, failed_actions,
if choice == 0:
return None, None
return get_action_info(section, actions[choice - 1], failed_actions)
return get_action_info(section, actions[choice], failed_actions)

This comment has been minimized.

@Adrianzatreanu

Adrianzatreanu Aug 9, 2017

Contributor

why did this change?

@Adrianzatreanu

Adrianzatreanu Aug 9, 2017

Contributor

why did this change?

This comment has been minimized.

@Nosferatul

Nosferatul Aug 9, 2017

Member

because, actions list didn't had an action for Do (N)othing. When the user choose an action, Do (N)othing will be always on index 0 in the actions list

@Nosferatul

Nosferatul Aug 9, 2017

Member

because, actions list didn't had an action for Do (N)othing. When the user choose an action, Do (N)othing will be always on index 0 in the actions list

def try_to_apply_action(action_name,
@@ -13,6 +13,7 @@
from coalib.processes.CONTROL_ELEMENT import CONTROL_ELEMENT
from coalib.processes.LogPrinterThread import LogPrinterThread
from coalib.results.Result import Result
from coalib.results.result_actions.DoNothingAction import DoNothingAction
from coalib.results.result_actions.ApplyPatchAction import ApplyPatchAction
from coalib.results.result_actions.IgnoreResultAction import IgnoreResultAction
from coalib.results.result_actions.ChainPatchAction import ChainPatchAction
@@ -27,7 +28,8 @@
from coalib.parsing.Globbing import fnmatch
ACTIONS = [ApplyPatchAction,
ACTIONS = [DoNothingAction,
ApplyPatchAction,
PrintDebugMessageAction,
ShowPatchAction,
IgnoreResultAction,
@@ -0,0 +1,16 @@
from coalib.results.result_actions.ResultAction import ResultAction
class DoNothingAction(ResultAction):
SUCCESS_MESSAGE = ''
is_applicable = staticmethod(lambda *args: True)
def apply(self,
result,
original_file_dict,
file_diff_dict):
"""
Do (N)othing

This comment has been minimized.

@Adrianzatreanu

Adrianzatreanu Aug 14, 2017

Contributor

shouldnt you document the params :D ?

@Adrianzatreanu

Adrianzatreanu Aug 14, 2017

Contributor

shouldnt you document the params :D ?

This comment has been minimized.

@Nosferatul

Nosferatul Aug 14, 2017

Member

the parent class ResultAction has it

:param original_file_dict: A dictionary containing the files in the

@Nosferatul

Nosferatul Aug 14, 2017

Member

the parent class ResultAction has it

:param original_file_dict: A dictionary containing the files in the

This comment has been minimized.

@Nosferatul

Nosferatul Aug 14, 2017

Member

and in the other actions the documentation for those params doesn't exist.

@Nosferatul

Nosferatul Aug 14, 2017

Member

and in the other actions the documentation for those params doesn't exist.

"""
@@ -26,6 +26,7 @@
from coalib.results.result_actions.ApplyPatchAction import ApplyPatchAction
from coalib.results.result_actions.OpenEditorAction import OpenEditorAction
from coalib.results.result_actions.ChainPatchAction import ChainPatchAction
from coalib.results.result_actions.DoNothingAction import DoNothingAction
from coalib.results.result_actions.ShowAppliedPatchesAction \
import ShowAppliedPatchesAction
from coalib.results.result_actions.ResultAction import ResultAction
@@ -460,8 +461,10 @@ def apply(*args, **kwargs):
def test_ask_for_actions_and_apply(self):
failed_actions = set()
action = TestAction()
do_nothing_action = DoNothingAction()
args = [self.console_printer, Section(''),
[action.get_metadata()], {'TestAction': action},
[do_nothing_action.get_metadata(), action.get_metadata()],
{'DoNothingAction': do_nothing_action, 'TestAction': action},
failed_actions, Result('origin', 'message'), {}, {}, {}]
with simulate_console_inputs('a', 'param1', 'a', 'param2') as generator:
@@ -557,17 +560,21 @@ def test_default_input(self):
def test_default_input2(self):
action = TestAction()
do_nothing_action = DoNothingAction()
args = [self.console_printer, Section(''),
[action.get_metadata()], {'TestAction': action},
[do_nothing_action.get_metadata(), action.get_metadata()],
{'DoNothingAction': do_nothing_action, 'TestAction': action},
set(), Result('origin', 'message'), {}, {}, {}]
with simulate_console_inputs(1, 1) as generator:
self.assertTrue(ask_for_action_and_apply(*args))
def test_default_input3(self):
action = TestAction()
do_nothing_action = DoNothingAction()
args = [self.console_printer, Section(''),
[action.get_metadata()], {'TestAction': action},
[do_nothing_action.get_metadata(), action.get_metadata()],
{'DoNothingAction': do_nothing_action, 'TestAction': action},
set(), Result('origin', 'message'), {}, {}, {}]
with simulate_console_inputs(1, 'a') as generator:
@@ -601,10 +608,12 @@ def test_default_input_apply_single_nothing(self):
def test_default_input_apply_single_test(self):
action = TestAction()
do_nothing_action = DoNothingAction()
apply_single = 'Test (A)ction'
se = Section('cli')
args = [self.console_printer, se,
[action.get_metadata()], {'TestAction': action},
[do_nothing_action.get_metadata(), action.get_metadata()],
{'DoNothingAction': do_nothing_action, 'TestAction': action},
set(), Result('origin', 'message'), {}, {}, {}, apply_single]
with simulate_console_inputs('a') as generator:
@@ -0,0 +1,35 @@
import unittest
from coala_utils.ContextManagers import retrieve_stdout
from coalib.results.Diff import Diff
from coalib.results.Result import Result
from coalib.results.result_actions.DoNothingAction import DoNothingAction
from coalib.settings.Section import Section, Setting
class ShowPatchActionTest(unittest.TestCase):
def setUp(self):
self.uut = DoNothingAction()
self.file_dict = {'a': ['a\n', 'b\n', 'c\n'], 'b': ['old_first\n']}
self.diff_dict = {'a': Diff(self.file_dict['a']),
'b': Diff(self.file_dict['b'])}
self.diff_dict['a'].add_lines(1, ['test\n'])
self.diff_dict['a'].delete_line(3)
self.diff_dict['b'].add_lines(0, ['first\n'])
self.test_result = Result('origin', 'message', diffs=self.diff_dict)
self.section = Section('name')
self.section.append(Setting('colored', 'false'))
def test_is_applicable(self):
diff = Diff([], rename='new_name')
result = Result('', '', diffs={'f': diff})
self.assertTrue(self.uut.is_applicable(result, {}, {'f': diff}))
def test_apply(self):
with retrieve_stdout() as stdout:
self.assertEqual(self.uut.apply(self.test_result,
self.file_dict,
{}), None)
ProTip! Use n and p to navigate between commits in a pull request.