Skip to content

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

Merged
vstinner merged 19 commits into
python:mainfrom
fedonman:fix-gh-153953-wave-test-coverage
Aug 10, 2026
Merged

gh-153953: Increase test coverage for the wave module#153954
vstinner merged 19 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
@fedonman

Copy link
Copy Markdown
Contributor Author

@vstinner comments addressed, you may review again.

Comment thread Lib/test/test_wave.py Outdated
Comment thread Lib/test/test_wave.py Outdated
Comment thread Lib/test/test_wave.py
@fedonman
fedonman requested a review from vstinner July 26, 2026 15:14

@vstinner vstinner left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh! I had a draft comment for 2 weeks, I forgot to send it.

Comment thread Lib/test/test_wave.py Outdated
Replaces the eight one-assertion tests with the two grouped ones from the
review, which also cover bad frame rate, setparams validation and the
comptype round trip.
@fedonman

fedonman commented Aug 7, 2026

Copy link
Copy Markdown
Contributor Author

Applied, thanks.

Comment thread Lib/test/test_wave.py Outdated

@vstinner vstinner left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@github-project-automation github-project-automation Bot moved this from Todo to In Progress in Sprint Aug 10, 2026
@vstinner
vstinner enabled auto-merge (squash) August 10, 2026 14:08
@vstinner
vstinner merged commit 61304a3 into python:main Aug 10, 2026
52 checks passed
@github-project-automation github-project-automation Bot moved this from In Progress to Done in Sprint Aug 10, 2026
@vstinner

Copy link
Copy Markdown
Member

Merged, thanks for your contribution!

@bedevere-bot

Copy link
Copy Markdown

⚠️⚠️⚠️ Buildbot failure ⚠️⚠️⚠️

Hi! The buildbot s390x Fedora Stable LTO + PGO 3.x (tier-3) has failed when building commit 61304a3.

What do you need to do:

  1. Don't panic.
  2. Check the buildbot page in the devguide if you don't know what the buildbots are or how they work.
  3. Go to the page of the buildbot that failed (https://buildbot.python.org/#/builders/1627/builds/3165) and take a look at the build logs.
  4. Check if the failure is related to this commit (61304a3) or if it is a false positive.
  5. If the failure is related to this commit, please, reflect that on the issue and make a new Pull Request with a fix.

You can take a look at the buildbot page here:

https://buildbot.python.org/#/builders/1627/builds/3165

Failed tests:

  • test_profiling

Summary of the results of the build (if available):

==

Click to see traceback logs
Traceback (most recent call last):
  File "/var/lib/buildbot/worker/cstratak-fedora-stable-s390x/3.x.cstratak-fedora-stable-s390x.lto-pgo/build/Lib/test/test_profiling/test_sampling_profiler/test_live_collector_ui.py", line 900, in test_run_failed_script_live
    main()
    ~~~~^^
  File "/var/lib/buildbot/worker/cstratak-fedora-stable-s390x/3.x.cstratak-fedora-stable-s390x.lto-pgo/build/Lib/profiling/sampling/cli.py", line 989, in main
    _main()
    ~~~~~^^
  File "/var/lib/buildbot/worker/cstratak-fedora-stable-s390x/3.x.cstratak-fedora-stable-s390x.lto-pgo/build/Lib/profiling/sampling/cli.py", line 1145, in _main
    handler(args)
    ~~~~~~~^^^^^^
  File "/var/lib/buildbot/worker/cstratak-fedora-stable-s390x/3.x.cstratak-fedora-stable-s390x.lto-pgo/build/Lib/profiling/sampling/cli.py", line 1251, in _handle_run
    _handle_live_run(args)
    ~~~~~~~~~~~~~~~~^^^^^^
  File "/var/lib/buildbot/worker/cstratak-fedora-stable-s390x/3.x.cstratak-fedora-stable-s390x.lto-pgo/build/Lib/profiling/sampling/cli.py", line 1386, in _handle_live_run
    sample_live(
    ~~~~~~~~~~~^
        process.pid,
        ^^^^^^^^^^^^
    ...<9 lines>...
        blocking=args.blocking,
        ^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "/var/lib/buildbot/worker/cstratak-fedora-stable-s390x/3.x.cstratak-fedora-stable-s390x.lto-pgo/build/Lib/profiling/sampling/sample.py", line 610, in sample_live
    profiler = SampleProfiler(
        pid,
    ...<8 lines>...
        blocking=blocking,
    )
  File "/var/lib/buildbot/worker/cstratak-fedora-stable-s390x/3.x.cstratak-fedora-stable-s390x.lto-pgo/build/Lib/profiling/sampling/sample.py", line 89, in __init__
    raise SystemExit(err) from err
SystemExit: Failed to find the PyRuntime section in process 159220 on Linux platform


Traceback (most recent call last):
  File "/var/lib/buildbot/worker/cstratak-fedora-stable-s390x/3.x.cstratak-fedora-stable-s390x.lto-pgo/build/Lib/test/test_profiling/test_sampling_profiler/test_live_collector_ui.py", line 900, in test_run_failed_script_live
    main()
    ~~~~^^
  File "/var/lib/buildbot/worker/cstratak-fedora-stable-s390x/3.x.cstratak-fedora-stable-s390x.lto-pgo/build/Lib/profiling/sampling/cli.py", line 989, in main
    _main()
    ~~~~~^^
  File "/var/lib/buildbot/worker/cstratak-fedora-stable-s390x/3.x.cstratak-fedora-stable-s390x.lto-pgo/build/Lib/profiling/sampling/cli.py", line 1145, in _main
    handler(args)
    ~~~~~~~^^^^^^
  File "/var/lib/buildbot/worker/cstratak-fedora-stable-s390x/3.x.cstratak-fedora-stable-s390x.lto-pgo/build/Lib/profiling/sampling/cli.py", line 1251, in _handle_run
    _handle_live_run(args)
    ~~~~~~~~~~~~~~~~^^^^^^
  File "/var/lib/buildbot/worker/cstratak-fedora-stable-s390x/3.x.cstratak-fedora-stable-s390x.lto-pgo/build/Lib/profiling/sampling/cli.py", line 1386, in _handle_live_run
    sample_live(
    ~~~~~~~~~~~^
        process.pid,
        ^^^^^^^^^^^^
    ...<9 lines>...
        blocking=args.blocking,
        ^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "/var/lib/buildbot/worker/cstratak-fedora-stable-s390x/3.x.cstratak-fedora-stable-s390x.lto-pgo/build/Lib/profiling/sampling/sample.py", line 610, in sample_live
    profiler = SampleProfiler(
        pid,
    ...<8 lines>...
        blocking=blocking,
    )
  File "/var/lib/buildbot/worker/cstratak-fedora-stable-s390x/3.x.cstratak-fedora-stable-s390x.lto-pgo/build/Lib/profiling/sampling/sample.py", line 89, in __init__
    raise SystemExit(err) from err
SystemExit: Failed to find the PyRuntime section in process 149156 on Linux platform


Traceback (most recent call last):
  File "/var/lib/buildbot/worker/cstratak-fedora-stable-s390x/3.x.cstratak-fedora-stable-s390x.lto-pgo/build/Lib/profiling/sampling/sample.py", line 87, in __init__
    self.unwinder = self._new_unwinder(native, gc, opcodes, skip_non_matching_threads)
                    ~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/var/lib/buildbot/worker/cstratak-fedora-stable-s390x/3.x.cstratak-fedora-stable-s390x.lto-pgo/build/Lib/profiling/sampling/sample.py", line 102, in _new_unwinder
    return _remote_debugging.RemoteUnwinder(
           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
        self.pid,
        ^^^^^^^^^
    ...<7 lines>...
        **kwargs
        ^^^^^^^^
    )
    ^
RuntimeError: Failed to find the PyRuntime section in process 149156 on Linux platform


Traceback (most recent call last):
  File "/var/lib/buildbot/worker/cstratak-fedora-stable-s390x/3.x.cstratak-fedora-stable-s390x.lto-pgo/build/Lib/profiling/sampling/sample.py", line 87, in __init__
    self.unwinder = self._new_unwinder(native, gc, opcodes, skip_non_matching_threads)
                    ~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/var/lib/buildbot/worker/cstratak-fedora-stable-s390x/3.x.cstratak-fedora-stable-s390x.lto-pgo/build/Lib/profiling/sampling/sample.py", line 102, in _new_unwinder
    return _remote_debugging.RemoteUnwinder(
           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
        self.pid,
        ^^^^^^^^^
    ...<7 lines>...
        **kwargs
        ^^^^^^^^
    )
    ^
RuntimeError: Failed to find the PyRuntime section in process 159220 on Linux platform

@fedonman
fedonman deleted the fix-gh-153953-wave-test-coverage branch August 10, 2026 16:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Increase test coverage for the wave module

4 participants