forked from robotframework/PythonLibCore
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_keyword_builder.py
91 lines (57 loc) · 2.8 KB
/
test_keyword_builder.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import typing
import pytest
from DynamicTypesAnnotationsLibrary import DynamicTypesAnnotationsLibrary
from moc_library import MockLibrary
from robotlibcore import KeywordBuilder
@pytest.fixture
def lib():
return MockLibrary()
@pytest.fixture
def dyn_types():
return DynamicTypesAnnotationsLibrary(1)
def test_documentation(lib):
spec = KeywordBuilder.build(lib.positional_args, {})
assert spec.documentation == "Some documentation\n\nMulti line docs"
spec = KeywordBuilder.build(lib.positional_and_default, {})
assert spec.documentation == ""
def test_no_args(lib):
spec = KeywordBuilder.build(lib.no_args, {})
assert spec.argument_specification == []
def test_positional_args(lib):
spec = KeywordBuilder.build(lib.positional_args, {})
assert spec.argument_specification == ["arg1", "arg2"]
def test_positional_and_named(lib):
spec = KeywordBuilder.build(lib.positional_and_default, {})
assert spec.argument_specification == ["arg1", "arg2", ("named1", "string1"), ("named2", 123)]
def test_named_only_default_only(lib):
spec = KeywordBuilder.build(lib.default_only, {})
assert spec.argument_specification == [("named1", "string1"), ("named2", 123)]
def test_varargs_and_kwargs(lib):
spec = KeywordBuilder.build(lib.varargs_kwargs, {})
assert spec.argument_specification == ["*vargs", "**kwargs"]
def test_named_only_part2(lib):
spec = KeywordBuilder.build(lib.named_only, {})
assert spec.argument_specification == ["*varargs", "key1", "key2"]
def test_named_only(lib):
spec = KeywordBuilder.build(lib.named_only_with_defaults, {})
assert spec.argument_specification == ["*varargs", "key1", "key2", ("key3", "default1"), ("key4", True)]
def test_types_in_keyword_deco(lib):
spec = KeywordBuilder.build(lib.positional_args, {})
assert spec.argument_types == {"arg1": str, "arg2": int}
def test_types_disabled_in_keyword_deco(lib):
spec = KeywordBuilder.build(lib.types_disabled, {})
assert spec.argument_types is None
def test_types_(lib):
spec = KeywordBuilder.build(lib.args_with_type_hints, {})
assert spec.argument_types == {"arg3": str, "arg4": type(None), "return": bool}
def test_types(lib):
spec = KeywordBuilder.build(lib.self_and_keyword_only_types)
assert spec.argument_types == {"varargs": int, "other": bool, "kwargs": int}
def test_optional_none(lib):
spec = KeywordBuilder.build(lib.optional_none)
assert spec.argument_types == {"arg1": typing.Union[str, None], "arg2": typing.Union[str, None]}
def test_complex_deco(dyn_types):
spec = KeywordBuilder.build(dyn_types.keyword_with_deco_and_signature)
assert spec.argument_types == {"arg1": bool, "arg2": bool}
assert spec.argument_specification == [("arg1", False), ("arg2", False)]
assert spec.documentation == "Test me doc here"