-
-
Notifications
You must be signed in to change notification settings - Fork 33.9k
gh-143866: Verify return value of pathlib write methods in tests #143870
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?
Conversation
|
Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool. If this change has little impact on Python users, wait for a maintainer to apply the |
| def test_write_bytes_return(self): | ||
| p = self.root / 'fileA' | ||
| data = b'some bytes' | ||
| self.assertEqual(len(data), p.write_bytes(data)) |
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 we update an existing test? Instead of creating a new one
|
Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool. If this change has little impact on Python users, wait for a maintainer to apply the |
|
Ok, i am changed it. Can you add "skip news" label please? |
| # Check that trying to write bytes does not truncate the file. | ||
| self.assertRaises(TypeError, p.write_text, b'somebytes', encoding='utf-8') | ||
| self.assertEqual(self.ground.readbytes(p), b'\xe4bcdefg') | ||
| # check the return 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.
Can we check the return value on line 79?
Description
This PR adds assertions to ensure that
pathlib.Path.write_text()andpathlib.Path.write_bytes()correctly return the number of bytes written.Currently, the tests only verify the side effects (file content), which means a regression (like accidentally removing the
returnstatement) would go unnoticed.Linked Issue
Fixes #143866