Пример #1
0
def validate_step(request):
    response = StepValidateResponse()
    response.isValid = True
    if registry.is_implemented(request.stepText) is False:
        response.errorType = StepValidateResponse.STEP_IMPLEMENTATION_NOT_FOUND
        response.errorMessage = 'Step implementation not found'
        response.isValid = False
        response.suggestion = _impl_suggestion(request.stepValue)
    elif registry.has_multiple_impls(request.stepText):
        response.isValid = False
        response.errorType = StepValidateResponse.DUPLICATE_STEP_IMPLEMENTATION
        response.suggestion = _duplicate_impl_suggestion(request)
    return response
Пример #2
0
    def test_loader_populates_registry_with_duplicate_steps(self):
        content = dedent("""
        @step("print hello")
        def printf():
            print("hello")


        @step("print hello")
        def print_word():
            print("hello")

        """)
        load_steps(Parser.parse("foo.py", content))
        self.assertTrue(registry.has_multiple_impls("print hello"))
    def test_loader_populates_registry_with_duplicate_steps(self):
        content = """
        @step("print hello")
        def print():
            print("hello")


        @step("print hello")
        def print_word():
            print("hello")

        """
        load_steps(content, "foo.py")
        self.assertTrue(registry.has_multiple_impls("print hello"))
Пример #4
0
def refactor_step(request, response):
    if registry.has_multiple_impls(request.oldStepValue.stepValue):
        step = request.oldStepValue.parameterizedStepValue
        raise Exception('Multiple Implementation found for `{}`'.format(step))
    info = registry.get_info_for(request.oldStepValue.stepValue)
    impl_file = open(info.file_name, 'r+')
    content = _refactor_content(impl_file.read(), info, request)
    if request.saveChanges:
        impl_file.seek(0)
        impl_file.truncate()
        impl_file.write(content)
    impl_file.close()
    response.refactorResponse.fileChanges.add(**{
        'fileName': info.file_name,
        'fileContent': content
    })
    response.refactorResponse.success = True
    response.refactorResponse.filesChanged.append(info.file_name)
Пример #5
0
def validate_step(request, response):
    response.messageType = Message.StepValidateResponse
    response.stepValidateResponse.isValid = True
    if registry.is_implemented(request.stepValidateRequest.stepText) is False:
        response.stepValidateResponse.errorType = StepValidateResponse.STEP_IMPLEMENTATION_NOT_FOUND
        response.stepValidateResponse.errorMessage = "Step implementation not found"
        response.stepValidateResponse.isValid = False
    elif registry.has_multiple_impls(request.stepValidateRequest.stepText):
        response.stepValidateResponse.isValid = False
        response.stepValidateResponse.errorType = StepValidateResponse.DUPLICATE_STEP_IMPLEMENTATION
        response.stepValidateResponse.errorMessage = "Multiple implementation found for `{}` ({})".format(
            request.stepValidateRequest.stepText,
            ", ".join(
                [
                    "{}:{}".format(impl.file_name, impl.line_number)
                    for impl in registry.get_infos_for(request.stepValidateRequest.stepText)
                ]
            ),
        )
Пример #6
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],
    )