Exemplo n.º 1
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)
Exemplo n.º 2
0
    def test_Processor_refactor_request_with_add_param_and_only_invalid_identifier(self):
        response = Message()
        request = Message()
        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> <!%$>."
        request.refactorRequest.newStepValue.stepValue = "Vowels in English language is {} {}."
        request.refactorRequest.newStepValue.parameters.extend(["vowels", "!%$"])
        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> <!%$>.")
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)
Exemplo n.º 3
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)
Exemplo n.º 4
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())