Skip to content

Commit 99b4c8d

Browse files
committed
Fixed atests
1 parent dae82d0 commit 99b4c8d

5 files changed

Lines changed: 22 additions & 11 deletions

File tree

atest/DynamicTypesLibrary.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ def keyword_default_types(self, arg=None):
5353
def keyword_many_default_types(self, arg1=1, arg2='Foobar'):
5454
return arg1, arg2
5555

56+
@keyword
57+
def keyword_booleans(self, arg1=True, arg2=False):
58+
return '%s: %s, %s: %s' % (arg1, type(arg1), arg2, type(arg2))
59+
5660
@keyword
5761
def keyword_none(self, arg=None):
5862
return '%s: %s' % (arg, type(arg))

atest/tests_types.robot

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Keyword Default Argument As Abject None Default Value
1313

1414
Keyword Default Argument As String None
1515
${return} = DynamicTypesLibrary.Keyword None None
16-
Should Match Regexp ${return} None: <(class|type) 'NoneType'>
16+
Should Match Regexp ${return} None: <(class|type) '(unicode|str|NoneType)'>
1717

1818
Keyword Default As Booleans With Defaults
1919
${return} DynamicTypesLibrary.Keyword Booleans
@@ -35,23 +35,18 @@ Keyword Annonations And Bool Defaults Using Default
3535
Keyword Annonations And Bool Defaults Defining All Arguments
3636
[Tags] py3
3737
${return} = DynamicTypesAnnotationsLibrary.Keyword Default And Annotation 1 true
38-
Should Match Regexp ${return} 1: <(class|type) 'int'>, True: <(class|type) 'bool'>
38+
Should Match Regexp ${return} 1: <(class|type) 'int'>, true: <(class|type) 'str'>
3939

4040
Keyword Annonations And Bool Defaults Defining All Arguments And With Number
4141
[Tags] py3
4242
${return} = DynamicTypesAnnotationsLibrary.Keyword Default And Annotation ${1} true
43-
Should Match Regexp ${return} 1: <(class|type) 'int'>, True: <(class|type) 'bool'>
43+
Should Match Regexp ${return} 1: <(class|type) 'int'>, true: <(class|type) 'str'>
4444

4545
Keyword Annonations And Robot Types Disbales Argument Conversion
4646
[Tags] py3
4747
${return} = DynamicTypesAnnotationsLibrary.Keyword Robot Types Disabled And Annotations 111
4848
Should Match Regexp ${return} 111: <(class|type) 'str'>
4949

50-
Keyword Annonations And Robot Types Defined
51-
[Tags] py3
52-
${return} = DynamicTypesAnnotationsLibrary.Keyword Robot Types And Bool Defaults tidii 111
53-
Should Match Regexp ${return} tidii: <(class|type) 'str'>, 111: <(class|type) 'str'>
54-
5550
Keyword Annonations And Keyword Only Arguments
5651
[Tags] py3
5752
${return} = DynamicTypesAnnotationsLibrary.Keyword Only Arguments 1 ${1} some=222

src/robotlibcore.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ def get_keyword_types(self, keyword_name):
124124
return types
125125
if not types:
126126
types = self.__get_typing_hints(method)
127-
types.pop('return', None)
127+
types = self.__join_defaults_with_types(method, types)
128128
return types
129129

130130
def __get_keyword(self, keyword_name):
@@ -137,6 +137,16 @@ def __get_keyword(self, keyword_name):
137137
raise ValueError('Keyword "%s" not found.' % keyword_name)
138138
return method
139139

140+
def __join_defaults_with_types(self, method, types):
141+
spec = ArgumentSpec.from_function(method)
142+
for name, value in spec.defaults:
143+
if name not in types and isinstance(value, bool):
144+
types[name] = type(value)
145+
for name, value in spec.kwonlydefaults:
146+
if name not in types and isinstance(value, bool):
147+
types[name] = type(value)
148+
return types
149+
140150
def __get_typing_hints(self, method):
141151
if PY2:
142152
return {}

utest/test_get_keyword_types.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def test_types_disabled(lib):
3333

3434
def test_keyword_types_and_bool_default(lib):
3535
types = lib.get_keyword_types('keyword_robot_types_and_bool_default')
36-
assert types == {'arg1': str}
36+
assert types == {'arg1': str, 'arg2': bool}
3737

3838

3939
def test_one_keyword_type_defined(lib):
@@ -188,7 +188,7 @@ def test_keyword_only_arguments_many_positional_and_default(lib_types):
188188
@pytest.mark.skipif(PY2, reason='Only applicable on Python 3')
189189
def test_keyword_all_args(lib_types):
190190
types = lib_types.get_keyword_types('keyword_all_args')
191-
assert types == {}
191+
assert types == {'value': bool}
192192

193193

194194
@pytest.mark.skipif(PY2, reason='Only applicable on Python 3')

utest/test_robotlibcore.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ def test_dir():
4141
'_DynamicCore__get_keyword_line',
4242
'_DynamicCore__get_keyword_path',
4343
'_DynamicCore__get_typing_hints',
44+
'_DynamicCore__join_defaults_with_types',
4445
'_HybridCore__get_members',
4546
'_HybridCore__get_members_from_instance',
4647
'_custom_name',
@@ -75,6 +76,7 @@ def test_dir():
7576
'_DynamicCore__get_keyword',
7677
'_DynamicCore__get_keyword_line',
7778
'_DynamicCore__get_keyword_path',
79+
'_DynamicCore__join_defaults_with_types',
7880
'get_keyword_arguments',
7981
'get_keyword_documentation',
8082
'get_keyword_source',

0 commit comments

Comments
 (0)