-
Notifications
You must be signed in to change notification settings - Fork 1.7k
callback integration test: use difflib rather than comparing lines #10690
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
base: main
Are you sure you want to change the base?
callback integration test: use difflib rather than comparing lines #10690
Conversation
7b1c0ae
to
7203948
Compare
d801cd8
to
fc185ec
Compare
The main problem with |
OK, that makes sense. One potential workaround would be allowing a test case to include parameters for 're.sub'. I used this to get rid of unpredictable output, such as the elapsed time from 'ansible.posix.profile_tasks'. |
Regex support would also be fine (I'd do it additional to providing alternatives), but it also won't work for difflib... I guess we really need an own diff implementation. The one used right now is quite primitive, but works. If you want to implement a more fancy one, feel free... |
- name: Assert test output equals expected output | ||
assert: | ||
that: result.output.differences | length == 0 | ||
that: result.output.diff | length == 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changing the RV name from differences to diff is a breaking change. Right? Cc: @felixfontein
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, but that doesn't matter, since it's an internal plugin used only by the integration tests that cannot be used from anywhere else.
If I only had to remove one instance of this list-of-strings syntax, does that mean there are no other uses of this feature? If there is only currently one use of this feature, would it be the end of the world if it was superceded by regex preprocessing?
Is the only non-hashable input the list of strings? |
Why is this? |
There likely have been more in the past, and new needs can arise at any time, due to changes in ansible-core.
The problem isn't that lists of strings can't be hashed (you could convert them to a tuple of strings, which can), but that it uses the hash for equality checking. Probably it wants to be able to check whether an element is part of a set by using a regular Python set (or dict).
Due to how SequenceMatcher works: it requires list elements to be hashable, and needs elements that are equialent to result in the same hash. |
Right, but I'm saying that those needs can be addressed with regex instead. If you want to allow one of 2 possible values for a line of text, you just write a regex that converts both of those possible values to a constant like "REPLACED", before doing the diff. Then you can use string hash for comparison. |
That was my first idea as well, but I don't think it will work if you have multiple entries where you have multiple choices, and some of these choices coincide (while others do not). |
SUMMARY
Modified callback integration test tooling to use difflib rather than comparing lines. The existing approach struggles to compare strings with different numbers of lines.
While working on my own callback testing, I found the abominable jinja diff implementation, and came up with my own workflow using the
diff
action plugin return value. This paired nicely with my diff filter. Requiringansible-test integration --diff
is a bit clunky, though. I figured this small change would be more likely to be merged than my cool hack.I see that the jinja diff has been rewritten in python (eff25c8). @felixfontein using
difflib
seems like a no brainer to me, did you consider this approach and decide against it?As far as I can tell,
difflib
has been in the python standard library at least as far back as python 2.6: https://docs.python.org/2.6/library/difflib.html.ISSUE TYPE
COMPONENT NAME
callback
ADDITIONAL INFORMATION
before:
after: