Beispiel #1
0
    def test_Processor_process_refactor_request(self):
        content = dedent('''\
        from getgauge.python import step

        @step('Vowels in English language are <aeiou>.')
        def foo(vowels):
            print(vowels)
        ''')
        self.fs.create_file(os.path.join(get_step_impl_dirs()[0], 'foo.py'),
                            contents=content)
        loader.load_files(get_step_impl_dirs())

        request = RefactorRequest()
        request.saveChanges = False
        request.oldStepValue.stepValue = 'Vowels in English language are {}.'
        request.oldStepValue.parameters.append('vowels')
        request.newStepValue.parameterizedStepValue = 'Vowels in English language is <vowels> <bsdfdsf>.'
        request.newStepValue.stepValue = 'Vowels in English language is {} {}.'
        request.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.paramPositions.extend([position, param_position])

        res = processor.process_refactor_request(request)

        self.assertTrue(res.success)
        diff_contents = [diff.content for diff in res.fileChanges[0].diffs]
        self.assertIn("vowels, arg1", diff_contents)
        self.assertIn("'Vowels in English language is <vowels> <bsdfdsf>.'",
                      diff_contents)
Beispiel #2
0
    def test_LspServerHandler_refactor(self):
        handler = LspServerHandler(None)
        content = "from getgauge.python import step\n\n" \
                  "@step('Vowels in English language are <aeiou>.')\n" \
                  "def foo(vowels):" \
                  "\tprint(vowels)"
        self.fs.create_file(os.path.join(get_step_impl_dir(), 'foo.py'), contents=content)
        loader.load_files(get_step_impl_dir())

        request = RefactorRequest()
        request.saveChanges = False
        request.oldStepValue.stepValue = 'Vowels in English language are {}.'
        request.oldStepValue.parameters.append('vowels')
        request.newStepValue.parameterizedStepValue = 'Vowels in English language is <vowels> <bsdfdsf>.'
        request.newStepValue.stepValue = 'Vowels in English language is {} {}.'
        request.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.paramPositions.extend([position, param_position])

        res = handler.Refactor(request, None, False)

        self.assertTrue(res.success)
        diff_contents = [diff.content for diff in res.fileChanges[0].diffs]
        self.assertIn("vowels, arg1", diff_contents)
        self.assertIn('("Vowels in English language is <vowels> <bsdfdsf>.")', diff_contents)
Beispiel #3
0
def load_implementations():
    d = get_step_impl_dirs()
    for impl_dir in d:
        if not path.exists(impl_dir):
            logging.error(
                'can not load implementations from {}. {} does not exist.'.
                format(impl_dir, impl_dir))
    load_files(d)
Beispiel #4
0
def load_implementations():
    d = get_step_impl_dir()
    if path.exists(d):
        load_files(d)
    else:
        logging.error(
            'can not load implementations from {}. {} does not exist.'.format(
                d, d))
Beispiel #5
0
def load_implementations():
    d = get_step_impl_dirs()
    logger.debug("Loading step implementations from {} dirs.".format(
        ', '.join(d)))
    for impl_dir in d:
        if not path.exists(impl_dir):
            logger.error(
                'can not load implementations from {}. {} does not exist.'.
                format(impl_dir, impl_dir))
    load_files(d)