示例#1
0
def test_string_variables_completions_unable_to_tokenize_2(
        workspace, libspec_manager, data_regression):
    from robotframework_ls.impl.completion_context import CompletionContext
    from robotframework_ls.impl import variable_completions

    workspace.set_root("case1", libspec_manager=libspec_manager)
    doc = workspace.get_doc("case1.robot")
    doc.source = """
*** Variables ***
${NAME}         Robot Framework
${VERSION}      2.0
${ROBOT} =      ${NAME} ${VERSION}

*** Test Cases ***
List Variable
    Log    ${NAME}
    Should Contain    ${na ${na}"""

    line, col = doc.get_last_line_col()
    completions = variable_completions.complete(
        CompletionContext(doc,
                          workspace=workspace.ws,
                          line=line,
                          col=col - len(" ${na}")))
    data_regression.check(completions)
示例#2
0
    def _threaded_complete_all(self, doc_uri, line, col, monitor: IMonitor):
        from robotframework_ls.impl import section_name_completions
        from robotframework_ls.impl import keyword_completions
        from robotframework_ls.impl import variable_completions
        from robotframework_ls.impl import filesystem_section_completions
        from robotframework_ls.impl import keyword_parameter_completions

        completion_context = self._create_completion_context(
            doc_uri, line, col, monitor)
        if completion_context is None:
            return []

        ret = section_name_completions.complete(completion_context)
        if not ret:
            ret.extend(
                filesystem_section_completions.complete(completion_context))

        if not ret:
            ret.extend(keyword_completions.complete(completion_context))

        if not ret:
            ret.extend(variable_completions.complete(completion_context))

        if not ret:
            ret.extend(
                keyword_parameter_completions.complete(completion_context))

        return ret
示例#3
0
    def m_complete_all(self, doc_uri, line, col):
        from robotframework_ls.impl import section_name_completions
        from robotframework_ls.impl import keyword_completions
        from robotframework_ls.impl import variable_completions

        completion_context = self._create_completion_context(doc_uri, line, col)
        if completion_context is None:
            return []

        ret = section_name_completions.complete(completion_context)
        ret.extend(keyword_completions.complete(completion_context))
        ret.extend(variable_completions.complete(completion_context))
        return ret
示例#4
0
def test_list_variables_completions_in_variables(workspace, libspec_manager,
                                                 data_regression):
    from robotframework_ls.impl.completion_context import CompletionContext
    from robotframework_ls.impl import variable_completions

    workspace.set_root("case1", libspec_manager=libspec_manager)
    doc = workspace.get_doc("case1.robot")
    doc.source = """
*** Variables ***
@{NAMES}        Matti       Teppo
@{NAMES2}       @{"""

    completions = variable_completions.complete(
        CompletionContext(doc, workspace=workspace.ws))
    data_regression.check(completions)
示例#5
0
def test_variables_completions_in_resource_paths(workspace, libspec_manager,
                                                 data_regression):
    from robotframework_ls.impl.completion_context import CompletionContext
    from robotframework_ls.impl import variable_completions

    workspace.set_root("case4", libspec_manager=libspec_manager)
    doc = workspace.get_doc("case4.robot")
    doc.source = """
*** Variables ***
${SOME_DIR}         c:/foo/bar
    
*** Settings ***
Resource           ${some_d"""
    completions = variable_completions.complete(
        CompletionContext(doc, workspace=workspace.ws))
    data_regression.check(completions)
示例#6
0
def test_variables_completions_builtins(workspace, libspec_manager,
                                        data_regression):
    from robotframework_ls.impl.completion_context import CompletionContext
    from robotframework_ls.impl import variable_completions

    workspace.set_root("case4", libspec_manager=libspec_manager)
    doc = workspace.get_doc("case4.robot")
    doc.source = """
*** Keywords ***
This is the Test
    [Arguments]    ${arg}    ${arg2}
    Log To Console    ${PREV_TEST_ST"""

    completions = variable_completions.complete(
        CompletionContext(doc, workspace=workspace.ws))
    data_regression.check(completions)
示例#7
0
def test_variables_completions_assign_3(workspace, libspec_manager,
                                        data_regression):
    from robotframework_ls.impl.completion_context import CompletionContext
    from robotframework_ls.impl import variable_completions

    workspace.set_root("case5", libspec_manager=libspec_manager)
    doc = workspace.get_doc("case5.robot")
    doc.source += """
*** Test Cases ***
[SetUp]
    ${variable_x} =    ${variable_y}    @{variable_z}=    Get X    an argument
    Log    We got @{variable"""

    completions = variable_completions.complete(
        CompletionContext(doc, workspace=workspace.ws))
    data_regression.check(completions)
示例#8
0
def test_variables_completions_recursive(workspace, libspec_manager,
                                         data_regression):
    from robotframework_ls.impl.completion_context import CompletionContext
    from robotframework_ls.impl import variable_completions

    workspace.set_root("case5", libspec_manager=libspec_manager)
    doc = workspace.get_doc("case5.robot")
    doc.source += """

*** Test Cases ***
List Variable
    Log    ${VAR"""

    completions = variable_completions.complete(
        CompletionContext(doc, workspace=workspace.ws))
    data_regression.check(completions)
示例#9
0
    def _threaded_complete_all(self, doc_uri, line, col, monitor: IMonitor):
        from robotframework_ls.impl import section_name_completions
        from robotframework_ls.impl import keyword_completions
        from robotframework_ls.impl import variable_completions
        from robotframework_ls.impl import filesystem_section_completions
        from robotframework_ls.impl import keyword_parameter_completions
        from robotframework_ls.impl import auto_import_completions
        from robotframework_ls.impl.collect_keywords import (
            collect_keyword_name_to_keyword_found,
        )
        from robotframework_ls.impl import ast_utils

        completion_context = self._create_completion_context(
            doc_uri, line, col, monitor
        )
        if completion_context is None:
            return []

        ret = section_name_completions.complete(completion_context)
        if not ret:
            ret.extend(filesystem_section_completions.complete(completion_context))

        if not ret:
            token_info = completion_context.get_current_token()
            if token_info is not None:
                token = ast_utils.get_keyword_name_token(
                    token_info.node, token_info.token
                )
                if token is not None:
                    keyword_name_to_keyword_found: Dict[
                        str, List[IKeywordFound]
                    ] = collect_keyword_name_to_keyword_found(completion_context)
                    ret.extend(keyword_completions.complete(completion_context))
                    ret.extend(
                        auto_import_completions.complete(
                            completion_context, keyword_name_to_keyword_found
                        )
                    )
                    return ret

        if not ret:
            ret.extend(variable_completions.complete(completion_context))

        if not ret:
            ret.extend(keyword_parameter_completions.complete(completion_context))

        return ret
示例#10
0
def test_list_variables_completions_basic_2(workspace, libspec_manager,
                                            data_regression):
    from robotframework_ls.impl.completion_context import CompletionContext
    from robotframework_ls.impl import variable_completions

    workspace.set_root("case1", libspec_manager=libspec_manager)
    doc = workspace.get_doc("case1.robot")
    doc.source = """*** Variables ***
@{NAMES}        Matti       Teppo

*** Test Cases ***
List Variable
    Should Contain    @{NA}"""
    line, col = doc.get_last_line_col()
    completions = variable_completions.complete(
        CompletionContext(doc, workspace=workspace.ws, line=line, col=col - 1))
    data_regression.check(completions)
示例#11
0
def test_dictionary_variables_completions_with_ampersand(
        workspace, libspec_manager, data_regression):
    from robotframework_ls.impl.completion_context import CompletionContext
    from robotframework_ls.impl import variable_completions

    workspace.set_root("case1", libspec_manager=libspec_manager)
    doc = workspace.get_doc("case1.robot")
    doc.source = """*** Variables ***
&{ROBOT}   Name=Robot Framework   Version=4.0

***Test Cases***
Test dictionary variable completion
   Log to Console   &{ROB"""

    completions = variable_completions.complete(
        CompletionContext(doc, workspace=workspace.ws))
    data_regression.check(completions)
示例#12
0
    def _complete_from_completion_context(self, completion_context):
        from robotframework_ls.impl import section_name_completions
        from robotframework_ls.impl import keyword_completions
        from robotframework_ls.impl import variable_completions
        from robotframework_ls.impl import dictionary_completions
        from robotframework_ls.impl import filesystem_section_completions
        from robotframework_ls.impl import keyword_parameter_completions
        from robotframework_ls.impl import auto_import_completions
        from robotframework_ls.impl.collect_keywords import (
            collect_keyword_name_to_keyword_found,
        )
        from robotframework_ls.impl import ast_utils

        ret = section_name_completions.complete(completion_context)
        if not ret:
            ret.extend(filesystem_section_completions.complete(completion_context))

        if not ret:
            token_info = completion_context.get_current_token()
            if token_info is not None:
                token = ast_utils.get_keyword_name_token(
                    token_info.node, token_info.token
                )
                if token is not None:
                    keyword_name_to_keyword_found: Dict[
                        str, List[IKeywordFound]
                    ] = collect_keyword_name_to_keyword_found(completion_context)
                    ret.extend(keyword_completions.complete(completion_context))
                    ret.extend(
                        auto_import_completions.complete(
                            completion_context, keyword_name_to_keyword_found
                        )
                    )
                    return ret

        if not ret:
            ret.extend(variable_completions.complete(completion_context))

        if not ret:
            ret.extend(dictionary_completions.complete(completion_context))

        if not ret:
            ret.extend(keyword_parameter_completions.complete(completion_context))

        return ret
示例#13
0
def test_dict_variables_completions(workspace, libspec_manager,
                                    data_regression):
    from robotframework_ls.impl.completion_context import CompletionContext
    from robotframework_ls.impl import variable_completions

    workspace.set_root("case1", libspec_manager=libspec_manager)
    doc = workspace.get_doc("case1.robot")
    doc.source = """
*** Variables ***
&{USER 1}       name=Matti    address=xxx         phone=123

*** Test Cases ***
List Variable
    Should Contain    &{"""

    completions = variable_completions.complete(
        CompletionContext(doc, workspace=workspace.ws))
    data_regression.check(completions)
示例#14
0
def test_variables_completions_in_variable_files(workspace, libspec_manager,
                                                 data_regression):
    from robotframework_ls.impl.completion_context import CompletionContext
    from robotframework_ls.impl import variable_completions

    workspace.set_root("case_vars_file", libspec_manager=libspec_manager)
    doc = workspace.get_doc("case_vars_file.robot")
    doc.source = """
*** Settings ***
Variables    ./robotvars.py


*** Test Cases ***
Test
    Log    ${VARIAB"""
    completions = variable_completions.complete(
        CompletionContext(doc, workspace=workspace.ws))
    data_regression.check(completions)
示例#15
0
def test_variables_completions_assign_4(workspace, libspec_manager,
                                        data_regression):
    from robotframework_ls.impl.completion_context import CompletionContext
    from robotframework_ls.impl import variable_completions

    workspace.set_root("case5", libspec_manager=libspec_manager)
    doc = workspace.get_doc("case5.robot")
    doc.source += """
*** Test Cases ***
[SetUp]
    ${variable_x} =    ${variable_y}    @{variable_z}=    Get X    an argument
    
Test1
    Log    We got @{variable"""

    # Note: local variables aren't available from one test to another.
    completions = variable_completions.complete(
        CompletionContext(doc, workspace=workspace.ws))
    data_regression.check(completions, basename="no_variables")
示例#16
0
def test_string_variables_completions_basic_1(workspace, libspec_manager,
                                              data_regression):
    from robotframework_ls.impl.completion_context import CompletionContext
    from robotframework_ls.impl import variable_completions

    workspace.set_root("case1", libspec_manager=libspec_manager)
    doc = workspace.get_doc("case1.robot")
    doc.source = """
*** Variables ***
${NAME}         Robot Framework
${VERSION}      2.0
${ROBOT} =      ${NAME} ${VERSION}

*** Test Cases ***
List Variable
    Log    ${NAME}
    Should Contain    ${N"""

    completions = variable_completions.complete(
        CompletionContext(doc, workspace=workspace.ws))
    data_regression.check(completions)