Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 35.2k
gh-75593: Allow opening of path-like files with wave.open#140951
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
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
99e7d5a6475b2ca36d5fca09e5c395b2fce9b96c88ec5b3dfba5ed6f31cc9c56c2b7deFile filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,11 @@ | ||
| import unittest | ||
| from test import audiotests | ||
| from test import support | ||
| from test.support.os_helper import FakePath | ||
| import io | ||
| import os | ||
| import struct | ||
| import tempfile | ||
| import sys | ||
| import wave | ||
| @@ -206,5 +208,25 @@ def test_open_in_write_raises(self): | ||
| self.assertIsNone(cm.unraisable) | ||
| class WaveOpen(unittest.TestCase): | ||
| def test_open_pathlike(self): | ||
| """It is possible to use `wave.read` and `wave.write` with a path-like object""" | ||
| with tempfile.NamedTemporaryFile(delete_on_close=False) as fp: | ||
| cases = ( | ||
| FakePath(fp.name), | ||
| FakePath(os.fsencode(fp.name)), | ||
Member There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Test also for | ||
| os.fsencode(fp.name), | ||
| ) | ||
| for fake_path in cases: | ||
| with self.subTest(fake_path): | ||
| with wave.open(fake_path, 'wb') as f: | ||
| f.setnchannels(1) | ||
| f.setsampwidth(2) | ||
| f.setframerate(44100) | ||
| with wave.open(fake_path, 'rb') as f: | ||
| pass | ||
| if __name__ == '__main__': | ||
| unittest.main() | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Add support of :term:`path-like objects <path-like object>` and :term:`bytes-like objects <bytes-like object>` in :func:`wave.open`. |
Uh oh!
There was an error while loading. Please reload this page.
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.
Isn't there a place for this test in an existing class? You can also look in audiotests -- if this was added before removing aifc, the test should be added there.
Uh oh!
There was an error while loading. Please reload this page.
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 had also considered adding the new tests to MiscTestCase or WaveLowLevelTest - I don't have a good reason to create a new class now that I think of it, except that perhaps they don't strictly belong in either of those places.
Just to clarify your point about adding the tests to audiotests.py - are you saying that the new tests should simply be moved there instead? Or do you mean that the existing tests in test_wave.py should inherit the new tests similar to the existing design?
My rationale for adding the tests to test_wave.py is I did feel like they belonged in test_wave.py and not audiotests.py since the classes in audiotests.py are inherited by the classes in test_wave.py to assert a range of things which felt redundant for the new tests to also perform.