def create_diff(old_annotation_loc, step, old_params_loc, params, with_location): annotation_diff, params_diff = TextDiff(), TextDiff() annotation_diff.content = step params_diff.content = params if with_location: update_annotation_diff(annotation_diff, old_annotation_loc) update_params_diff(params_diff, old_params_loc) return [annotation_diff, params_diff]
def test_Processor_put_stub_impl_request(self): request = Message() response = Message() codes = ["code1", "code2"] request.stubImplementationCodeRequest.implementationFilePath = "" request.stubImplementationCodeRequest.codes.extend(codes) processors[Message.StubImplementationCodeRequest](request, response, None) expected_output_codes = dedent('''\ from getgauge.python import step code1 code2''') expected_span = Span(**{ 'start': 0, 'startChar': 0, 'end': 0, 'endChar': 0 }) expected_text_diff = TextDiff(**{ 'span': expected_span, 'content': expected_output_codes }) self.assertEqual(len(response.fileDiff.textDiffs), 1) self.assertEqual(response.fileDiff.textDiffs[0], expected_text_diff) self.assertEqual(path.basename(response.fileDiff.filePath), "step_implementation.py")
def stub_impl_response(codes, file_name, response): content = read_file_contents(file_name) prefix = "" if content is not None: new_line_char = '\n' if len(content.strip().split('\n')) == len(content.split('\n')) else '' last_line = len(content.split('\n')) prefix = "from getgauge.python import step\n" if len(content.strip()) == 0 else new_line_char span = Span(**{'start': last_line, 'startChar': 0, 'end': last_line, 'endChar': 0}) else: file_name = get_file_name() prefix = "from getgauge.python import step\n" span = Span(**{'start': 0, 'startChar': 0, 'end': 0, 'endChar': 0}) codes = [prefix] + codes[:] textDiffs = [TextDiff(**{'span': span, 'content': '\n'.join(codes)})] response.fileDiff.filePath = file_name response.fileDiff.textDiffs.extend(textDiffs)
def refactor_step(request, response, with_location=True): if registry.has_multiple_impls(request.oldStepValue.stepValue): raise Exception('Multiple Implementation found for `{}`'.format( request.oldStepValue.parameterizedStepValue)) info = registry.get_info_for(request.oldStepValue.stepValue) impl_file = PythonFile.parse(info.file_name) diffs = impl_file.refactor_step( info.step_text, request.newStepValue.parameterizedStepValue, _new_parameter_positions(request), ) content = impl_file.get_code() if request.saveChanges: with open(info.file_name, 'w') as f: f.write(content) response.refactorResponse.success = True response.refactorResponse.filesChanged.append(info.file_name) response.refactorResponse.fileChanges.add( fileName=info.file_name, fileContent=content, # FIXME: Remove deprecated field diffs=[TextDiff(span=Span(**d[0]), content=d[1]) for d in diffs], )