Beispiel #1
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
        })
        request = StepNameRequest()
        request.stepValue = 'Step {} with {}'

        response = processor.process_step_name_request(request)
        self.assertTrue(isinstance(response, StepNameResponse))
        self.assertEqual(['Step <a> with <b>'], response.stepName)
        self.assertEqual(True, response.isStepPresent)
        request = StepNameRequest()
        self.assertEqual(False, response.hasAlias)

        request.stepValue = 'Step 4'
        response = processor.process_step_name_request(request)

        self.assertTrue(isinstance(response, StepNameResponse))
        self.assertEqual(['Step 4'], response.stepName)
        self.assertEqual(True, response.isStepPresent)
        self.assertEqual(False, response.hasAlias)
Beispiel #2
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
        })

        request = StepPositionsRequest()
        request.filePath = 'foo.py'

        response = processor.process_step_positions_request(request)

        self.assertTrue(isinstance(response, StepPositionsResponse))
        self.assertEqual('', response.error)

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

        self.assertIn(('Step {} with {}', 0), steps)
        self.assertIn(('Step 1', 4), steps)
Beispiel #3
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)
Beispiel #4
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)
Beispiel #5
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)
Beispiel #6
0
    def test_Processor_step_names_request(self):
        registry.add_step('Step <a> with <b>', 'func', '')
        registry.add_step('Step 4', 'func1', '')

        response = processor.process_step_names_request()

        self.assertTrue(isinstance(response, StepNamesResponse))
        self.assertEqual({'Step <a> with <b>', 'Step 4'}, set(response.steps))
    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))
Beispiel #8
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))
Beispiel #9
0
    def test_Processor_valid_step_validate_request(self):
        registry.add_step('Step <a> with <b>', 'func', '')
        registry.add_step('Step 4', 'func1', '')

        request = StepValidateRequest()
        request.stepText = 'Step {} with {}'
        response = processor.process_validate_step_request(request)

        self.assertTrue(isinstance(response, StepValidateResponse))
        self.assertTrue(response.isValid)
Beispiel #10
0
 def _step(func):
     f_code = sys._getframe().f_back.f_code
     span = {
         'start': f_code.co_firstlineno,
         'startChar': 0,
         'end': 0,
         'endChar': 0
     }
     registry.add_step(step_text, func, f_code.co_filename, span)
     return func
Beispiel #11
0
    def test_Processor_execute_step_request(self):
        registry.add_step('Step 4', impl1, '')

        request = ExecuteStepRequest()
        request.parsedStepText = 'Step 4'

        response = processor.process_execute_step_request(request)

        self.assertTrue(isinstance(response, ExecutionStatusResponse))
        self.assertEqual(False, response.executionResult.failed)
        self.assertEqual('', response.executionResult.errorMessage)
        self.assertEqual('', response.executionResult.stackTrace)
Beispiel #12
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)
    def setUp(self):
        RefactorTests.path = os.path.join(tempfile.gettempdir(), 'step_impl.py')
        RefactorTests.file = open(RefactorTests.path, 'w')
        RefactorTests.file.write("""@step("Vowels in English language are <vowels>.")
def assert_default_vowels(given_vowels):
    Messages.write_message("Given vowels are {0}".format(given_vowels))
    assert given_vowels == "".join(vowels)""")
        RefactorTests.file.close()
        RefactorTests.file = open(RefactorTests.path, 'r')
        RefactorTests.data = RefactorTests.file.read()
        RefactorTests.file.close()
        registry.add_step('Vowels in English language are <vowels>.', None,
                          RefactorTests.path)
Beispiel #14
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)
Beispiel #15
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'

        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)
Beispiel #16
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)
Beispiel #17
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)
Beispiel #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)
Beispiel #19
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', '')
        request = RefactorRequest()
        request.oldStepValue.stepValue = 'Step {} with {}'
        request.oldStepValue.parameterizedStepValue = 'Step <a> with <b>'

        response = processor.process_refactor_request(request)

        self.assertTrue(isinstance(response, RefactorResponse))
        self.assertEqual(False, response.success)
        self.assertEqual(
            'Reason: Multiple Implementation found for `Step <a> with <b>`',
            response.error)
Beispiel #20
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)
Beispiel #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)
Beispiel #22
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)
Beispiel #23
0
    def test_Processor_invalid_step_validate_request_when_duplicate_impl_found(self):
        registry.add_step('Step <a> with <b>', 'func', '')
        registry.add_step('Step <a> with <b>', 'func', '')

        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)
Beispiel #24
0
    def setUp(self):
        RefactorTests.path = os.path.join(tempfile.gettempdir(), "step_impl.py")
        RefactorTests.file = open(RefactorTests.path, "w")
        RefactorTests.file.write(
            """@step("Vowels in English language are <vowels>.")
def assert_default_vowels(given_vowels):
    Messages.write_message("Given vowels are {0}".format(given_vowels))
    assert given_vowels == "".join(vowels)"""
        )
        RefactorTests.file.close()
        RefactorTests.file = open(RefactorTests.path, "r")
        RefactorTests.data = RefactorTests.file.read()
        RefactorTests.file.close()
        registry.add_step("Vowels in English language are <vowels>.", None, RefactorTests.path)
Beispiel #25
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 = StepValidateRequest()
        request.stepText = 'Step {} with {}'

        response = processor.process_validate_step_request(request)

        self.assertTrue(isinstance(response, StepValidateResponse))
        self.assertFalse(response.isValid)
        self.assertEqual(StepValidateResponse.DUPLICATE_STEP_IMPLEMENTATION,
                         response.errorType)
Beispiel #26
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)
Beispiel #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', '')

        request = StepValidateRequest()
        request.stepText = 'Step2'
        request.stepValue.stepValue = 'Step2'

        response = processor.process_validate_step_request(request)

        self.assertTrue(isinstance(response, StepValidateResponse))
        self.assertFalse(response.isValid)
        self.assertEqual(StepValidateResponse.STEP_IMPLEMENTATION_NOT_FOUND,
                         response.errorType)
        self.assertTrue(
            '@step("")\ndef step2():\n    assert False, "Add implementation code"'
            in response.suggestion)
Beispiel #28
0
    def test_Processor_execute_step_request_with_param(self):
        registry.add_step('Step <a> with <b>', impl, '')
        registry.add_step('Step 4', 'func1', '')

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

        response = processor.process_execute_step_request(request)

        self.assertTrue(isinstance(response, ExecutionStatusResponse))
        self.assertEqual(False, response.executionResult.failed)
        self.assertEqual('', response.executionResult.errorMessage)
        self.assertEqual('', response.executionResult.stackTrace)
Beispiel #29
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
        })
        request = StepNameRequest()
        request.stepValue = 'Step 1'

        response = processor.process_step_name_request(request)

        self.assertTrue(isinstance(response, StepNameResponse))
        self.assertTrue('Step 1' in response.stepName)
        self.assertTrue('Step 2' in response.stepName)
        self.assertTrue('Step 3' in response.stepName)
        self.assertEqual(True, response.isStepPresent)
        self.assertEqual(True, response.hasAlias)
Beispiel #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)
Beispiel #31
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)
Beispiel #32
0
    def test_Processor_step_name_request(self):
        registry.add_step('Step <a> with <b>', 'func', '')
        registry.add_step('Step 4', 'func1', '')
        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)
def load_steps(python_file):
    for funcStep in python_file.iter_steps():
        registry.add_step(funcStep[0], funcStep[1], python_file.file_path,
                          funcStep[2])
Beispiel #34
0
 def _step(func):
     f_back = sys._getframe().f_back
     registry.add_step(step_text, func, f_back.f_code.co_filename, inspect.getsourcelines(func)[1])
     return func
Beispiel #35
0
 def _step(func):
     f_back = sys._getframe().f_back
     registry.add_step(step_text, func, f_back.f_code.co_filename,
                       inspect.getsourcelines(func)[1])
     return func
Beispiel #36
0
def add_steps(file_name, func, steps):
    if len(steps) > 1:
        registry.add_step(steps, func, file_name, None)
    elif len(steps) == 1:
        registry.add_step(steps[0], func, file_name, None)
Beispiel #37
0
def add_steps(file_name, func, steps):
    if len(steps) > 1:
        registry.add_step(steps, func, file_name, _create_span(func))
    elif len(steps) == 1:
        registry.add_step(steps[0], func, file_name, _create_span(func))