gh-153953: Increase test coverage for the wave module#153954
Open
fedonman wants to merge 11 commits into
Open
Conversation
Add tests for previously-uncovered paths in Lib/wave.py, all reachable through the public API: * Wave_write parameter validation: rejecting bad channel counts, sample widths, compression types and formats; the "not set" errors from the getters; the "cannot change parameters after starting to write" guards on every setter; and tell(). * Wave_read error handling: rejecting an unknown WAVE_FORMAT_EXTENSIBLE subformat, raising EOFError on a truncated fmt chunk, skipping unknown chunks, getfp(), and closing the file when opening a malformed path fails. * wave.open() rejecting an invalid mode. This raises line coverage of Lib/wave.py under test_wave from 317 to 345 of 449 executable lines. Test-only change; no behavior change.
vstinner
reviewed
Jul 18, 2026
Co-authored-by: Victor Stinner <vstinner@python.org>
The test relied on the _wave_file helper and FMT_PCM constant, which only exist on WaveReadErrorTest. Build the WAVE file with the wave module so the test is self-contained.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds tests for previously-uncovered code paths in
Lib/wave.py, all reachable through the public API and deterministic across platforms.Wave_writeparameter validationsetnchannels()rejecting a non-positive channel countgetnchannels()/getsampwidth()/getframerate()/getparams()raising when parameters are unsetsetsampwidth()rejecting out-of-range widthssetcomptype()/setformat()rejecting unsupported valuessetnchannels,setsampwidth,setframerate,setnframes,setcomptype,setformat,setparams)tell()Wave_readerror handlingWAVE_FORMAT_EXTENSIBLEfile whose SubFormat GUID is not PCMEOFErroron a truncatedfmtchunk (missing header / missing sample width)fmtanddatagetfp()wave.open()Measured with the stdlib
tracemodule while runningtest_wave, line coverage ofLib/wave.pyrises from 317/449 to 345/449 executable lines.This is a test-only change with no behavior change, so no
Misc/NEWS.dentry is included../python -m test -R 3:3 test_wavereports no reference leaks.Fixes #153953.
wavemodule #153953