Ejemplo n.º 1
0
    def test_Processor_glob_pattern(self):
        request = Message()
        response = Message()

        processors[Message.ImplementationFileGlobPatternRequest](request, response, None)

        self.assertEqual(response.implementationFileGlobPatternResponse.globPatterns, ["step_impl/**/*.py"])
Ejemplo n.º 2
0
    def test_Processor_step_name_request(self):
        registry.add_step('Step <a> with <b>', 'func', '', {
            'start': 1,
            'startChar': 0,
            'end': 3,
            'endChar': 10
        })
        registry.add_step('Step 4', 'func1', '', {
            'start': 5,
            'startChar': 0,
            'end': 6,
            'endChar': 10
        })
        response = Message()
        request = Message()
        request.stepNameRequest.stepValue = 'Step {} with {}'

        processors[Message.StepNameRequest](request, response, None)

        self.assertEqual(Message.StepNameResponse, response.messageType)
        self.assertEqual(['Step <a> with <b>'],
                         response.stepNameResponse.stepName)
        self.assertEqual(True, response.stepNameResponse.isStepPresent)
        self.assertEqual(False, response.stepNameResponse.hasAlias)

        response = Message()
        request = Message()
        request.stepNameRequest.stepValue = 'Step 4'

        processors[Message.StepNameRequest](request, response, None)

        self.assertEqual(Message.StepNameResponse, response.messageType)
        self.assertEqual(['Step 4'], response.stepNameResponse.stepName)
        self.assertEqual(True, response.stepNameResponse.isStepPresent)
        self.assertEqual(False, response.stepNameResponse.hasAlias)
Ejemplo n.º 3
0
def dispatch_messages(socket):
    while True:
        request = read_message(socket, Message())
        response = Message()
        processors[request.messageType](request, response, socket)
        if request.messageType != Message.CacheFileRequest:
            send_message(response, request, socket)
Ejemplo n.º 4
0
    def test_Processor_refactor_request_with_add_param_and_invalid_identifier(self):
        response = Message()
        request = Message()
        request.refactorRequest.saveChanges = True
        request.refactorRequest.oldStepValue.stepValue = 'Vowels in English language are {}.'
        request.refactorRequest.oldStepValue.parameters.append('vowels')
        request.refactorRequest.newStepValue.parameterizedStepValue = 'Vowels in English language is \
<vowels> <vowels!2_ab%$>.'
        request.refactorRequest.newStepValue.stepValue = 'Vowels in English language is {} {}.'
        request.refactorRequest.newStepValue.parameters.extend(['vowels', 'vowels!2_ab%$'])
        position = ParameterPosition()
        position.oldPosition = 0
        position.newPosition = 0
        param_position = ParameterPosition()
        param_position.oldPosition = -1
        param_position.newPosition = 1
        request.refactorRequest.paramPositions.extend([position, param_position])

        processors[Message.RefactorRequest](request, response, None)
        actual_data = self.getActualText()

        self.assertEqual(Message.RefactorResponse, response.messageType)
        self.assertEqual(True,
                         response.refactorResponse.success,
                         response.refactorResponse.error)

        self.assertEqual([RefactorTests.path],
                         response.refactorResponse.filesChanged)

        expected = """@step("Vowels in English language is <vowels> <vowels!2_ab%$>.")
def assert_default_vowels(given_vowels, arg1):
    Messages.write_message("Given vowels are {0}".format(given_vowels))
    assert given_vowels == "".join(vowels)
"""
        self.assertEqual(expected, actual_data)
Ejemplo n.º 5
0
    def test_Processor_failed_execute_step_request_with_continue_on_failure(
            self):
        registry.add_step('Step 4', failing_impl, '')
        registry.continue_on_failure(failing_impl, [IndexError])

        response = Message()

        request = Message()
        request.executeStepRequest.parsedStepText = 'Step 4'

        processors[Message.ExecuteStep](request, response, None)

        self.assertEqual(Message.ExecutionStatusResponse, response.messageType)
        self.assertEqual(
            True, response.executionStatusResponse.executionResult.failed)
        self.assertEqual(
            ProtoExecutionResult.ASSERTION,
            response.executionStatusResponse.executionResult.errorType)
        self.assertNotEqual(
            '', response.executionStatusResponse.executionResult.errorMessage)
        self.assertNotEqual(
            '', response.executionStatusResponse.executionResult.stackTrace)
        self.assertEqual(
            True,
            response.executionStatusResponse.executionResult.recoverableError)
Ejemplo n.º 6
0
    def test_Processor_step_position_request(self):
        registry.add_step('Step <a> with <b>', 'func', 'foo.py', {
            'start': 0,
            'startChar': 0,
            'end': 3,
            'endChar': 10
        })
        registry.add_step('Step 1', 'func', 'foo.py', {
            'start': 4,
            'startChar': 0,
            'end': 7,
            'endChar': 10
        })

        response = Message()
        request = Message()
        request.stepPositionsRequest.filePath = 'foo.py'

        processors[Message.StepPositionsRequest](request, response, None)

        self.assertEqual(Message.StepPositionsResponse, response.messageType)
        self.assertEqual('', response.refactorResponse.error)

        steps = [(p.stepValue, p.span.start)
                 for p in response.stepPositionsResponse.stepPositions]

        self.assertIn(('Step {} with {}', 0), steps)
        self.assertIn(('Step 1', 4), steps)
Ejemplo n.º 7
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")
Ejemplo n.º 8
0
    def test_Processor_cache_file_with_closed_status(self):
        request = Message()
        response = Message()

        self.load_content_steps('''\
        from getgauge.python import step

        @step('foo1')
        def foo():
            pass
        ''')

        request.cacheFileRequest.filePath = 'foo.py'
        request.cacheFileRequest.status = CacheFileRequest.CLOSED
        self.fs.create_file('foo.py',
                            contents=dedent('''\
        from getgauge.python import step

        @step('foo <bar>')
        def foo():
            pass
        '''))
        processors[Message.CacheFileRequest](request, response, None)

        self.assertEqual(registry.is_implemented('foo1'), False)
        self.assertEqual(registry.is_implemented('foo {}'), True)
Ejemplo n.º 9
0
    def test_Processor_refactor_request_with_remove_param(self):
        response = Message()
        request = Message()
        request.refactorRequest.saveChanges = True
        request.refactorRequest.oldStepValue.stepValue = 'Vowels in English language are {}.'
        request.refactorRequest.oldStepValue.parameters.append('vowels')
        request.refactorRequest.newStepValue.parameterizedStepValue = 'Vowels in English language is.'
        request.refactorRequest.newStepValue.stepValue = 'Vowels in English language is.'

        processors[Message.RefactorRequest](request, response, None)

        actual_data = self.getActualText()

        self.assertEqual(Message.RefactorResponse, response.messageType)
        self.assertEqual(True,
                         response.refactorResponse.success,
                         response.refactorResponse.error)

        self.assertEqual([RefactorTests.path],
                         response.refactorResponse.filesChanged)

        expected = """@step("Vowels in English language is.")
def assert_default_vowels():
    Messages.write_message("Given vowels are {0}".format(given_vowels))
    assert given_vowels == "".join(vowels)
"""
        self.assertEqual(expected, actual_data)
Ejemplo n.º 10
0
    def test_Processor_step_ending_execution_request(self):
        registry.add_after_step(impl1)
        registry.add_after_step(impl2)
        response = Message()
        request = Message()
        processors[Message.StepExecutionEnding](request, response, None)

        self.assertEqual(Message.ExecutionStatusResponse, response.messageType)
        self.assertEqual(False, response.executionStatusResponse.executionResult.failed)
Ejemplo n.º 11
0
    def test_Processor_scenario_starting_execution_request(self):
        registry.add_before_scenario(impl1)
        registry.add_before_scenario(impl2)
        response = Message()
        request = Message()
        processors[Message.ScenarioExecutionStarting](request, response, None)

        self.assertEqual(Message.ExecutionStatusResponse, response.messageType)
        self.assertEqual(False, response.executionStatusResponse.executionResult.failed)
Ejemplo n.º 12
0
    def test_Processor_failing_step_ending_execution_request(self):
        registry.add_after_step(failing_impl)
        response = Message()
        request = Message()
        processors[Message.StepExecutionEnding](request, response, None)

        self.assertEqual(Message.ExecutionStatusResponse, response.messageType)
        self.assertEqual(True, response.executionStatusResponse.executionResult.failed)
        self.assertEqual(ProtoExecutionResult.ASSERTION, response.executionStatusResponse.executionResult.errorType)
        self.assertEqual('list index out of range', response.executionStatusResponse.executionResult.errorMessage)
        self.assertNotEqual('', response.executionStatusResponse.executionResult.stackTrace)
Ejemplo n.º 13
0
    def test_Processor_step_name_request_with_unimplemented_step(self):
        response = Message()
        request = Message()
        request.stepNameRequest.stepValue = 'Step {} with {}'

        processors[Message.StepNameRequest](request, response, None)

        self.assertEqual(Message.StepNameResponse, response.messageType)
        self.assertEqual([], response.stepNameResponse.stepName)
        self.assertEqual(False, response.stepNameResponse.isStepPresent)
        self.assertEqual(False, response.stepNameResponse.hasAlias)
Ejemplo n.º 14
0
    def test_Processor_cache_file_with_create_status(self):
        request = Message()
        response = Message()

        request.cacheFileRequest.filePath = 'foo.py'
        request.cacheFileRequest.status = CacheFileRequest.CREATED
        self.fs.create_file('foo.py',
                            contents="from getgauge.python import step\n@step('foo <bar>')\ndef foo():\n\tpass\n")
        processors[Message.CacheFileRequest](request, response, None)

        self.assertEqual(registry.is_implemented('foo {}'), True)
Ejemplo n.º 15
0
    def test_Processor_failed_execute_step_request(self):
        response = Message()
        request = Message()

        processors[Message.ExecuteStep](request, response, None)

        self.assertEqual(Message.ExecutionStatusResponse, response.messageType)
        self.assertEqual(True, response.executionStatusResponse.executionResult.failed)
        self.assertEqual(ProtoExecutionResult.ASSERTION, response.executionStatusResponse.executionResult.errorType)
        self.assertNotEqual('', response.executionStatusResponse.executionResult.errorMessage)
        self.assertNotEqual('', response.executionStatusResponse.executionResult.stackTrace)
        self.assertEqual(False, response.executionStatusResponse.executionResult.recoverableError)
Ejemplo n.º 16
0
    def test_Processor_cache_file_with_delete_status(self):
        request = Message()
        response = Message()
        ast = loader.generate_ast("from getgauge.python import step\n@step('foo1')\ndef foo():\n\tpass\n", "foo.py")
        loader.load_steps(ast, "foo.py")

        request.cacheFileRequest.filePath = 'foo.py'
        request.cacheFileRequest.status = CacheFileRequest.DELETED

        processors[Message.CacheFileRequest](request, response, None)

        self.assertEqual(registry.is_implemented('foo1'), False)
Ejemplo n.º 17
0
    def test_Processor_valid_step_validate_request(self):
        registry.add_step('Step <a> with <b>', 'func', '')
        registry.add_step('Step 4', 'func1', '')

        response = Message()

        request = Message()
        request.stepValidateRequest.stepText = 'Step {} with {}'

        processors[Message.StepValidateRequest](request, response, None)

        self.assertEqual(Message.StepValidateResponse, response.messageType)
        self.assertTrue(response.stepValidateResponse.isValid)
Ejemplo n.º 18
0
    def test_Processor_step_name_request_with_aliases(self):
        registry.add_step(['Step 1', 'Step 2', 'Step 3'], 'func1', '',
                          {'start': 5, 'startChar': 0, 'end': 6, 'endChar': 10})
        response = Message()
        request = Message()
        request.stepNameRequest.stepValue = 'Step 1'

        processors[Message.StepNameRequest](request, response, None)
        self.assertEqual(Message.StepNameResponse, response.messageType)
        self.assertTrue('Step 1' in response.stepNameResponse.stepName)
        self.assertTrue('Step 2' in response.stepNameResponse.stepName)
        self.assertTrue('Step 3' in response.stepNameResponse.stepName)
        self.assertEqual(True, response.stepNameResponse.isStepPresent)
        self.assertEqual(True, response.stepNameResponse.hasAlias)
Ejemplo n.º 19
0
    def test_Processor_invalid_step_validate_request_when_duplicate_impl_found(self):
        registry.add_step('Step <a> with <b>', impl, '', {'start': 0})
        registry.add_step('Step <a> with <b>', impl, '', {'start': 2})

        response = Message()

        request = Message()
        request.stepValidateRequest.stepText = 'Step {} with {}'

        processors[Message.StepValidateRequest](request, response, None)

        self.assertEqual(Message.StepValidateResponse, response.messageType)
        self.assertFalse(response.stepValidateResponse.isValid)
        self.assertEqual(StepValidateResponse.DUPLICATE_STEP_IMPLEMENTATION, response.stepValidateResponse.errorType)
Ejemplo n.º 20
0
    def test_Processor_refactor_request_when_multiple_impl_found(self):
        registry.add_step('Step <a> with <b>', 'func', '')
        registry.add_step('Step <a> with <b>', 'func', '')
        response = Message()
        request = Message()
        request.refactorRequest.oldStepValue.stepValue = 'Step {} with {}'
        request.refactorRequest.oldStepValue.parameterizedStepValue = 'Step <a> with <b>'

        processors[Message.RefactorRequest](request, response, None)

        self.assertEqual(Message.RefactorResponse, response.messageType)
        self.assertEqual(False, response.refactorResponse.success)
        self.assertEqual('Reason: Multiple Implementation found for `Step <a> with <b>`',
                         response.refactorResponse.error)
Ejemplo n.º 21
0
    def test_Processor_execute_step_request(self):
        registry.add_step('Step 4', impl1, '')

        response = Message()

        request = Message()
        request.executeStepRequest.parsedStepText = 'Step 4'

        processors[Message.ExecuteStep](request, response, None)

        self.assertEqual(Message.ExecutionStatusResponse, response.messageType)
        self.assertEqual(False, response.executionStatusResponse.executionResult.failed)
        self.assertEqual('', response.executionStatusResponse.executionResult.errorMessage)
        self.assertEqual('', response.executionStatusResponse.executionResult.stackTrace)
Ejemplo n.º 22
0
    def test_Processor_refactor_request_without_save_changes_add_param_and_invalid_identifier(
            self):
        response = Message()
        request = Message()

        request.refactorRequest.saveChanges = False
        request.refactorRequest.oldStepValue.stepValue = 'Vowels in English language are {}.'
        request.refactorRequest.oldStepValue.parameters.append('vowels')
        request.refactorRequest.newStepValue.parameterizedStepValue = 'Vowels in English language is \
<vowels> <vowels!2_ab%$>.'

        request.refactorRequest.newStepValue.stepValue = 'Vowels in English language is {} {}.'
        request.refactorRequest.newStepValue.parameters.extend(
            ['vowels', 'vowels!2_ab%$'])
        position = ParameterPosition()
        position.oldPosition = 0
        position.newPosition = 0
        param_position = ParameterPosition()
        param_position.oldPosition = -1
        param_position.newPosition = 1
        request.refactorRequest.paramPositions.extend(
            [position, param_position])

        old_content = self.getActualText()

        processor.refactor_step(request.refactorRequest, response, None)

        self.assertEqual(Message.RefactorResponse, response.messageType)
        self.assertEqual(True, response.refactorResponse.success,
                         response.refactorResponse.error)

        self.assertEqual([RefactorTests.path],
                         response.refactorResponse.filesChanged)
        expected = """@step("Vowels in English language is <vowels> <vowels!2_ab%$>.")
def assert_default_vowels(arg0, arg1):
    Messages.write_message("Given vowels are {0}".format(given_vowels))
    assert given_vowels == "".join(vowels)
"""
        self.assertEqual(expected,
                         response.refactorResponse.fileChanges[0].fileContent)
        self.assertEqual(old_content, self.getActualText())
        diff_contents = [
            diff.content
            for diff in response.refactorResponse.fileChanges[0].diffs
        ]
        self.assertIn(
            '"Vowels in English language is <vowels> <vowels!2_ab%$>."',
            diff_contents)
        self.assertIn('arg0, arg1', diff_contents)
Ejemplo n.º 23
0
    def test_Processor_cache_file_with_closed_status(self):
        request = Message()
        response = Message()

        ast = loader.generate_ast("from getgauge.python import step\n@step('foo1')\ndef foo():\n\tpass\n", "foo.py")
        loader.load_steps(ast, "foo.py")

        request.cacheFileRequest.filePath = 'foo.py'
        request.cacheFileRequest.status = CacheFileRequest.CLOSED
        self.fs.create_file('foo.py',
                            contents="from getgauge.python import step\n@step('foo <bar>')\ndef foo():\n\tpass\n")
        processors[Message.CacheFileRequest](request, response, None)

        self.assertEqual(registry.is_implemented('foo1'), False)
        self.assertEqual(registry.is_implemented('foo {}'), True)
Ejemplo n.º 24
0
    def test_Processor_cache_file_with_changed_status(self):
        request = Message()
        response = Message()
        loader.load_steps(
            "from getgauge.python import step\n@step('foo1')\ndef foo():\n\tpass\n",
            'foo.py')

        request.cacheFileRequest.filePath = 'foo.py'
        request.cacheFileRequest.content = "from getgauge.python import step\n@step('foo <bar>')\ndef foo():\n\tpass\n"
        request.cacheFileRequest.status = CacheFileRequest.CHANGED

        processors[Message.CacheFileRequest](request, response, None)

        self.assertEqual(registry.is_implemented('foo1'), False)
        self.assertEqual(registry.is_implemented('foo {}'), True)
Ejemplo n.º 25
0
    def test_create_execution_context_from(self):
        message = Message()
        spec_name = 'SPEC_NAME'
        spec_file_name = 'SPEC_FILE_NAME'
        scenario_name = 'SCENARIO_NAME'
        step_name = 'STEP_NAME'

        message.executionStartingRequest.\
            currentExecutionInfo.currentSpec.name = spec_name
        message.executionStartingRequest.\
            currentExecutionInfo.currentSpec.fileName = spec_file_name
        message.executionStartingRequest.\
            currentExecutionInfo.currentSpec.isFailed = True
        message.executionStartingRequest.\
            currentExecutionInfo.currentScenario.name = scenario_name
        message.executionStartingRequest.\
            currentExecutionInfo.currentScenario.isFailed = False
        message.executionStartingRequest.\
            currentExecutionInfo.currentStep.step.actualStepText = step_name
        message.executionStartingRequest.\
            currentExecutionInfo.currentStep.isFailed = True

        specification = Specification(spec_name, spec_file_name, True, [])
        scenario = Scenario(scenario_name, False, [])
        step = Step(step_name, True)

        context = ExecutionContext(specification, scenario, step)

        expected_execution_context = create_execution_context_from(
            message.executionStartingRequest.currentExecutionInfo)
        self.assertEqual(expected_execution_context, context)
Ejemplo n.º 26
0
    def test_Processor_cache_file_with_delete_status(self):
        request = Message()
        response = Message()
        self.load_content_steps('''\
        from getgauge.python import step

        @step('foo1')
        def foo():
            pass
        ''')

        request.cacheFileRequest.filePath = 'foo.py'
        request.cacheFileRequest.status = CacheFileRequest.DELETED

        processors[Message.CacheFileRequest](request, response, None)

        self.assertEqual(registry.is_implemented('foo1'), False)
Ejemplo n.º 27
0
    def test_Processor_invalid_step_validate_request_when_no_impl_found(self):
        registry.add_step('Step <a> with <b>', 'func', '')
        registry.add_step('Step 4', 'func1', '')

        response = Message()

        request = Message()
        request.stepValidateRequest.stepText = 'Step2'
        request.stepValidateRequest.stepValue.stepValue = 'Step2'

        processors[Message.StepValidateRequest](request, response, None)

        self.assertEqual(Message.StepValidateResponse, response.messageType)
        self.assertFalse(response.stepValidateResponse.isValid)
        self.assertEqual(StepValidateResponse.STEP_IMPLEMENTATION_NOT_FOUND, response.stepValidateResponse.errorType)
        self.assertTrue('@step("")\ndef step2():\n    assert False, "Add implementation code"' in
                        response.stepValidateResponse.suggestion)
Ejemplo n.º 28
0
    def test_Processor_refactor_request_without_save_change_with_add_param(
            self):
        response = Message()
        request = Message()

        request.refactorRequest.saveChanges = False
        request.refactorRequest.oldStepValue.stepValue = 'Vowels in English language are {}.'
        request.refactorRequest.oldStepValue.parameters.append('vowels')
        request.refactorRequest.newStepValue.parameterizedStepValue = 'Vowels in English language \
is <vowels> <bsdfdsf>.'

        request.refactorRequest.newStepValue.stepValue = 'Vowels in English language is {} {}.'
        request.refactorRequest.newStepValue.parameters.extend(
            ['vowels', 'bsdfdsf'])
        position = ParameterPosition()
        position.oldPosition = 0
        position.newPosition = 0
        param_position = ParameterPosition()
        param_position.oldPosition = -1
        param_position.newPosition = 1
        request.refactorRequest.paramPositions.extend(
            [position, param_position])

        old_content = self.getActualText()

        processors[Message.RefactorRequest](request, response, None)

        expected = """@step("Vowels in English language is <vowels> <bsdfdsf>.")
def assert_default_vowels(given_vowels, arg1):
    Messages.write_message("Given vowels are {0}".format(given_vowels))
    assert given_vowels == "".join(vowels)
"""

        self.assertEqual(Message.RefactorResponse, response.messageType)
        self.assertEqual(True, response.refactorResponse.success,
                         response.refactorResponse.error)

        self.assertEqual([RefactorTests.path],
                         response.refactorResponse.filesChanged)

        self.assertEqual(RefactorTests.path,
                         response.refactorResponse.fileChanges[0].fileName)
        self.assertEqual(expected,
                         response.refactorResponse.fileChanges[0].fileContent)
        self.assertEqual(old_content, self.getActualText())
Ejemplo n.º 29
0
    def test_Processor_step_names_request(self):
        registry.add_step('Step <a> with <b>', 'func', '')
        registry.add_step('Step 4', 'func1', '')
        response = Message()

        processors[Message.StepNamesRequest](None, response, None)

        self.assertEqual(Message.StepNamesResponse, response.messageType)
        self.assertEqual({'Step <a> with <b>', 'Step 4'}, set(response.stepNamesResponse.steps))
Ejemplo n.º 30
0
    def test_Processor_execute_step_request_with_param(self):
        registry.add_step('Step <a> with <b>', impl, '')
        registry.add_step('Step 4', 'func1', '')

        response = Message()

        request = Message()
        request.executeStepRequest.parsedStepText = 'Step {} with {}'
        parameter = Parameter()
        parameter.value = 'param 1'
        parameter1 = Parameter()
        parameter1.value = 'param 2'
        request.executeStepRequest.parameters.extend([parameter, parameter1])

        processors[Message.ExecuteStep](request, response, None)

        self.assertEqual(Message.ExecutionStatusResponse, response.messageType)
        self.assertEqual(False, response.executionStatusResponse.executionResult.failed)
        self.assertEqual('', response.executionStatusResponse.executionResult.errorMessage)
        self.assertEqual('', response.executionStatusResponse.executionResult.stackTrace)