def test_ignore(self): uut = IgnoreResultAction() with make_temp() as f_a: file_dict = { f_a: ['1\n', '2\n', '3\n'] } file_diff_dict = {} # Apply an initial patch uut.apply(Result.from_values('origin', 'msg', f_a, 2), file_dict, file_diff_dict, 'c') self.assertEqual( file_diff_dict[f_a].modified, ['1\n', '2 // Ignore origin\n', '3\n']) with open(f_a, 'r') as f: self.assertEqual(file_diff_dict[f_a].modified, f.readlines()) self.assertTrue(exists(f_a + '.orig')) # Apply a second patch, old patch has to stay! uut.apply(Result.from_values('else', 'msg', f_a, 1), file_dict, file_diff_dict, 'c') self.assertEqual( file_diff_dict[f_a].modified, ['1 // Ignore else\n', '2 // Ignore origin\n', '3\n']) with open(f_a, 'r') as f: self.assertEqual(file_diff_dict[f_a].modified, f.readlines())
def test_is_applicable(self): with self.assertRaises(TypeError) as context: IgnoreResultAction.is_applicable('str', {}, {}) self.assertEqual( IgnoreResultAction.is_applicable( Result.from_values('origin', 'msg', "file doesn't exist", 2), {}, {} ), "The result is associated with source code that doesn't " 'seem to exist.' ) self.assertEqual( IgnoreResultAction.is_applicable( Result('', ''), {}, {} ), 'The result is not associated with any source code.' ) with make_temp() as f_a: self.assertTrue(IgnoreResultAction.is_applicable( Result.from_values('origin', 'msg', f_a, 2), {}, {}))
def test_is_applicable(self): self.assertFalse(IgnoreResultAction.is_applicable('str', {}, {})) self.assertFalse(IgnoreResultAction.is_applicable( Result.from_values('origin', 'msg', "file doesn't exist", 2), {}, {})) with make_temp() as f_a: self.assertTrue(IgnoreResultAction.is_applicable( Result.from_values('origin', 'msg', f_a, 2), {}, {}))
def test_is_applicable(self): self.assertFalse(IgnoreResultAction.is_applicable('str', {}, {})) self.assertFalse( IgnoreResultAction.is_applicable( Result.from_values('origin', 'msg', "file doesn't exist", 2), {}, {})) with make_temp() as f_a: self.assertTrue( IgnoreResultAction.is_applicable( Result.from_values('origin', 'msg', f_a, 2), {}, {}))
def test_no_orig(self): uut = IgnoreResultAction() with make_temp() as f_a: file_dict = { f_a: ['1\n', '2\n', '3\n'] } file_diff_dict = {} # Apply an initial patch uut.apply(Result.from_values('origin', 'msg', f_a, 2), file_dict, file_diff_dict, 'c', no_orig=True) self.assertFalse(exists(f_a + '.orig'))
def test_no_orig(self): uut = IgnoreResultAction() with make_temp() as f_a: file_dict = { f_a: ['1\n', '2\n', '3\n'] } file_diff_dict = {} # Apply an initial patch uut.apply(Result.from_values('origin', 'msg', f_a, 2), file_dict, file_diff_dict, 'c', no_orig=True) self.assertFalse(exists(f_a + '.orig'))
def test_is_applicable(self): prior_ignore = ('IgnoreResultAction') associated_result = Result.from_values('origin', 'msg', "file doesn't exist", 2) with self.assertRaises(TypeError) as context: IgnoreResultAction.is_applicable('str', {}, {}) with self.assertRaises(TypeError) as context: IgnoreResultAction.is_applicable('str', {}, {}, prior_ignore) self.assertEqual( IgnoreResultAction.is_applicable(associated_result, {}, {}), "The result is associated with source code that doesn't " 'seem to exist.') self.assertEqual( IgnoreResultAction.is_applicable( associated_result, {}, {}, prior_ignore), 'An ignore comment was already added for this result.') self.assertEqual( IgnoreResultAction.is_applicable( Result('', ''), {}, {}, prior_ignore), 'An ignore comment was already added for this result.') self.assertEqual( IgnoreResultAction.is_applicable( Result('', ''), {}, {} ), 'The result is not associated with any source code.' ) with make_temp() as f_a: result = Result.from_values('origin', 'msg', f_a, 2) self.assertTrue(IgnoreResultAction.is_applicable(result, {}, {})) self.assertEqual( IgnoreResultAction.is_applicable( result, {}, {}, prior_ignore), 'An ignore comment was already added for this result.')
def test_ignore_jinja2(self): uut = IgnoreResultAction() with make_temp() as f_a: file_dict = { f_a: ['1\n', '2\n'] } file_diff_dict = {} # Test ignore comment in jinja2 uut.apply(Result.from_values('else', 'msg', f_a, 1), file_dict, file_diff_dict, 'jinja2') self.assertEqual( file_diff_dict[f_a].modified, ['1 {# Ignore else #}\n', '2\n']) with open(f_a, 'r') as f: self.assertEqual(file_diff_dict[f_a].modified, f.readlines())
def provide_all_actions(): return [DoNothingAction().get_metadata().desc, ShowPatchAction().get_metadata().desc, ApplyPatchAction().get_metadata().desc, IgnoreResultAction().get_metadata().desc, OpenEditorAction().get_metadata().desc, PrintAspectAction().get_metadata().desc, PrintDebugMessageAction().get_metadata().desc, PrintMoreInfoAction().get_metadata().desc]
def test_is_applicable(self): with self.assertRaises(TypeError) as context: IgnoreResultAction.is_applicable('str', {}, {}) self.assertEqual( IgnoreResultAction.is_applicable( Result.from_values('origin', 'msg', "file doesn't exist", 2), {}, {}), "The result is associated with source code that doesn't " 'seem to exist.') self.assertEqual( IgnoreResultAction.is_applicable(Result('', ''), {}, {}), 'The result is not associated with any source code.') with make_temp() as f_a: self.assertTrue( IgnoreResultAction.is_applicable( Result.from_values('origin', 'msg', f_a, 2), {}, {}))
def test_ignore(self): uut = IgnoreResultAction() with make_temp() as f_a: file_dict = { f_a: ['1\n', '2\n', '3\n'] } file_diff_dict = {} # Apply an initial patch uut.apply(Result.from_values('origin', 'msg', f_a, 2), file_dict, file_diff_dict, 'c') self.assertEqual( file_diff_dict[f_a].modified, ['1\n', '2 // Ignore origin\n', '3\n']) with open(f_a, 'r') as f: self.assertEqual(file_diff_dict[f_a].modified, f.readlines()) self.assertTrue(exists(f_a + '.orig')) # Apply a second patch, old patch has to stay! uut.apply(Result.from_values('else', 'msg', f_a, 1), file_dict, file_diff_dict, 'css') self.assertEqual( file_diff_dict[f_a].modified, ['1 /* Ignore else */\n', '2 // Ignore origin\n', '3\n']) with open(f_a, 'r') as f: self.assertEqual(file_diff_dict[f_a].modified, f.readlines()) import logging logger = logging.getLogger() with unittest.mock.patch('subprocess.call'): with self.assertLogs(logger, 'WARNING') as log: uut.apply(Result.from_values('else', 'msg', f_a, 1), file_dict, file_diff_dict, 'dothraki') self.assertEqual(1, len(log.output)) self.assertIn( 'coala does not support Ignore in "dothraki".', log.output[0] )
def test_ignore(self): uut = IgnoreResultAction() with make_temp() as f_a: file_dict = { f_a: ['1\n', '2\n', '3\n'] } file_diff_dict = {} # Apply an initial patch uut.apply(Result.from_values('origin', 'msg', f_a, 2), file_dict, file_diff_dict, 'c') self.assertEqual( file_diff_dict[f_a].modified, ['1\n', '2 // Ignore origin\n', '3\n']) with open(f_a, 'r') as f: self.assertEqual(file_diff_dict[f_a].modified, f.readlines()) self.assertTrue(exists(f_a + '.orig')) # Apply a second patch, old patch has to stay! uut.apply(Result.from_values('else', 'msg', f_a, 1), file_dict, file_diff_dict, 'css') self.assertEqual( file_diff_dict[f_a].modified, ['1 /* Ignore else */\n', '2 // Ignore origin\n', '3\n']) with open(f_a, 'r') as f: self.assertEqual(file_diff_dict[f_a].modified, f.readlines()) import logging logger = logging.getLogger() with unittest.mock.patch('subprocess.call'): with self.assertLogs(logger, 'WARNING') as log: uut.apply(Result.from_values('else', 'msg', f_a, 1), file_dict, file_diff_dict, 'dothraki') self.assertEqual(1, len(log.output)) self.assertIn( 'coala does not support Ignore in "dothraki".', log.output[0] )
def test_ignore(self): uut = IgnoreResultAction() with make_temp() as f_a: file_dict = {f_a: ['1\n', '2\n', '3\n']} file_diff_dict = {} # Apply an initial patch uut.apply(Result.from_values('origin', 'msg', f_a, 2), file_dict, file_diff_dict, 'c') self.assertEqual(file_diff_dict[f_a].modified, ['1\n', '2 // Ignore origin\n', '3\n']) with open(f_a, 'r') as f: self.assertEqual(file_diff_dict[f_a].modified, f.readlines()) self.assertTrue(exists(f_a + '.orig')) # Apply a second patch, old patch has to stay! uut.apply(Result.from_values('else', 'msg', f_a, 1), file_dict, file_diff_dict, 'c') self.assertEqual( file_diff_dict[f_a].modified, ['1 // Ignore else\n', '2 // Ignore origin\n', '3\n']) with open(f_a, 'r') as f: self.assertEqual(file_diff_dict[f_a].modified, f.readlines())
"that doesn't seem to exist in the given file.") STR_PROJECT_WIDE = 'Project wide:' STR_ENTER_NUMBER = ('Enter number (Ctrl-' f"{'Z' if platform.system() == 'Windows' else 'D'} " 'to exit): ') STR_INVALID_OPTION = '*** Invalid Option: ({}) ***\n' WARNING_COLOR = 'red' FILE_NAME_COLOR = 'blue' FILE_LINES_COLOR = 'blue' CAPABILITY_COLOR = 'green' HIGHLIGHTED_CODE_COLOR = 'red' SUCCESS_COLOR = 'green' REQUIRED_SETTINGS_COLOR = 'green' CLI_ACTIONS = (OpenEditorAction(), ApplyPatchAction(), PrintDebugMessageAction(), PrintMoreInfoAction(), ShowPatchAction(), IgnoreResultAction(), ShowAppliedPatchesAction(), GeneratePatchesAction()) DIFF_EXCERPT_MAX_SIZE = 4 def color_letter(console_printer, line): x = line.find('(') if x == -1: letter = '' y = x + 1 else: letter = line[x + 1] y = x + 2 warn = line.rfind('[') if warn == 0: warn = len(line)
"that doesn't seem to exist in the given file.") STR_PROJECT_WIDE = 'Project wide:' STR_ENTER_NUMBER = 'Enter number (Ctrl-{} to exit): '.format( 'Z' if platform.system() == 'Windows' else 'D') FILE_NAME_COLOR = 'blue' FILE_LINES_COLOR = 'blue' CAPABILITY_COLOR = 'green' HIGHLIGHTED_CODE_COLOR = 'red' SUCCESS_COLOR = 'green' REQUIRED_SETTINGS_COLOR = 'green' CLI_ACTIONS = (OpenEditorAction(), ApplyPatchAction(), PrintDebugMessageAction(), PrintMoreInfoAction(), ShowPatchAction(), IgnoreResultAction(), ShowAppliedPatchesAction(), GeneratePatchesAction()) DIFF_EXCERPT_MAX_SIZE = 4 def color_letter(console_printer, line): x = -1 y = -1 letter = '' for i, l in enumerate(line, 0): if line[i] == '(': x = i if line[i] == ')': y = i if l.isupper() and x != -1:
'needed by {} for section \"{}\": ') STR_LINE_DOESNT_EXIST = ('The line belonging to the following result ' 'cannot be printed because it refers to a line ' "that doesn't seem to exist in the given file.") STR_PROJECT_WIDE = 'Project wide:' STR_ENTER_NUMBER = 'Enter number (Ctrl-{} to exit): '.format( 'Z' if platform.system() == 'Windows' else 'D') FILE_NAME_COLOR = 'blue' FILE_LINES_COLOR = 'blue' CAPABILITY_COLOR = 'green' HIGHLIGHTED_CODE_COLOR = 'red' SUCCESS_COLOR = 'green' REQUIRED_SETTINGS_COLOR = 'green' CLI_ACTIONS = (OpenEditorAction(), ApplyPatchAction(), PrintDebugMessageAction(), PrintMoreInfoAction(), ShowPatchAction(), IgnoreResultAction(), ChainPatchAction()) DIFF_EXCERPT_MAX_SIZE = 4 def format_lines(lines, symbol='', line_nr=''): def sym(x): return ']' if x is '[' else x return '\n'.join('{}{:>5}{} {}'.format(symbol, sym(symbol), line_nr, line) for line in lines.rstrip('\n').split('\n')) def print_section_beginning(console_printer, section): """ Will be called after initialization current_section in begin_section()