Skip to content

Commit e38c868

Browse files
committed
Enhance user keyword argument conversion errors
Error messages enhanced in these cases: - Embedded argument value is invalid. - Argument default value is invalid.
1 parent 79cc536 commit e38c868

File tree

4 files changed

+23
-19
lines changed

4 files changed

+23
-19
lines changed

atest/robot/variables/variable_types.robot

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ User keyword
141141
User keyword: Default value
142142
Check Test Case ${TESTNAME}
143143

144-
User keyword: Wrong default value
144+
User keyword: Invalid default value
145145
Check Test Case ${TESTNAME} 1
146146
Check Test Case ${TESTNAME} 2
147147

@@ -151,15 +151,15 @@ User keyword: Invalid value
151151
User keyword: Invalid type
152152
Check Test Case ${TESTNAME}
153153
Error In File
154-
... 0 variables/variable_types.robot 480
154+
... 0 variables/variable_types.robot 481
155155
... Creating keyword 'Bad type' failed:
156156
... Invalid argument specification: Invalid argument '\${arg: bad}':
157157
... Unrecognized type 'bad'.
158158

159159
User keyword: Invalid assignment with kwargs k_type=v_type declaration
160160
Check Test Case ${TESTNAME}
161161
Error In File
162-
... 1 variables/variable_types.robot 484
162+
... 1 variables/variable_types.robot 485
163163
... Creating keyword 'Kwargs does not support key=value type syntax' failed:
164164
... Invalid argument specification: Invalid argument '\&{kwargs: int=float}':
165165
... Unrecognized type 'int=float'.
@@ -182,7 +182,7 @@ Embedded arguments: Invalid value from variable
182182
Embedded arguments: Invalid type
183183
Check Test Case ${TESTNAME}
184184
Error In File
185-
... 2 variables/variable_types.robot 504
185+
... 2 variables/variable_types.robot 505
186186
... Creating keyword 'Embedded invalid type \${x: invalid}' failed:
187187
... Invalid embedded argument '\${x: invalid}':
188188
... Unrecognized type 'invalid'.

atest/testdata/variables/variable_types.robot

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -235,15 +235,16 @@ User keyword: Default value
235235
Default as string
236236
Default as string ${42}
237237

238-
User keyword: Wrong default value 1
238+
User keyword: Invalid default value 1
239239
[Documentation] FAIL
240-
... ValueError: Argument default value 'arg' got value 'wrong' that cannot be converted to integer.
241-
Wrong default
240+
... ValueError: Default value for argument 'arg' got value 'invalid' that cannot be converted to integer.
241+
Invalid default
242242

243-
User keyword: Wrong default value 2
243+
User keyword: Invalid default value 2
244244
[Documentation] FAIL
245-
... ValueError: Argument 'arg' got value 'yyy' that cannot be converted to integer.
246-
Wrong default yyy
245+
... ValueError: Argument 'arg' got value 'bad' that cannot be converted to integer.
246+
Invalid default 42
247+
Invalid default bad
247248

248249
User keyword: Invalid value
249250
[Documentation] FAIL
@@ -280,11 +281,11 @@ Embedded arguments: With variables
280281
Embedded ${x} and ${y}
281282

282283
Embedded arguments: Invalid value
283-
[Documentation] FAIL ValueError: Argument 'kala' cannot be converted to integer.
284+
[Documentation] FAIL ValueError: Argument 'y' got value 'kala' that cannot be converted to integer.
284285
Embedded 1 and kala
285286

286287
Embedded arguments: Invalid value from variable
287-
[Documentation] FAIL ValueError: Argument '[2, 3]' (list) cannot be converted to integer.
288+
[Documentation] FAIL ValueError: Argument 'y' got value '[2, 3]' (list) that cannot be converted to integer.
288289
Embedded 1 and ${{[2, 3]}}
289290

290291
Embedded arguments: Invalid type
@@ -472,9 +473,9 @@ Default as string
472473
Should be equal ${arg} 42 type=str
473474
RETURN ${arg}
474475

475-
Wrong default
476-
[Arguments] ${arg: int}=wrong
477-
Fail This shuld not be run
476+
Invalid default
477+
[Arguments] ${arg: int}=invalid
478+
Should Be Equal ${arg} 42 type=int
478479

479480
Bad type
480481
[Arguments] ${arg: bad}

src/robot/running/arguments/embedded.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
from robot.errors import DataError
2121
from robot.utils import get_error_message
22-
from robot.variables import VariableMatch, VariableMatches
22+
from robot.variables import VariableMatches
2323

2424
from ..context import EXECUTION_CONTEXTS
2525
from .typeinfo import TypeInfo
@@ -45,7 +45,7 @@ def __init__(
4545
def from_name(cls, name: str) -> "EmbeddedArguments|None":
4646
return EmbeddedArgumentParser().parse(name) if "${" in name else None
4747

48-
def match(self, name: str) -> 're.Match|None':
48+
def match(self, name: str) -> "re.Match|None":
4949
"""Deprecated since Robot Framework 7.3."""
5050
warnings.warn(
5151
"'EmbeddedArguments.match()' is deprecated since Robot Framework 7.3. Use "
@@ -87,7 +87,10 @@ def _replace_placeholders(self, arg: str, placeholders: "dict[str, str]") -> str
8787
return arg
8888

8989
def map(self, args: Sequence[object]) -> "list[tuple[str, object]]":
90-
args = [t.convert(a) if t else a for a, t in zip(args, self.types)]
90+
args = [
91+
info.convert(value, name) if info else value
92+
for info, name, value in zip(self.types, self.args, args)
93+
]
9194
self.validate(args)
9295
return list(zip(self.args, args))
9396

src/robot/running/userkeywordrunner.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ def _set_variables(self, spec: ArgumentSpec, positional, named, variables):
138138
value = value.resolve(variables)
139139
info = spec.types.get(name)
140140
if info:
141-
value = info.convert(value, name, kind="Argument default value")
141+
value = info.convert(value, name, kind="Default value for argument")
142142
variables[f"${{{name}}}"] = value
143143
if spec.var_positional:
144144
variables[f"@{{{spec.var_positional}}}"] = var_positional

0 commit comments

Comments
 (0)