gh-131015: Add test for bytes formatting errors#131881
Conversation
|
|
||
| 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.
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.
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.
Yes, something like this is fine. It'll become easier to add more test cases later.
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
picnixz
left a comment
There was a problem hiding this comment.
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 <10796600+picnixz@users.noreply.github.com> (cherry picked from commit 0555778)
Added test for byte formatting errors as for strings in https://github.com/python/cpython/blob/main/Lib/test/test_str.py#L1581-L1591