Пример #1
0
def process_stub_impl_request(request):
    response = FileDiff()
    file_name = request.implementationFilePath
    codes = request.codes
    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.filePath = file_name
    response.textDiffs.extend(textDiffs)
    return response
Пример #2
0
    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")
Пример #3
0
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)
Пример #4
0
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],
    )
Пример #5
0
def _create_pos(p):
    return StepPositionsResponse.StepPosition(**{
        'stepValue': p['stepValue'],
        'span': Span(**p['span'])
    })