You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
New Should Contain Any and Should Not Contain Any keywords #2120
I am searching through a list and would like to pass if any one of my values are found. It appears that the List Should Contain Value keyword only accepts one value. I have tried using Value1 or Value2 but it does not appear to be searching for either one. I would suggest to modify this keyword to accept multiple values separated by 'or'.
Furthermore, I would like to have the output display the matches, and fail if no matches are found
Yes, there doesn't seem to be any keyword that supports this in Collections. We cannot change List Should Contain Value because basically any change would be backwards incompatible. Adding separate List Should Contain Any Value is possible, but we could also consider adding more generic Should Contain Any to BuiltIn. Are you interested to provide a pull request?
GitHub has pretty good documentation about pull requests, and our contributing guidelines have links to them along with some other valuable information. Let us know if it is hard to get started or you get stuck somewhere.
Would you be interested to implement List Should Contain Any Value or Should Contain Any? I think the latter would be more valuable because it would be more generic. If the former is implemented, then we should add related dict keywords too. Adding all of them is possible too but perhaps too much work compared to benefits. Regardless what is implemented, Not version (e.g. Should Not Contain Any) should be added too.
After thinking this a bit more, I believe it's best to implement Should Contain Any and Should Not Contain Any. They are generic and can be used with strings or anything that is list-like. This functionality isn't needed too often, so adding separate List Should Contain Any Value, Dictionary Should Contain Any Key, etc. wouldn't be worth the effort in my opinion.
changed the title [-]Allow List Should Contain Value to accept multiple values[/-][+]New `Should Contain Any` and `Should Not Contain Any` keywords[/+]on Jun 1, 2016
Nobody has shown any interest to implement the new keywords, but I consider them so useful that I plan to include them in RF 3.0.1 anyway. If someone is interested in contributing to RF, this would be a pretty easy issue to get started.
Great! Please provide a pull request once you got something ready and we can review it. If you do it in a separate branch, you can easily commit new changes and the PR automatically gets updated.
The signature of these keywords should probably be something like container, *items. That allows usage like this:
Should Contain Any ${text} foo bar zap
What do you think, should same msg=None and values=True arguments be accepted as Should (Not) Contain accepts? If yes, the signature should probably be container, *items, **config and code contain something like:
msg=config.pop('msg', None)
values=config.pop('values', True)
ifconfig:
raiseRuntimeError('Message explaining that unsupported config values were used')
Alternatively we could look does the last and second last item start with msg= and values= but that is more complicated. This kind of **config approach is already used by the Process library and it has worked well there. If we didn't need to care about Python 2, we could just use keyword-only arguments.
While writing tests I came across the fact that lists and tuples are stringified with u' ' (unlike strings):
'(u'yet', u'yes', u'no')'
I'm not sure if this is desired behaviour or not, or maybe I'm just doing something wrong.
For now, I left this hanging in the tests' fail messages, because it looks harmless. Let me know if this needs a follow-up resolution.
Is this in the error message? Probably should use utils.seq2str there.
u prefix is added because strings passed to Robot are Unicode and string representation of tuples and lists contains the repr() of items. It's not added in Python 3 which is problematic in tests. Using the aforementioned util resolves that too.
On a very quick look the PR looks very good. Hopefully I have time to look it tomorrow in more detail. Trying to get our house sold means I'm somewhat busy.
This has been implemented by @jimni in PR #2393 that was just merged. I'll do a little additional testing possibly little fine tuning but otherwise this issue can be considered done. Thanks @jimni for a great PR!
Final fine-tuning in done in 5bde125. Main change was making it an explicit error to use these keywords without any items to test against. Should Contain Any already failed with a bad error and Should Not Contain Any passed in this case. I think it is safer to fail in both cases and to have a better message, but it is still easy to change this before the 3.0.1 release.
I consider this issue done. Already started thinking should we also add Should (Not) Match Any keywords... =)
Activity
pekkaklarck commentedon Aug 28, 2015
Yes, there doesn't seem to be any keyword that supports this in Collections. We cannot change
List Should Contain Valuebecause basically any change would be backwards incompatible. Adding separateList Should Contain Any Valueis possible, but we could also consider adding more genericShould Contain Anyto BuiltIn. Are you interested to provide a pull request?jongu82 commentedon Aug 28, 2015
Yes I am interested. I'm fairly new to github and the use of pull requests but I'd be willing to give it a shot.
pekkaklarck commentedon Aug 28, 2015
GitHub has pretty good documentation about pull requests, and our contributing guidelines have links to them along with some other valuable information. Let us know if it is hard to get started or you get stuck somewhere.
Would you be interested to implement
List Should Contain Any ValueorShould Contain Any? I think the latter would be more valuable because it would be more generic. If the former is implemented, then we should add related dict keywords too. Adding all of them is possible too but perhaps too much work compared to benefits. Regardless what is implemented,Notversion (e.g.Should Not Contain Any) should be added too.pekkaklarck commentedon Oct 9, 2015
After thinking this a bit more, I believe it's best to implement
Should Contain AnyandShould Not Contain Any. They are generic and can be used with strings or anything that is list-like. This functionality isn't needed too often, so adding separateList Should Contain Any Value,Dictionary Should Contain Any Key, etc. wouldn't be worth the effort in my opinion.Anyone interested to implement
Should (Not) Contain Any? There's plenty of time until RF 3.0 which is the next planned release and I can help if needed. If you are new to providing pull requests and contributing in general, you can start by reading these guidelines:https://github.com/robotframework/robotframework/blob/master/CONTRIBUTING.rst
[-]Allow List Should Contain Value to accept multiple values[/-][+]New `Should Contain Any` and `Should Not Contain Any` keywords[/+]pekkaklarck commentedon Jun 1, 2016
Nobody has shown any interest to implement the new keywords, but I consider them so useful that I plan to include them in RF 3.0.1 anyway. If someone is interested in contributing to RF, this would be a pretty easy issue to get started.
jimni commentedon Jun 2, 2016
I would like to have a go at this issue.
I will either come up with the solution before 7th of June, or consider me forfeit :)
pekkaklarck commentedon Jun 2, 2016
Great! Please provide a pull request once you got something ready and we can review it. If you do it in a separate branch, you can easily commit new changes and the PR automatically gets updated.
The signature of these keywords should probably be something like
container, *items. That allows usage like this:What do you think, should same
msg=Noneandvalues=Truearguments be accepted asShould (Not) Containaccepts? If yes, the signature should probably becontainer, *items, **configand code contain something like:Alternatively we could look does the last and second last item start with
msg=andvalues=but that is more complicated. This kind of**configapproach is already used by the Process library and it has worked well there. If we didn't need to care about Python 2, we could just use keyword-only arguments.jimni commentedon Jun 2, 2016
I believe they should. I will aim for this behaviour.
jimni commentedon Jun 2, 2016
Should we also redefine
Should (Not) Containas wrappers for these new keywords? As in:I'm not sure if this interpretation of SRP is considered appropriate in RF, please let me know.
pekkaklarck commentedon Jun 2, 2016
Depends how the code would look line in the end. These kws may also have slightly different failure messages making direct reuse harder.
jimni commentedon Jun 2, 2016
I see your point. Let's consider that afterwards
jimni commentedon Jun 5, 2016
While writing tests I came across the fact that lists and tuples are stringified with
u' '(unlike strings):I'm not sure if this is desired behaviour or not, or maybe I'm just doing something wrong.
For now, I left this hanging in the tests' fail messages, because it looks harmless. Let me know if this needs a follow-up resolution.
Looking forward to your feedback.
pekkaklarck commentedon Jun 5, 2016
Is this in the error message? Probably should use
utils.seq2strthere.uprefix is added because strings passed to Robot are Unicode and string representation of tuples and lists contains therepr()of items. It's not added in Python 3 which is problematic in tests. Using the aforementioned util resolves that too.pekkaklarck commentedon Jun 5, 2016
On a very quick look the PR looks very good. Hopefully I have time to look it tomorrow in more detail. Trying to get our house sold means I'm somewhat busy.
jimni commentedon Jun 5, 2016
Take your time, I'm not going anywhere.
jimni commentedon Jun 6, 2016
utils.seq2strworked very well. Thank you.Merge pull request #2393 from jimni/feature-#2120-Should-Contain-Any
pekkaklarck commentedon Oct 5, 2016
This has been implemented by @jimni in PR #2393 that was just merged. I'll do a little additional testing possibly little fine tuning but otherwise this issue can be considered done. Thanks @jimni for a great PR!
Small cleanup to "Should (Not) Contain Any". #2120
Fine-tuning `Should (Not) Contain Any`. #2120
pekkaklarck commentedon Oct 7, 2016
Final fine-tuning in done in 5bde125. Main change was making it an explicit error to use these keywords without any items to test against.
Should Contain Anyalready failed with a bad error andShould Not Contain Anypassed in this case. I think it is safer to fail in both cases and to have a better message, but it is still easy to change this before the 3.0.1 release.I consider this issue done. Already started thinking should we also add
Should (Not) Match Anykeywords... =)