Skip to content

Increase test coverage for the wave module #153953

Description

@fedonman

Tests

Several code paths in Lib/wave.py are not exercised by Lib/test/test_wave.py. Most of them are error and validation branches reachable through the public API, so they are easy to cover with small, deterministic tests.

Measuring line coverage of Lib/wave.py while running test_wave (via the stdlib trace module) shows the existing suite covers 317 of 449 executable lines. The uncovered branches include, among others:

Wave_write parameter validation

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

Wave_read error handling

  • rejecting a WAVE_FORMAT_EXTENSIBLE file whose SubFormat GUID is not PCM
  • raising EOFError on a truncated fmt chunk
  • skipping unknown chunks between fmt and data
  • getfp()
  • closing the underlying file when opening a malformed file by path fails

wave.open()

  • rejecting an invalid mode

Proposal

Add tests covering these paths. This is test-only (no behavior change), so no Misc/NEWS.d entry is required.

I have a patch ready and will open a PR.

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    testsTests in the Lib/test dirtype-featureA feature request or enhancement

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions