class GeneratePatchesActionTest(unittest.TestCase): def setUp(self): self.uut = GeneratePatchesAction() self.file_dict = {'a.py': ['a\n', 'b\n', 'c\n'], 'b': ['old_first\n']} self.diff_dict = { 'a.py': Diff(self.file_dict['a.py']), 'b': Diff(self.file_dict['b']) } self.diff_dict['a.py'].add_lines(1, ['test\n']) self.diff_dict['a.py'].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('no_color', 'True')) 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 prepare_file(['fixme '], None) as (lines, filename): dir_path = os.path.dirname(filename) file_path = os.path.basename(filename) newfilename = os.path.join(dir_path, file_path + '.py') os.rename(filename, newfilename) file_dict = {newfilename: ['fixme ']} diff_dict = {newfilename: Diff(file_dict[newfilename])} diff_dict[newfilename].add_line(1, ['test\n']) test_result = Result('origin', 'message', diffs=diff_dict) section = Section('name') section.append(Setting('no_color', 'True')) with simulate_console_inputs('1', 'True', '0') as generator: with retrieve_stdout() as stdout: self.uut.apply_from_section(test_result, file_dict, {}, section) self.assertIn( '[ ] *0. Do Nothing\n' '[ ] 1. Apply patch ' '(\'SpaceConsistencyBear\')\n' '[ ]', stdout.getvalue()) os.rename(newfilename, filename) def test_apply_no_input(self): with retrieve_stdout() as stdout: with simulate_console_inputs('', '0') as generator: self.assertEqual( self.uut.apply_from_section(self.test_result, self.file_dict, {}, self.section), False)
class GeneratePatchesActionTest(unittest.TestCase): def setUp(self): self.uut = GeneratePatchesAction() self.file_dict = {'a.py': ['a\n', 'b\n', 'c\n'], 'b': ['old_first\n']} self.diff_dict = {'a.py': Diff(self.file_dict['a.py']), 'b': Diff(self.file_dict['b'])} self.diff_dict['a.py'].add_lines(1, ['test\n']) self.diff_dict['a.py'].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('no_color', 'True')) 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 prepare_file(['fixme '], None) as (lines, filename): dir_path = os.path.dirname(filename) file_path = os.path.basename(filename) newfilename = os.path.join(dir_path, file_path + '.py') os.rename(filename, newfilename) file_dict = {newfilename: ['fixme ']} diff_dict = {newfilename: Diff(file_dict[newfilename])} diff_dict[newfilename].add_line(1, ['test\n']) test_result = Result('origin', 'message', diffs=diff_dict) section = Section('name') section.append(Setting('no_color', 'True')) with simulate_console_inputs('1', 'True', '0') as generator: with retrieve_stdout() as stdout: self.uut.apply_from_section(test_result, file_dict, {}, section) self.assertIn('[ ] *0. Do Nothing\n' '[ ] 1. Apply patch ' '(\'SpaceConsistencyBear\')\n' '[ ]', stdout.getvalue()) os.rename(newfilename, filename) def test_apply_no_input(self): with retrieve_stdout() as stdout: with simulate_console_inputs('', '0') as generator: self.assertEqual(self.uut.apply_from_section(self.test_result, self.file_dict, {}, self.section), False)
def setUp(self): self.uut = GeneratePatchesAction() self.file_dict = {'a.py': ['a\n', 'b\n', 'c\n'], 'b': ['old_first\n']} self.diff_dict = { 'a.py': Diff(self.file_dict['a.py']), 'b': Diff(self.file_dict['b']) } self.diff_dict['a.py'].add_lines(1, ['test\n']) self.diff_dict['a.py'].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('no_color', 'True'))
def setUp(self): self.uut = GeneratePatchesAction() self.file_dict = {'a.py': ['a\n', 'b\n', 'c\n'], 'b': ['old_first\n']} self.diff_dict = {'a.py': Diff(self.file_dict['a.py']), 'b': Diff(self.file_dict['b'])} self.diff_dict['a.py'].add_lines(1, ['test\n']) self.diff_dict['a.py'].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('no_color', 'True'))
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_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 first_part = line[:x+1]