8000 gh-119780: Adjust exception messages in Lib/test/test_format.py by skirpichev · Pull Request #119781 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-119780: Adjust exception messages in Lib/test/test_format.py #119781

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

Merged
merged 5 commits into from
May 31, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions Lib/test/test_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ def test_exc(formatstr, args, exception, excmsg):
else:
if verbose: print('no')
print('Unexpected ', exception, ':', repr(str(exc)))
raise
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest to remove this for now, and properly rewrite this function in a separate issue. This will help to backport it.

This is an ancient code which was ported to unittest. Now we can use subTest() if we want to see multiple failures.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the issue with backporting this change? It should work fine on 3.12 too. We can rewrite this to properly use subTest() later, but this change is small and fixes a bug that led us to miss some real test failures.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code will be different in main and other branches, therefore conflicts, which should be resolved manually.

Copy link
Contributor Author
@skirpichev skirpichev May 31, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@serhiy-storchaka, reverted. Issue description adjusted, so I don't think there should be a new issue.

except:
if verbose: print('no')
print('Unexpected exception')
Expand Down Expand Up @@ -304,9 +305,9 @@ def test_str_format(self):
test_exc('%c', sys.maxunicode+1, OverflowError,
"%c arg not in range(0x110000)")
#test_exc('%c', 2**128, OverflowError, "%c arg not in range(0x110000)")
test_exc('%c', 3.14, TypeError, "%c requires int or char")
test_exc('%c', 'ab', TypeError, "%c requires int or char")
test_exc('%c', b'x', TypeError, "%c requires int or char")
test_exc('%c', 3.14, TypeError, "%c requires an int or a unicode character, not float")
test_exc('%c', 'ab', TypeError, "%c requires an int or a unicode character, not a string of length 2")
test_exc('%c', b'x', TypeError, "%c requires an int or a unicode character, not bytes")

if maxsize == 2**31-1:
# crashes 2.2.1 and earlier:
Expand Down Expand Up @@ -370,11 +371,11 @@ def __bytes__(self):
test_exc(b"%c", 2**128, OverflowError,
"%c arg not in range(256)")
test_exc(b"%c", b"Za", TypeError,
"%c requires an integer in range(256) or a single byte")
"%c requires an integer in range(256) or a single byte, not a bytes object of length 2")
test_exc(b"%c", "Y", TypeError,
"%c requires an integer in range(256) or a single byte")
"%c requires an integer in range(256) or a single byte, not str")
test_exc(b"%c", 3.14, TypeError,
"%c requires an integer in range(256) or a single byte")
"%c requires an integer in range(256) or a single byte, not float")
test_exc(b"%b", "Xc", TypeError,
"%b requires a bytes-like object, "
"or an object that implements __bytes__, not 'str'")
Expand Down
0