Skip to content

Commit 1ceb18a

Browse files
committed
Fix bug in creating arguments spec
1 parent 7d74880 commit 1ceb18a

File tree

5 files changed

+42
-9
lines changed

5 files changed

+42
-9
lines changed

atest/DynamicTypesAnnotationsLibrary.py

+1
Original file line numberDiff line numberDiff line change
@@ -146,4 +146,5 @@ def enum_conversion(self, param: Optional[penum] = None):
146146
@keyword
147147
@_my_deco(old_args=("arg1", ), new_args=("arg2", ))
148148
def keyword_with_deco_and_signature(self, arg1: bool = False, arg2: bool = False):
149+
"""Test me doc here"""
149150
return f"{arg1}: {type(arg1)}, {arg2}: {type(arg2)}"

src/robotlibcore.py

+9-3
Original file line numberDiff line numberDiff line change
@@ -164,17 +164,22 @@ class KeywordBuilder(object):
164164

165165
@classmethod
166166
def build(cls, function):
167-
if not PY2:
168-
function = inspect.unwrap(function)
169167
return KeywordSpecification(
170168
argument_specification=cls._get_arguments(function),
171169
documentation=inspect.getdoc(function) or '',
172170
argument_types=cls._get_types(function)
173171
)
174172

173+
@classmethod
174+
def unwrap(cls, function):
175+
if PY2:
176+
return function
177+
return inspect.unwrap(function)
178+
175179
@classmethod
176180
def _get_arguments(cls, function):
177-
arg_spec = cls._get_arg_spec(function)
181+
unwrap_function = cls.unwrap(function)
182+
arg_spec = cls._get_arg_spec(unwrap_function)
178183
argument_specification = cls._get_default_and_named_args(
179184
arg_spec, function
180185
)
@@ -255,6 +260,7 @@ def _get_types(cls, function):
255260
def _get_typing_hints(cls, function):
256261
if PY2:
257262
return {}
263+
function = cls.unwrap(function)
258264
try:
259265
hints = typing.get_type_hints(function)
260266
except Exception:

utest/run.py

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
'-p', 'no:cacheprovider',
2626
'--junitxml=%s' % xunit_report,
2727
'-o', 'junit_family=xunit2',
28+
'--showlocals',
2829
curdir
2930
]
3031
if args.cov:

utest/test_keyword_builder.py

+24-1
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
from robotlibcore import PY2, RF31, KeywordBuilder
44
from moc_library import MockLibrary
55
if not PY2:
6-
from typing import Union
76
from moc_library_py3 import MockLibraryPy3
7+
from DynamicTypesAnnotationsLibrary import DynamicTypesAnnotationsLibrary
88

99

1010
@pytest.fixture
@@ -17,6 +17,11 @@ def lib_py3():
1717
return MockLibraryPy3()
1818

1919

20+
@pytest.fixture
21+
def dyn_types():
22+
return DynamicTypesAnnotationsLibrary(1)
23+
24+
2025
def test_documentation(lib):
2126
spec = KeywordBuilder.build(lib.positional_args)
2227
assert spec.documentation == 'Some documentation\n\nMulti line docs'
@@ -109,3 +114,21 @@ def test_types(lib_py3):
109114
def test_optional_none(lib_py3):
110115
spec = KeywordBuilder.build(lib_py3.optional_none)
111116
assert spec.argument_types == {'arg1': str, 'arg2': str}
117+
118+
119+
@pytest.mark.skipif(PY2, reason='Only for Python 3')
120+
@pytest.mark.skipif(RF31, reason='For RF 3.2')
121+
def test_complex_deco_rf32(dyn_types):
122+
spec = KeywordBuilder.build(dyn_types.keyword_with_deco_and_signature)
123+
assert spec.argument_types == {'arg1': bool, 'arg2': bool}
124+
assert spec.argument_specification == [('arg1', False), ('arg2', False)]
125+
assert spec.documentation == "Test me doc here"
126+
127+
128+
@pytest.mark.skipif(PY2, reason='Only for Python 3')
129+
@pytest.mark.skipif(not RF31, reason='For RF 3.2')
130+
def test_complex_deco_rf31(dyn_types):
131+
spec = KeywordBuilder.build(dyn_types.keyword_with_deco_and_signature)
132+
assert spec.argument_types == {'arg1': bool, 'arg2': bool}
133+
assert spec.argument_specification == ['arg1=False', 'arg2=False']
134+
assert spec.documentation == "Test me doc here"

utest/test_robotlibcore.py

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import sys
22

33
import pytest
4-
from robot import __version__ as robot__version
4+
from robot import __version__ as robot_version
55

66
from robotlibcore import HybridCore, PY2
77
from HybridLibrary import HybridLibrary
@@ -99,7 +99,7 @@ def test_getattr():
9999
"'%s' object has no attribute 'non_existing'" % type(lib).__name__
100100

101101

102-
@pytest.mark.skipif(robot__version >= '3.2', reason='For RF 3.1')
102+
@pytest.mark.skipif(robot_version >= '3.2', reason='For RF 3.1')
103103
def test_get_keyword_arguments_rf31():
104104
args = DynamicLibrary().get_keyword_arguments
105105
assert args('mandatory') == ['arg1', 'arg2']
@@ -112,7 +112,7 @@ def test_get_keyword_arguments_rf31():
112112
args('__foobar__')
113113

114114

115-
@pytest.mark.skipif(robot__version < '3.2', reason='For RF 3.2 or greater')
115+
@pytest.mark.skipif(robot_version < '3.2', reason='For RF 3.2 or greater')
116116
def test_get_keyword_arguments_rf32():
117117
args = DynamicLibrary().get_keyword_arguments
118118
assert args('mandatory') == ['arg1', 'arg2']
@@ -126,7 +126,7 @@ def test_get_keyword_arguments_rf32():
126126

127127

128128
@pytest.mark.skipif(PY2, reason='Only for Python 3')
129-
@pytest.mark.skipif(robot__version < '3.2', reason='For RF 3.2 or greater')
129+
@pytest.mark.skipif(robot_version < '3.2', reason='For RF 3.2 or greater')
130130
def test_keyword_only_arguments_for_get_keyword_arguments_rf32():
131131
args = DynamicTypesAnnotationsLibrary(1).get_keyword_arguments
132132
assert args('keyword_only_arguments') == ['*varargs', ('some', 111)]
@@ -135,10 +135,11 @@ def test_keyword_only_arguments_for_get_keyword_arguments_rf32():
135135
assert args('keyword_only_arguments_default_and_no_default') == ['*varargs', 'other', ('value', False)]
136136
all_args = ['mandatory', ('positional', 1), '*varargs', 'other', ('value', False), '**kwargs']
137137
assert args('keyword_all_args') == all_args
138+
assert args('keyword_with_deco_and_signature') == [('arg1', False), ('arg2', False)]
138139

139140

140141
@pytest.mark.skipif(PY2, reason='Only for Python 3')
141-
@pytest.mark.skipif(robot__version >= '3.2', reason='For RF 3.1')
142+
@pytest.mark.skipif(robot_version >= '3.2', reason='For RF 3.1')
142143
def test_keyword_only_arguments_for_get_keyword_arguments_rf31():
143144
args = DynamicTypesAnnotationsLibrary(1).get_keyword_arguments
144145
assert args('keyword_only_arguments') == ['*varargs', 'some=111']
@@ -147,6 +148,7 @@ def test_keyword_only_arguments_for_get_keyword_arguments_rf31():
147148
assert args('keyword_only_arguments_default_and_no_default') == ['*varargs', 'other', 'value=False']
148149
all_args = ['mandatory', 'positional=1', '*varargs', 'other', 'value=False', '**kwargs']
149150
assert args('keyword_all_args') == all_args
151+
assert args('keyword_with_deco_and_signature') == ['arg1=False', 'arg2=False']
150152

151153

152154
def test_get_keyword_documentation():

0 commit comments

Comments
 (0)