Skip to content

Commit a971dcf

Browse files
committed
add tests for hover and goto for variable imports
1 parent 8c49df5 commit a971dcf

File tree

6 files changed

+21
-12
lines changed

6 files changed

+21
-12
lines changed

.vscode/launch.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,17 @@
195195
"${workspaceFolder}/out/test/**/*.js"
196196
],
197197
"preLaunchTask": "npm: compile"
198+
},
199+
{
200+
"name": "Python: Debug Tests",
201+
"type": "python",
202+
"request": "launch",
203+
"program": "${file}",
204+
"purpose": [
205+
"debug-test"
206+
],
207+
"console": "integratedTerminal",
208+
"justMyCode": false
198209
}
199210
],
200211
"inputs": [

robotcode/language_server/robotframework/diagnostics/library_doc.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1221,6 +1221,7 @@ def get_variables_doc(
12211221
from robot.variables.filesetter import PythonImporter, YamlImporter
12221222

12231223
source: Optional[str] = None
1224+
stem = Path(name).stem
12241225
try:
12251226
source = find_file(name, working_dir, base_dir, pythonpath, environment, variables)
12261227

@@ -1234,13 +1235,13 @@ def get_variables_doc(
12341235
]
12351236

12361237
return VariablesDoc(
1237-
name,
1238+
name=stem,
12381239
source=source,
12391240
variables=vars,
12401241
)
12411242
except BaseException as e:
12421243
return VariablesDoc(
1243-
name=name,
1244+
name=stem,
12441245
source=source,
12451246
errors=[
12461247
error_from_exception(

robotcode/language_server/robotframework/parts/hover.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ async def hover_VariablesImport( # noqa: N802
318318

319319
try:
320320
libdoc = await namespace.get_imported_variables_libdoc(variables_node.name, variables_node.args)
321-
321+
322322
if libdoc is None or libdoc.errors:
323323
libdoc = await namespace.imports_manager.get_libdoc_for_variables_import(
324324
str(variables_node.name), (), str(document.uri.to_path().parent)

tests/robotcode/language_server/robotframework/parts/data/goto.robot

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Library Collections
55
Library ${CURDIR}/libs/myvariables.py
66
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Library Import by Path: len(result) == 1 and result[0].target_uri.endswith("/libs/myvariables.py")
77
Variables ${CURDIR}/libs/myvariables.py
8-
# TODO ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Variables Import: len(result) == 1 and result[0].target_uri.endswith("libs/myvariables.py")
8+
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Variables Import: len(result) == 1 and result[0].target_uri.endswith("libs/myvariables.py")
99
Resource ${CURDIR}/resources/firstresource.resource
1010
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Resource Import: len(result) == 1 and result[0].target_uri.endswith("/resources/firstresource.resource")
1111

@@ -26,9 +26,5 @@ first
2626
# ^^^^^^ For Variable: len(result) == 1 and result[0].target_uri.endswith("/data/goto.robot")
2727
# ^^^^^^^^ For Variable: len(result) == 1 and result[0].target_uri.endswith("/data/goto.robot")
2828
END
29-
Log ${CMD_VAR}
30-
# TODO ^^^^^^^^^^ Command Line Variable: len(result) == 1 and result[0].target_uri.endswith("...")
31-
Log ${CURDIR}
32-
# TODO ^^^^^^^^^ BuiltIn Variable: len(result) == 1 and result[0].target_uri.endswith("...")
3329
Log ${A_VAR_FROM_LIB}
34-
# TODO ^^^^^^^^^^^^^^^^^ Imported Variable: len(result) == 1 and result[0].target_uri.endswith("...")
30+
# ^^^^^^^^^^^^^^^^^ Imported Variable: len(result) == 1 and result[0].target_uri.endswith("libs/myvariables.py")

tests/robotcode/language_server/robotframework/parts/data/hover.robot

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ Library ${CURDIR}/libs/myvariables.py
66
# TODO ^^^^^^^^^ variable in library import: value == '(builtin variable) ${CURDIR}'
77
Variables ${CURDIR}/libs/myvariables.py
88
# TODO ^^^^^^^^^ variable in variables import: value == '(builtin variable) ${CURDIR}'
9+
# ^^^^^^^^^^^^^^ variable import by path name: re.match(r'## Variables \*myvariables.*', value)
910
Resource ${CURDIR}/resources/firstresource.resource
10-
# ^^^^^^^^^^^^^^ library import by path name: re.match(r'## Resource \*firstresource.*', value)
11+
# ^^^^^^^^^^^^^^ resource import by path name: re.match(r'## Resource \*firstresource.*', value)
1112
# TODO ^^^^^^^^^ variable in resource import: value == '(builtin variable) ${CURDIR}'
1213

1314
*** Variables ***
@@ -34,7 +35,7 @@ first
3435
# ^^^^^^^^^ BuiltIn variable: value == '(builtin variable) ${CURDIR}'
3536
#^^^ Spaces: result is None
3637
Log ${A_VAR_FROM_LIB}
37-
# TODO ^^^^^^^^^^^^^^^^^ variable from lib: value == '(imported variable) ${A_VAR_FROM_LIB}'
38+
# ^^^^^^^^^^^^^^^^^ variable from lib: value == '(imported variable) ${A_VAR_FROM_LIB}'
3839

3940

4041
*** Keywords ***

tests/robotcode/language_server/robotframework/tools.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def generate_tests_from_source_document(
5454

5555
def generate_test_id(params: Any) -> Any:
5656
if isinstance(params, GeneratedTestData):
57-
return f"{params.line}-{params.character}-{params.name}"
57+
return f"{params.line:03}-{params.character:03}-{params.name}"
5858
if dataclasses.is_dataclass(params):
5959
return repr(params)
6060
if isinstance(params, Path):

0 commit comments

Comments
 (0)