-
-
Notifications
You must be signed in to change notification settings - Fork 31.9k
gh-131015: Add test for bytes formatting errors #131881
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
Conversation
Lib/test/test_bytes.py
Outdated
|
||
pi = PseudoFloat(3.1415) | ||
|
||
self.assertRaisesRegex(TypeError, '%x format: an integer is required, not float', operator.mod, '%x', 3.14) |
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.
Can you make it so that all lines are under 80 chars please? I think the existing code is breaking that limit but I'm not entirely sure. More generally, you could do mod = operator.mod
to reduce the overall line length as well.
mod = operator.mod
msg = "...."
self.assertRaisesRegex(TypeError, msg, mod, ...)
Or use a private helper for this test.
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.
What do you think about that option?
exceptions_params = (
('%x format: an integer is required, not float','%x', 3.14),
...
)
for msg, format, value in exceptions_params:
self.assertRaisesRegex(TypeError, msg , mod, format, value)
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, something like this is fine. It'll become easier to add more test cases later.
Co-authored-by: Bénédikt Tran <[email protected]>
Co-authored-by: Bénédikt Tran <[email protected]>
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.
It could have been possible to also separate the error checks and put them in a separate method but the other tests don't seem to separate the good and the bad cases so let's keep it that way.
We should test bytes and not strings formatting.
I'll merge this tomorrow. |
Thanks @ApostolFet for the PR, and @picnixz for merging it 🌮🎉.. I'm working now to backport this PR to: 3.12. |
Thanks @ApostolFet for the PR, and @picnixz for merging it 🌮🎉.. I'm working now to backport this PR to: 3.13. |
Sorry, @ApostolFet and @picnixz, I could not cleanly backport this to
|
Sorry, @ApostolFet and @picnixz, I could not cleanly backport this to
|
I'll make the backports |
GH-132114 is a backport of this pull request to the 3.12 branch. |
GH-132115 is a backport of this pull request to the 3.13 branch. |
Co-authored-by: Bénédikt Tran <[email protected]> (cherry picked from commit 0555778)
Co-authored-by: Bénédikt Tran <[email protected]>
Added test for byte formatting errors as for strings in https://github.com/python/cpython/blob/main/Lib/test/test_str.py#L1581-L1591