Skip to content

Commit d8102c8

Browse files
committed
rework language server tests to use pytest-regressions, add some more tests
1 parent cefdfb1 commit d8102c8

File tree

217 files changed

+5806
-133
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

217 files changed

+5806
-133
lines changed

poetry.lock

Lines changed: 39 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ robotframework-tidy = "^1.5.1"
5959
PyYAML = "^6.0"
6060
types-PyYAML = "^6.0"
6161
snakeviz = "^2.1.1"
62+
pytest-regressions = "^2.3.1"
6263

6364

6465
[tool.poetry-dynamic-versioning]
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
*** Settings ***
2+
Library Collections
3+
Library ${CURDIR}/libs/myvariables.py
4+
Variables ${CURDIR}/libs/myvariables.py
5+
Resource ${CURDIR}/resources/firstresource.resource
6+
7+
*** Variables ***
8+
${a var} hello
9+
10+
*** Test Cases ***
11+
first
12+
[Setup] Log To Console hi ${a var}
13+
[Teardown] BuiltIn.Log To Console hi ${a var}
14+
15+
Log Hi ${a var}
16+
# ^^^ simple keyword call
17+
Log To Console hi ${a var}
18+
# ^^^^^^^^^^^^^^ multiple references
19+
BuiltIn.Log To Console hi ${a var}
20+
# ^^^^^^^^^^^^^^ multiple references with namespace
21+
# ^^^^^ multiple variables
Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,46 @@
11
*** Settings ***
2-
#^ Settings Start: any(e for e in result if e.start_line == line and (e.start_character is None or e.start_character==0) and e.kind=='section')
2+
#^ Settings Start
33
Documentation Hallo Welt
44
... was geht
55
66
*** Test Cases ***
7-
#^ Settings End: any(e for e in result if e.end_line == line - 1 and (e.end_character is None or e.end_character>0) and e.kind=='section')
8-
#^ Test Cases Start: any(e for e in result if e.start_line == line and e.kind=='section')
7+
#^ Settings End
8+
#^ Test Cases Start
99
First
10-
#^ Testcase Start: any(e for e in result if e.start_line == line and e.kind=='testcase')
10+
#^ Testcase Start
1111
Log Hello from testcase
1212
a keyword
1313
FOR ${i} IN 1 2 3
14-
#^ For Start: any(e for e in result if e.start_line == line and e.kind=='for')
14+
#^ For Start
1515
IF ${i}==1
16-
#^ If Start: any(e for e in result if e.start_line == line and e.kind=='if')
16+
#^ If Start
1717
Log "one"
1818
ELSE IF ${i}==2
19-
#^ If Start: any(e for e in result if e.start_line == line and e.kind=='if')
19+
#^ If Start
2020
Log "two"
2121
ELSE
22-
#^ If Start: any(e for e in result if e.start_line == line and e.kind=='if')
22+
#^ If Start
2323
Log "more then two"
2424
END
25-
#^ If End: any(e for e in result if e.end_line == line and e.kind=='if')
25+
#^ If End
2626

2727
Log ${i}
2828

2929
END
30-
#^ For End: any(e for e in result if e.end_line == line and e.kind=='for')
30+
#^ For End
3131

3232
*** Keywords ***
33-
#^ Test Cases End: any(e for e in result if e.end_line == line - 1 and e.kind=='section')
34-
#^ Testcase End: any(e for e in result if e.end_line == line - 1 and e.kind=='testcase')
33+
#^ Test Cases End
34+
#^ Testcase End
3535
a keyword
36-
#^ Keyword Start: any(e for e in result if e.start_line == line and e.kind=='keyword')
36+
#^ Keyword Start
3737
Log Hello from keyword
3838

3939
*** Comments ***
40-
#^ Keyword End: any(e for e in result if e.end_line == line - 1 and e.kind=='keyword')
41-
#^ Comment Start: any(e for e in result if e.start_line == line and e.kind=='comment')
40+
#^ Keyword End
41+
#^ Comment Start
4242
this is a long long
4343
long long long
4444
long long comment section
4545

46-
#^ Comment End: any(e for e in result if e.end_line == line + 1 and e.kind=='comment')
46+
#^ Comment End
Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
*** Settings ***
22
Library Collections
3-
# ^^^^^^^^^^^ Robot Library Import: len(result) == 1 and result[0].target_uri.endswith("robot/libraries/Collections.py")
4-
# ^^^^^^^^^^^ Separator: result is None or len(result) == 0
3+
# ^^^^^^^^^^^ Robot Library Import
4+
# ^^^^^^^^^^^ Separator
55
Library ${CURDIR}/libs/myvariables.py
6-
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Library Import by Path: len(result) == 1 and result[0].target_uri.endswith("/libs/myvariables.py")
6+
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Library Import by Path
77
Variables ${CURDIR}/libs/myvariables.py
8-
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Variables Import: len(result) == 1 and result[0].target_uri.endswith("libs/myvariables.py")
8+
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Variables Import
99
Resource ${CURDIR}/resources/firstresource.resource
10-
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Resource Import: len(result) == 1 and result[0].target_uri.endswith("/resources/firstresource.resource")
10+
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Resource Import
1111

1212
*** Variables ***
1313
${A VAR} i'm a var
@@ -16,29 +16,29 @@ ${A VAR} i'm a var
1616
*** Test Cases ***
1717
first
1818
Log Hello ${A VAR}
19-
# ^^^^^^^ Variable: len(result) == 1 and result[0].target_uri.endswith("/data/goto.robot")
20-
# ^^^ BuiltIn Keyword: len(result) == 1 and result[0].target_uri.endswith("robot/libraries/BuiltIn.py")
19+
# ^^^^^^^ Variable
20+
# ^^^ BuiltIn Keyword
2121

2222
Collections.Log Dictionary ${A DICT}
23-
# ^^^^^^^^^ Variable: len(result) == 1 and result[0].target_uri.endswith("/data/goto.robot")
24-
# ^^^^^^^^^^^^^^ Robot Library Keyword: len(result) == 1 and result[0].target_uri.endswith("robot/libraries/Collections.py")
25-
# ^^^^^^^^^^^ Robot Namespace from Library: len(result) == 1 and result[0].target_uri.endswith("data/goto.robot")
23+
# ^^^^^^^^^ Variable
24+
# ^^^^^^^^^^^^^^ Robot Library Keyword
25+
# ^^^^^^^^^^^ Robot Namespace from Library
2626

2727
BuiltIn.Log Hello ${A VAR}
28-
# ^^^ BuiltIn Keyword with Namespace: len(result) == 1 and result[0].target_uri.endswith("robot/libraries/BuiltIn.py")
29-
# ^^^^^^^ Robot BuilIn Namespace: len(result) == 1 and result[0].target_uri.endswith("robot/libraries/BuiltIn.py")
28+
# ^^^ BuiltIn Keyword with Namespace
29+
# ^^^^^^^ Robot BuilIn Namespace
3030

3131
FOR ${key} ${value} IN &{A DICT}
3232
Log ${key}=${value}
33-
# ^^^^^^ For Variable: len(result) == 1 and result[0].target_uri.endswith("/data/goto.robot")
34-
# ^^^^^^^^ For Variable: len(result) == 1 and result[0].target_uri.endswith("/data/goto.robot")
33+
# ^^^^^^ For Variable
34+
# ^^^^^^^^ For Variable
3535
END
3636
Log ${A_VAR_FROM_LIB}
37-
# ^^^^^^^^^^^^^^^^^ Imported Variable: len(result) == 1 and result[0].target_uri.endswith("libs/myvariables.py")
37+
# ^^^^^^^^^^^^^^^^^ Imported Variable
3838

3939
do something in a resource
40-
# ^^^^^^^^^^^^^^^^^^^^^^^^^^ Keyword from resource: len(result) == 1 and result[0].target_uri.endswith("/data/resources/firstresource.resource")
40+
# ^^^^^^^^^^^^^^^^^^^^^^^^^^ Keyword from resource
4141

4242
firstresource.do something in a resource
43-
# ^^^^^^^^^^^^^^^^^^^^^^^^^^ Keyword from resource: len(result) == 1 and result[0].target_uri.endswith("/data/resources/firstresource.resource")
44-
# ^^^^^^^^^^^^^ Namespace from resource: len(result) == 1 and result[0].target_uri.endswith("/data/goto.robot")
43+
# ^^^^^^^^^^^^^^^^^^^^^^^^^^ Keyword from resource
44+
# ^^^^^^^^^^^^^ Namespace from resource
Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,79 +1,79 @@
11
*** Settings ***
22
Library Collections
3-
# ^^^^^^^^^^^ library import by module name: re.match(r'## Library \*Collections\*.*', value)
3+
# ^^^^^^^^^^^ library import by module name
44
Library ${CURDIR}/libs/myvariables.py
5-
# ^^^^^^^^^^^^^^ library import by path name: re.match(r'## Library \*myvariables.*', value)
6-
# ^^^^^^^^^ variable in library import: value == '(builtin variable) ${CURDIR}'
5+
# ^^^^^^^^^^^^^^ library import by path name
6+
# ^^^^^^^^^ variable in library import
77
Variables ${CURDIR}/libs/myvariables.py
8-
# ^^^^^^^^^ variable in variables import: value == '(builtin variable) ${CURDIR}'
9-
# ^^^^^^^^^^^^^^ variable import by path name: re.match(r'## Variables \*myvariables.*', value)
8+
# ^^^^^^^^^ variable in variables import
9+
# ^^^^^^^^^^^^^^ variable import by path name
1010
Resource ${CURDIR}/resources/firstresource.resource
11-
# ^^^^^^^^^^^^^^ resource import by path name: re.match(r'## Resource \*firstresource.*', value)
12-
# ^^^^^^^^^ variable in resource import: value == '(builtin variable) ${CURDIR}'
11+
# ^^^^^^^^^^^^^^ resource import by path name
12+
# ^^^^^^^^^ variable in resource import
1313

1414
*** Variables ***
1515
${A VAR} i'm a var
16-
#^^^^^^^ variable declaration: value == '(variable) ${A VAR}'
16+
#^^^^^^^ variable declaration
1717
&{A DICT} a=1 b=2 c=3
18-
#^^^^^^^ variable declaration: value == '(variable) &{A DICT}'
18+
#^^^^^^^ variable declaration
1919

2020
*** Test Cases ***
2121
first
2222
[Setup] Log Hello ${A VAR}
23-
# ^^^ Keyword in Setup: re.match(r'.*Log.*', value)
23+
# ^^^ Keyword in Setup
2424
[Teardown] Log Hello ${A VAR}
25-
# ^^^ Keyword in Teardown: re.match(r'.*Log.*', value)
25+
# ^^^ Keyword in Teardown
2626

2727
Log Hello ${A VAR}
28-
# ^^^ Keyword from Library: re.match(r'.*Log.*', value)
28+
# ^^^ Keyword from Library
2929

3030
Collections.Log Dictionary ${A DICT}
31-
# ^^^^^^^^^^^^^^ Keyword with namespace: re.match(r'.*Log Dictionary.*', value)
32-
# ^^^^^^^^^^^ namespace before keyword: re.match(r'.*Collections.*', value)
31+
# ^^^^^^^^^^^^^^ Keyword with namespace
32+
# ^^^^^^^^^^^ namespace before keyword
3333
FOR ${key} ${value} IN &{A DICT}
34-
# ^^^^^^ FOR loop variable declaration: value == '(local variable) ${key}'
34+
# ^^^^^^ FOR loop variable declaration
3535
Log ${key}=${value}
36-
# ^^^ Keyword in FOR loop: re.match(r'.*Log.*', value)
36+
# ^^^ Keyword in FOR loop
3737
END
3838
Log ${CMD_VAR}
39-
# ^^^^^^^^^^ BuiltIn variable: value == '(command line variable) ${CMD_VAR}'
40-
# ^^^ BuiltIn Keyword: re.match(r'.*Log.*', value)
39+
# ^^^^^^^^^^ BuiltIn variable
40+
# ^^^ BuiltIn Keyword
4141
Log ${CURDIR}
42-
# ^^^^^^^^^ BuiltIn variable: value == '(builtin variable) ${CURDIR}'
43-
#^^^ Spaces: result is None
42+
# ^^^^^^^^^ BuiltIn variable
43+
#^^^ Spaces
4444
Log ${A_VAR_FROM_LIB}
45-
# ^^^^^^^^^^^^^^^^^ variable from lib: value == '(imported variable) ${A_VAR_FROM_LIB}'
45+
# ^^^^^^^^^^^^^^^^^ variable from lib
4646

4747
do something in a resource
48-
# ^^^^^^^^^^^^^^^^^^^^^^^^^^ Keyword from resource: re.match(r'.*do something in a resource.*', value)
48+
# ^^^^^^^^^^^^^^^^^^^^^^^^^^ Keyword from resource
4949

5050
firstresource.do something in a resource
51-
# ^^^^^^^^^^^^^^^^^^^^^^^^^^ KeywordCall from resource with Namespace: re.match(r'.*do something in a resource.*', value)
52-
# ^^^^^^^^^^^^^ Namespace from resource: re.match(r'## Resource \*firstresource.*', value)
51+
# ^^^^^^^^^^^^^^^^^^^^^^^^^^ KeywordCall from resource with Namespace
52+
# ^^^^^^^^^^^^^ Namespace from resource
5353

5454

5555
*** Keywords ***
5656
a keyword
5757
Run Keyword log hi
58-
# ^^^^^^^^^^^ run keyword: re.match(r'.*Run Keyword.*', value)
59-
# ^^^ run keyword argument: re.match(r'.*Log.*', value)
58+
# ^^^^^^^^^^^ run keyword
59+
# ^^^ run keyword argument
6060

6161
Run Keywords a simple keyword s l e e p a w h i le
62-
# ^^^^^^^^^^^^ run keywords: re.match(r'.*Run Keywords.*', value)
63-
# ^^^^^^^^^^^^^^^^ run keywords simple keyword: re.match(r'.*a simple keyword.*', value)
64-
# ^^^^^^^^^^^^^^^^^^^^ run keywords second parameter with spaces: re.match(r'.*sleep a while.*', value)
62+
# ^^^^^^^^^^^^ run keywords
63+
# ^^^^^^^^^^^^^^^^ run keywords simple keyword
64+
# ^^^^^^^^^^^^^^^^^^^^ run keywords second parameter with spaces
6565

6666
Run Keywords log hi AND a simple keyword AND s l e e p a w h i le
67-
# ^^^^^^^^^^^^ run keywords: re.match(r'.*Run Keywords.*', value)
68-
# ^^^ run keywords simple keyword, parameter and AND: re.match(r'.*Log.*', value)
69-
# ^^^^^^^^^^^^^^^^ run keywords simple keyword and AND: re.match(r'.*a simple keyword.*', value)
70-
# ^^^^^^^^^^^^^^^^^^^^ run keywords second parameter with spaces and no AND: re.match(r'.*sleep a while.*', value)
71-
# ^^^ AND: result is None
67+
# ^^^^^^^^^^^^ run keywords
68+
# ^^^ run keywords simple keyword, parameter and AND
69+
# ^^^^^^^^^^^^^^^^ run keywords simple keyword and AND
70+
# ^^^^^^^^^^^^^^^^^^^^ run keywords second parameter with spaces and no AND
71+
# ^^^ AND
7272

7373
a simple keyword
74-
#^^^^^^^^^^^^^^^ simple keyword with extra spaces and parameter: re.match(r'.*a simple keyword.*', value)
74+
#^^^^^^^^^^^^^^^ simple keyword with extra spaces and parameter
7575
Pass Execution
7676

7777
sleep a while
7878
S l e e p 1s
79-
# ^^^^^^^^^ simple keyword with extra spaces and parameter: re.match(r'.*Sleep.*', value)
79+
# ^^^^^^^^^ simple keyword with extra spaces and parameter
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
from pathlib import Path
2+
3+
import pytest
4+
from pytest_regressions.data_regression import DataRegressionFixture
5+
6+
from robotcode.language_server.common.lsp_types import Position
7+
from robotcode.language_server.common.text_document import TextDocument
8+
from robotcode.language_server.robotframework.protocol import (
9+
RobotLanguageServerProtocol,
10+
)
11+
12+
from ..tools import (
13+
GeneratedTestData,
14+
generate_test_id,
15+
generate_tests_from_source_document,
16+
)
17+
18+
19+
@pytest.mark.parametrize(
20+
("test_document", "data"),
21+
generate_tests_from_source_document(Path(Path(__file__).parent, "data/document_highlight.robot")),
22+
indirect=["test_document"],
23+
ids=generate_test_id,
24+
)
25+
@pytest.mark.usefixtures("protocol")
26+
@pytest.mark.asyncio
27+
async def test(
28+
data_regression: DataRegressionFixture,
29+
protocol: RobotLanguageServerProtocol,
30+
test_document: TextDocument,
31+
data: GeneratedTestData,
32+
) -> None:
33+
result = await protocol.robot_document_highlight.collect(
34+
protocol.robot_document_highlight, test_document, Position(line=data.line, character=data.character)
35+
)
36+
data_regression.check({"data": data, "result": result})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
data: !GeneratedTestData
2+
character: 4
3+
line: 14
4+
name: simple keyword call
5+
result:
6+
- !DocumentHighlight
7+
kind: !DocumentHighlightKind 'TEXT'
8+
range:
9+
end:
10+
character: 7
11+
line: 14
12+
start:
13+
character: 4
14+
line: 14

0 commit comments

Comments
 (0)