Skip to content
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

Tags objects do not support equality checking correctly #3242

Closed
stdedos opened this issue Jul 18, 2019 · 5 comments
Closed

Tags objects do not support equality checking correctly #3242

stdedos opened this issue Jul 18, 2019 · 5 comments
Labels
acknowledge To be acknowledged in release notes alpha 1 bug good first issue Good for newcomers priority: low
Milestone

Comments

@stdedos
Copy link
Contributor

stdedos commented Jul 18, 2019

I tried to unit-test a listener manipulating tags here: pytest-dev/pytest#5618 (comment) It seems that compares robot.model.Tags is kinda tricky. Is this wanted?

@pekkaklarck
Copy link
Member

I can reproduce this:

>>> from robot.model import Tags
>>> Tags(['x']) == Tags(['x'])
False

This definitely isn't correct, but it luckily ought to be pretty easy to add __eq__ (and __ne__) to Tags. PR would be appreciated, but because I consider this a bug, I can fix it myself as well after my holidays and once the newparser branch is merged to master.

@pekkaklarck pekkaklarck added this to the v3.2 milestone Jul 22, 2019
stdedos added a commit to stdedos/robotframework that referenced this issue Jul 23, 2019
* Add unit tests from both the issue
  (robotframework#3242)
  and the issue that started the discussion)
  (pytest-dev/pytest#5618)

Signed-off-by: Stavros Ntentos <133706+stdedos@users.noreply.github.com>
@stdedos
Copy link
Contributor Author

stdedos commented Jul 23, 2019

My only objection is that, I don't feel confident enough doing so.

Regarless, here(^^) is a PR to consider.

@pekkaklarck
Copy link
Member

One thing to take into account is that tags in Robot are case-, space- and underscore-insensitive. In other words, Tags(['X X']) == Tags(['x_x']) should be true. Also the order of tags shouldn't matter so Tags(['a', 'b']) == Tags(['b', 'a']) should be true as well.

An other thing to consider is that should Tags get more list methods. I added missing list methods to ItemList few days ago (#3261) and I guess same could be done to Tags as well. In this case the easiest solution would be using collections.abc.MutableSequence. I'm not sure is that worth the effort, though.

@stdedos
Copy link
Contributor Author

stdedos commented Sep 16, 2019

One thing to take into account is that tags in Robot are case-, space- and underscore-insensitive. In other words, Tags(['X X']) == Tags(['x_x']) should be true. Also the order of tags shouldn't matter so Tags(['a', 'b']) == Tags(['b', 'a']) should be true as well.

Would it then be acceptable, only for comparison purposes, to normalize everything? (this.lower().replace('_', ' ') == otherthis.lower().replace('_', ' ') and sorted(this) == sorted(other))

Or should that be done during init (as it could lower operations per call)?

An other thing to consider is that should Tags get more list methods. I added missing list methods to ItemList few days ago (#3261) and I guess same could be done to Tags as well. In this case the easiest solution would be using collections.abc.MutableSequence. I'm not sure is that worth the effort, though.

It seems you have alpha-merged something. Should I retry the patchset? Should I try to implement the normalization above? Do nothing and close?

@pekkaklarck
Copy link
Member

pekkaklarck commented Sep 16, 2019

Normalization should be done when comparing. We want to preserver the original format so it cannot be done at __init__. I doubt normalization when needed really affects performance, especially when normally there aren't that many tags and comparisons ought to be pretty rare in general.

stdedos added a commit to stdedos/robotframework that referenced this issue Oct 16, 2019
* Add unit tests from both the issue
  (robotframework#3242)
  and the issue that started the discussion)
  (pytest-dev/pytest#5618)

Signed-off-by: Stavros Ntentos <133706+stdedos@users.noreply.github.com>
stdedos added a commit to stdedos/robotframework that referenced this issue Oct 16, 2019
* Add unit tests from both the issue
  (robotframework#3242)
  and the issue that started the discussion)
  (pytest-dev/pytest#5618)
* Additional implementation details as per Slack discussion

Signed-off-by: Stavros Ntentos <133706+stdedos@users.noreply.github.com>
stdedos added a commit to stdedos/robotframework that referenced this issue Oct 18, 2019
First review round:

* Remove most of the `test__eq__` tests, as they belonged in
  `test_init_with_iterable_and_normalization_and_sorting` instead
  * Reuse the "duplicate tags" test
* Code style changes
stdedos added a commit to stdedos/robotframework that referenced this issue Oct 18, 2019
First review round:

* Remove most of the `test__eq__` tests, as they belonged in
  `test_init_with_iterable_and_normalization_and_sorting` instead
  * Reuse the "duplicate tags" test
* Code style changes
stdedos added a commit to stdedos/robotframework that referenced this issue Oct 18, 2019
First review round:

* Remove most of the `test__eq__` tests, as they belonged in
  `test_init_with_iterable_and_normalization_and_sorting` instead
  * Reuse the "duplicate tags" test
* Code style changes
* Fix robotframework/issues#3347
@pekkaklarck pekkaklarck added acknowledge To be acknowledged in release notes alpha 1 labels Oct 18, 2019
@pekkaklarck pekkaklarck changed the title Tags(tag_list) != Tags(tag_list) Tags objects do not support equality checking correctly Nov 11, 2019
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 alpha 1 bug good first issue Good for newcomers priority: low
Projects
None yet
Development

No branches or pull requests

2 participants