Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Argument conversion with enums should work with normalized names #3611

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Snooz82 opened this issue Jul 10, 2020 · 5 comments
Closed

Argument conversion with enums should work with normalized names #3611

Snooz82 opened this issue Jul 10, 2020 · 5 comments
Labels
acknowledge To be acknowledged in release notes enhancement priority: medium
Milestone

Comments

@Snooz82
Copy link
Member

Snooz82 commented Jul 10, 2020

We are using a lot of enums in Browser Library and would like to have the automatic conversion from strings in RF to enum members in Python being able to match members based on a normalized string.

Because members of enums can not contains spaces, like method names in python, but spaces are typically quite common in RobotFramework we want to be able to allow spaces in member names.
Same with case sensitivity.
Case sensitivity with values is very rare.

Lets assume we have the following enum:

AssertionOperator = Enum(
    "AssertionOperator",
    {
        "noassertion": "NO_ASSERTION",
        "NO_ASSERTION": "NO_ASSERTION",
        "equal": "==",
        "==": "==",
        "shouldbe": "==",
        "inequal": "!=",
        "!=": "!=",
        "shouldnotbe": "!=",
        "lessthan": "<",
        "<": "<",
        "greaterthan": ">",
        ">": ">",
        "<=": "<=",
        ">=": ">=",
        "contains": "*=",
        "*=": "*=",
        "starts": "^=",
        "^=": "^=",
        "shouldstartwith": "^=",
        "ends": "$=",
        "shouldendwith": "$=",
        "$=": "$=",
        "matches": "$",
        "validate": "validate",
        "then": "then",
    },
)

The values in robot shouldnotbe, Should Not Be and should_not_be etc all match to the member shouldnotbe

When documenting the enum in libdoc it should also document the "robotic" name Should Not Be

This is related to #3607 but imho with a higher priority.

@pekkaklarck
Copy link
Member

Enum member matching being case, space and also underscore insensitive like matching keyword names sounds good to me. It also ought to be so easy to do and backwards compatible that we can consider it in RF 3.2.2.

How Libdoc should show enum members is a different question and part of #3607.

@mkorpela
Copy link
Member

This will actually be somewhat backwards incompatible as currently there could be lower and uppercase etc enum values that are different. They will be same after this change.
But I do ’t know how much trouble this might be. I would assume that not so much.

@pekkaklarck
Copy link
Member

Yeah, it's possible someone would be affected by this change but those changes are pretty small compared to benefits.

The bigger question is, do we want to have such an enhancement in a patch release in the first place. A library using this functionality would then work differently with RF 3.2.1 and 3.2.2 which needed to be documented. Then again, there's the same issue between RF 3.2 and 3.3 if we do the change later.

I still think this is a good enhancement for RF 3.2.2 but if others disagree and this feature isn't needed super urgently waiting for RF 3.3 is fine as well.

@pekkaklarck pekkaklarck added the acknowledge To be acknowledged in release notes label Aug 18, 2020
pekkaklarck pushed a commit that referenced this issue Aug 20, 2020
pekkaklarck added a commit that referenced this issue Aug 20, 2020
It is now an error to use non-exact match that matches multiple
members. See issue #3611 and PR #3632 for more details.
@pekkaklarck
Copy link
Member

Thanks to @willemvanoort for PR #3632 implementing this!

@pekkaklarck pekkaklarck changed the title Enum conversion should work with normalized names Argument conversion with enums should work with normalized names Aug 31, 2020
@pekkaklarck
Copy link
Member

This enhancement ought to be fully backwards compatible. The reason is that the code first tries an exact match so if we have an enum like

class Example(Enum):
    FOO = 1
    foo = 2

using FOO and foo in arguments works exactly the same in different versions.

If an enum has two members with names that have same normalized form, using a non-exact version will actually be an error. For example, using argument Foo wouldn't work with the example enum above.

vokiput pushed a commit to vokiput/robotframework that referenced this issue Dec 27, 2020
vokiput pushed a commit to vokiput/robotframework that referenced this issue Dec 27, 2020
vokiput pushed a commit to vokiput/robotframework that referenced this issue Dec 27, 2020
It is now an error to use non-exact match that matches multiple
members. See issue robotframework#3611 and PR robotframework#3632 for more details.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
acknowledge To be acknowledged in release notes enhancement priority: medium
Projects
None yet
Development

No branches or pull requests

3 participants