def test_compute_python_launch_from_robocorp_code_launch(
        language_server_initialized: IRobocorpLanguageServerClient,
        cases: CasesFixture):
    client = language_server_initialized

    robot = cases.get_path("custom_envs/pysample/robot.yaml")
    result = _compute_robot_launch_from_robocorp_code_launch(
        client, "Default", robot, pythonExe="c:/temp/py.exe")
    assert result["success"]
    r = result["result"]

    assert os.path.samefile(r["program"],
                            cases.get_path("custom_envs/pysample/task.py"))
    assert os.path.samefile(r["cwd"], cases.get_path("custom_envs/pysample"))
    del r["program"]
    del r["cwd"]

    assert r == {
        "type": "python",
        "name": "Launch Name",
        "request": "launch",
        "pythonArgs": [],
        "args": [],
        "pythonPath": "c:/temp/py.exe",
        "console": "internalConsole",
    }
def test_compute_robot_launch_from_robocorp_code_launch(
        language_server_initialized: IRobocorpLanguageServerClient,
        cases: CasesFixture):
    client = language_server_initialized

    robot = cases.get_path("custom_envs/simple-web-scraper/robot.yaml")
    result = _compute_robot_launch_from_robocorp_code_launch(
        client, "Web scraper", robot)
    assert result["success"]
    r = result["result"]

    assert os.path.samefile(
        r["target"], cases.get_path("custom_envs/simple-web-scraper/tasks"))
    assert os.path.samefile(r["cwd"],
                            cases.get_path("custom_envs/simple-web-scraper"))
    del r["target"]
    del r["cwd"]

    assert r == {
        "type": "robotframework-lsp",
        "name": "Launch Name",
        "request": "launch",
        "args": ["-d", "output", "--logtitle", "Task log"],
        "terminal": "none",
    }
Example #3
0
def test_customize_interpreter_add_plugins_dir(
        language_server_io: ILanguageServerClient, workspace_dir: str,
        cases: CasesFixture):
    from robocorp_ls_core import uris
    import os
    from pathlib import Path
    from robotframework_ls.impl.robot_workspace import RobotDocument

    language_server = language_server_io

    cases.copy_to("custom_env", workspace_dir)

    language_server.initialize(workspace_dir, process_id=os.getpid())
    case1_robot: Path = Path(workspace_dir) / "env1" / "caselib1.robot"
    assert case1_robot.exists()
    uri_case1 = uris.from_fs_path(str(case1_robot))

    doc = RobotDocument(uri_case1)
    i_line = doc.find_line_with_contents("    verify lib1")

    language_server.open_doc(uri_case1, 1)

    ret = language_server.find_definitions(uri_case1, i_line, 6)
    result = ret["result"]
    assert not result

    # Now, customize it with the plugins.
    plugins_dir = cases.get_path("custom_env/plugins")

    add_plugins_result = language_server.execute_command(
        "robot.addPluginsDir", [plugins_dir])
    assert add_plugins_result["result"]

    ret = language_server.find_definitions(uri_case1, i_line, 6)
    result = ret["result"]
    assert result
    check = next(iter(result))
    assert check["uri"].endswith("lib1.py")

    # Check with another case
    case2_robot: Path = Path(workspace_dir) / "env2" / "caselib2.robot"
    assert case2_robot.exists()
    uri_case2 = uris.from_fs_path(str(case2_robot))
    doc = RobotDocument(uri_case2)
    i_line = doc.find_line_with_contents("    verify lib2")
    ret = language_server.find_definitions(uri_case2, i_line, 6)
    result = ret["result"]
    assert result
    check = next(iter(result))
    assert check["uri"].endswith("lib2.py")
Example #4
0
def cases(tmpdir_factory) -> CasesFixture:
    basename = "res áéíóú"
    copy_to = str(tmpdir_factory.mktemp(basename))

    f = __file__
    original_resources_dir = os.path.join(os.path.dirname(f), "_resources")
    assert os.path.exists(original_resources_dir)

    return CasesFixture(copy_to, original_resources_dir)
Example #5
0
def test_resolve_interpreter(
    cases: CasesFixture, config_provider: IConfigProvider, rcc_conda_installed
) -> None:
    from robocorp_ls_core.constants import NULL
    from robocorp_code.plugins.resolve_interpreter import RobocorpResolveInterpreter
    from robocorp_ls_core import uris
    from robocorp_ls_core.pluginmanager import PluginManager
    from pathlib import Path
    from robocorp_code.plugins.resolve_interpreter import _CacheInfo
    from robocorp_ls_core.ep_providers import EPConfigurationProvider
    from robocorp_ls_core.ep_providers import EPEndPointProvider

    _CacheInfo._cache_hit_files = 0

    pm = PluginManager()
    pm.set_instance(EPConfigurationProvider, config_provider)
    pm.set_instance(EPEndPointProvider, NULL)

    resolve_interpreter = RobocorpResolveInterpreter(weak_pm=weakref.ref(pm))
    path = cases.get_path(
        "custom_envs/simple-web-scraper/tasks/simple-web-scraper.robot"
    )
    interpreter_info = resolve_interpreter.get_interpreter_info_for_doc_uri(
        uris.from_fs_path(path)
    )
    assert interpreter_info
    assert os.path.exists(interpreter_info.get_python_exe())
    environ = interpreter_info.get_environ()
    assert environ
    assert environ["RPA_SECRET_MANAGER"] == "RPA.Robocloud.Secrets.FileSecrets"
    assert environ["RPA_SECRET_FILE"] == "/Users/<your-username-here>/vault.json"
    additional_pythonpath_entries = interpreter_info.get_additional_pythonpath_entries()
    assert len(additional_pythonpath_entries) == 3
    found = set()
    for v in additional_pythonpath_entries:
        p = Path(v)
        assert p.is_dir()
        found.add(p.name)

    assert found == {"variables", "libraries", "resources"}

    assert _CacheInfo._cache_hit_files == 0
    assert _CacheInfo._cache_hit_interpreter == 0
    interpreter_info = resolve_interpreter.get_interpreter_info_for_doc_uri(
        uris.from_fs_path(path)
    )
    assert _CacheInfo._cache_hit_files == 3
    assert _CacheInfo._cache_hit_interpreter == 1
def _generate_new_libspec(libspec_manager: LibspecManager,
                          cases: CasesFixture):
    filename = cases.get_path("case_argspec/case_argspec.py")
    libspec_manager._create_libspec(filename)