-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support for postional only args in dynamic library api (#4701)
Fixes #4660.
- Loading branch information
Showing
5 changed files
with
170 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
*** Settings *** | ||
Suite Setup Run Tests ${EMPTY} keywords/dynamic_positional_only_args.robot | ||
Force Tags require-py3.8 | ||
Resource atest_resource.robot | ||
|
||
*** Test Cases *** | ||
One Argument | ||
Check Test Case ${TESTNAME} | ||
|
||
Three arguments | ||
Check Test Case ${TESTNAME} | ||
|
||
Pos and named | ||
Check Test Case ${TESTNAME} | ||
|
||
Pos and names too few arguments | ||
Check Test Case ${TESTNAME} | ||
|
||
Three arguments too many arguments | ||
Check Test Case ${TESTNAME} | ||
|
||
Pos with default | ||
Check Test Case ${TESTNAME} | ||
|
||
All args | ||
Check Test Case ${TESTNAME} | ||
|
||
Arg with too may / separators | ||
Check Test Case ${TESTNAME} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
class DynamicPositionalOnly: | ||
kws = { | ||
"one argument": ["one", "/"], | ||
"three arguments": ["a", "b", "c", "/"], | ||
"with normal": ["posonly", "/", "normal"], | ||
"default str": ["required", "optional=default", "/"], | ||
"default tuple": ["required", ("optional", "default"), "/"], | ||
"all args kw": [("one", "value"), "/", ("named", "other"), "*varargs", "**kwargs"], | ||
"arg with separator": ["/one"], | ||
"Arg with too many / separators": ["one", "/", "two", "/"] | ||
} | ||
|
||
def get_keyword_names(self): | ||
return [key for key in self.kws] | ||
|
||
def run_keyword(self, name, args, kwargs=None): | ||
if kwargs: | ||
return f"{name}-{args}-{kwargs}" | ||
return f"{name}-{args}" | ||
|
||
def get_keyword_arguments(self, name): | ||
return self.kws[name] |
66 changes: 66 additions & 0 deletions
66
atest/testdata/keywords/dynamic_positional_only_args.robot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
*** Settings *** | ||
Library DynamicPositionalOnly.py | ||
Force Tags require-py3.8 | ||
|
||
*** Test Cases *** | ||
One Argument | ||
${result} = One Argument value | ||
Should be equal ${result} one argument-('value',) | ||
${result} = One Argument one=value | ||
Should be equal ${result} one argument-('one=value',) | ||
${result} = One Argument foo=value | ||
Should be equal ${result} one argument-('foo=value',) | ||
|
||
Three arguments | ||
${result} = Three Arguments a b c | ||
Should be equal ${result} three arguments-('a', 'b', 'c') | ||
${result} = Three Arguments x=a y=b z=c | ||
Should be equal ${result} three arguments-('x=a', 'y=b', 'z=c') | ||
${result} = Three Arguments a=a b=b c=c | ||
Should be equal ${result} three arguments-('a=a', 'b=b', 'c=c') | ||
|
||
Pos and named | ||
${result} = with normal a b | ||
Should be equal ${result} with normal-('a', 'b') | ||
${result} = with normal posonly=posonly normal=111 | ||
Should be equal ${result} with normal-('posonly=posonly',)-{'normal': '111'} | ||
${result} = with normal aaa normal=111 | ||
Should be equal ${result} with normal-('aaa',)-{'normal': '111'} | ||
|
||
Pos and names too few arguments | ||
[Documentation] FAIL Keyword 'DynamicPositionalOnly.With Normal' expected 2 arguments, got 1. | ||
with normal normal=aaa | ||
|
||
Three arguments too many arguments | ||
[Documentation] FAIL Keyword 'DynamicPositionalOnly.Three Arguments' expected 3 arguments, got 4. | ||
Three Arguments a b c / | ||
|
||
Pos with default | ||
${result} = default str a | ||
Should be equal ${result} default str-('a',) | ||
${result} = default str a optional=b | ||
Should be equal ${result} default str-('a', 'optional=b') | ||
${result} = default str optional=b | ||
Should be equal ${result} default str-('optional=b',) | ||
${result} = default tuple a | ||
Should be equal ${result} default tuple-('a',) | ||
${result} = default tuple a optional=b | ||
Should be equal ${result} default tuple-('a', 'optional=b') | ||
${result} = default tuple optional=b | ||
Should be equal ${result} default tuple-('optional=b',) | ||
${result} = default tuple optional=b optional=c | ||
Should be equal ${result} default tuple-('optional=b', 'optional=c') | ||
Arg with separator /one= | ||
Should be equal ${result} default tuple-('optional=b', 'optional=c') | ||
|
||
All args | ||
${result} = all args kw other value 1 2 kw1=1 kw2=2 | ||
Should be equal ${result} all args kw-('other', 'value', '1', '2')-{'kw1': '1', 'kw2': '2'} | ||
${result} = all args kw other | ||
Should be equal ${result} all args kw-('other',) | ||
${result} = all args kw | ||
Should be equal ${result} all args kw-() | ||
|
||
Arg with too may / separators | ||
[Documentation] FAIL No keyword with name 'Arg with too many / separators' found. | ||
Arg with too many / separators one two |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters