-
Notifications
You must be signed in to change notification settings - Fork 32
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
Removing escape sequence from output in cmd_output function! #142
base: main
Are you sure you want to change the base?
Conversation
In console outputs we are getting escape sequences because of which most of the testcases are failing to use the output of few commands. This PR removes the escape sequence first then use the output.This PR fixes multiple testcases. Signed-off-by: Anushree Mathur <[email protected]>
In total 2000+ testcases are failing but to give an example I am mentioning the following testcase!
After applying the patch:
|
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.
I don't think the strip_console_codes
should be used at all times as get_output
might be used to interact with any kind of output. IMO the consumers should decide whether they need to strip the console codes or leave them present in the output.
It's true that people interacting with odd outputs might use read_nonblocking
directly to get the full output, but having get_output
seems convenient and some only need to check the output after the execution (eg. tests needing to check whether arrows were used correctly).
I mean if there were thousands of lines where people need to clean the output, I'd consider adding an argument to do so, but doing it out of the box seems like removing useful feature for lower-level usage.
Hello @ldoktor , thanks alot for taking time and reviewing this commit! I understand your point, so do you suggest that we do it locally in the functions where these outputs are being used? Could you please guide me how i can proceed otherwise? Thanks in advance! |
What I meant is to do it explicitly in the test itself: from aexpect.utils.astring import strip_console_codes
...
out = session.cmd_output(...)
out_safe = strip_console_codes(out) But if it proves to be massively used we might consider support for |
Hello @ldoktor , understood your point clearly! Thank you so much. Will make the changes in the testcase itself. |
Hi, I will be able to test and review this towards the end of the week, I hope this is ok and thanks for the contribution! |
Hi @ldoktor @pevogam , I have tried modifying my PR in the following way as suggested by @ldoktor! Many places cmd_output is used so I changed the code here and tried to run the same tescase after applying the strip_console_code=True in the local code where I wanted the O/P to be replaced and it worked totally fine! I would really like to have some suggestions here if I can proceed in this manner! Thanks in advance for your time.
|
Hi @Anushree-Mathur, could you perhaps provide a diff instead so that it is easy to parse what modification entails? |
Hi @pevogam , here is the git diff result:
|
This seems fine by me, provided the code is polished a bit. Mainly it needs to tackle the |
I second that opinion. This change is invasive and should preserve the behavior for anyone not wishing to remove the console codes and likely has their own handling logic down the line.
I think this diff is much more reasonable and perhaps you could push the suggested change for easier review now?
I can definitely do in-line commenting and recommendations once I see this pushed but @Anushree-Mathur it would be great if you take in @ldoktor's recommendation before the push so we can save on the feedback cycles. Also, I wonder what is the difference between this PR and #141? Could we instead close one of them and focus on just one pull request regarding escaping such characters? |
Well the #141 is solely about the last_line_matches, which is mainly used to detect console. It's safer to use filtering there as the whole output is returned while the filtered one is only used for the detection. Note I'd classify the #141 actually as a bugfix as I think we ought to treat the output that way and I'm surprised we're not hitting problems with it too frequently. As for this one it's a convenience for test-writers who could use this feature to get filtered output and I like @Anushree-Mathur kept the default behaviour as is so unless one deliberately opts-in for it they get the same behaviour. |
Even then the changes seem quite related and could have at least be two commits in the same branch like "fix critical problem" followed by "enhance use for others for related problem" but your arguments also make a lot of sense. Alright, in any case still good to see the suggested changes pushed so that we can test them. |
In console outputs we are getting escape sequences because of which most of the testcases are failing to use the output of few commands. This PR removes the escape sequence first then use the output.This PR fixes multiple testcases.
Signed-off-by: Anushree Mathur [email protected]