def test_apply(self): uut = ShowAppliedPatchesAction() with make_temp() as f_a, make_temp() as f_b, make_temp() as f_c: file_dict = { f_a: ['1\n', '2\n', '3\n'], f_b: ['1\n', '2\n', '3\n'], f_c: ['1\n', '2\n', '3\n'] } expected_file_dict = { f_a: ['1\n', '3_changed\n'], f_b: ['1\n', '2\n', '3_changed\n'], f_c: ['1\n', '2\n', '3\n'] } with make_temp() as testfile_path: file_diff_dict = {} file_dict = {testfile_path: ['1\n', '2\n', '3\n']} diff = Diff(file_dict[testfile_path]) diff.delete_line(2) diff.change_line(3, '3\n', '3_changed\n') result = Result('origin', 'msg', diffs={f_a: diff}, applied_actions={'ApplyPatchAction': [Result( 'origin', 'message', diffs={testfile_path: diff}), file_dict, file_diff_dict, Section('')]}) self.assertTrue(uut.apply(result, file_dict, file_diff_dict))
def test_apply(self): uut = ShowAppliedPatchesAction() with make_temp() as f_a, make_temp() as f_b, make_temp() as f_c: file_dict = { f_a: ['1\n', '2\n', '3\n'], f_b: ['1\n', '2\n', '3\n'], f_c: ['1\n', '2\n', '3\n'] } expected_file_dict = { f_a: ['1\n', '3_changed\n'], f_b: ['1\n', '2\n', '3_changed\n'], f_c: ['1\n', '2\n', '3\n'] } with make_temp() as testfile_path: file_diff_dict = {} file_dict = {testfile_path: ['1\n', '2\n', '3\n']} diff = Diff(file_dict[testfile_path]) diff.delete_line(2) diff.change_line(3, '3\n', '3_changed\n') result = Result('origin', 'msg', diffs={f_a: diff}, applied_actions={ 'ApplyPatchAction': [ Result('origin', 'message', diffs={testfile_path: diff}), file_dict, file_diff_dict, Section('') ] }) self.assertTrue(uut.apply(result, file_dict, file_diff_dict))
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) first_part = line[:x + 1]
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: letter = l