Skip to content

gh-153953: Increase test coverage for the wave module#153954

Open
fedonman wants to merge 11 commits into
python:mainfrom
fedonman:fix-gh-153953-wave-test-coverage
Open

gh-153953: Increase test coverage for the wave module#153954
fedonman wants to merge 11 commits into
python:mainfrom
fedonman:fix-gh-153953-wave-test-coverage

Conversation

@fedonman

@fedonman fedonman commented Jul 18, 2026

Copy link
Copy Markdown
Contributor

Adds tests for previously-uncovered code paths in Lib/wave.py, all reachable through the public API and deterministic across platforms.

Wave_write parameter validation

  • setnchannels() rejecting a non-positive channel count
  • getnchannels() / getsampwidth() / getframerate() / getparams() raising when parameters are unset
  • setsampwidth() rejecting out-of-range widths
  • setcomptype() / setformat() rejecting unsupported values
  • the "cannot change parameters after starting to write" guard on every setter (setnchannels, setsampwidth, setframerate, setnframes, setcomptype, setformat, setparams)
  • tell()

Wave_read error handling

  • rejecting a WAVE_FORMAT_EXTENSIBLE file whose SubFormat GUID is not PCM
  • raising EOFError on a truncated fmt chunk (missing header / missing sample width)
  • skipping an unknown, odd-sized chunk between fmt and data
  • getfp()
  • closing the underlying file when opening a malformed file by path fails

wave.open()

  • rejecting an invalid mode

Measured with the stdlib trace module while running test_wave, line coverage of Lib/wave.py rises from 317/449 to 345/449 executable lines.

This is a test-only change with no behavior change, so no Misc/NEWS.d entry is included. ./python -m test -R 3:3 test_wave reports no reference leaks.

Fixes #153953.

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.
@bedevere-app bedevere-app Bot added the tests Tests in the Lib/test dir label Jul 18, 2026
Comment thread Lib/test/test_wave.py Outdated
Comment thread Lib/test/test_wave.py Outdated
Comment thread Lib/test/test_wave.py Outdated
@fedonman
fedonman requested a review from vstinner July 18, 2026 23:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

Increase test coverage for the wave module

3 participants