Skip to content

PYTHON-5779 Coverage increase for compression_support.py#2770

Draft
aclark4life wants to merge 5 commits intomongodb:masterfrom
aclark4life:PYTHON-5779
Draft

PYTHON-5779 Coverage increase for compression_support.py#2770
aclark4life wants to merge 5 commits intomongodb:masterfrom
aclark4life:PYTHON-5779

Conversation

@aclark4life
Copy link
Copy Markdown
Contributor

@aclark4life aclark4life commented Apr 23, 2026

PYTHON-5779

Changes in this PR

Adds test/test_compression_support.py with unit tests for pymongo/compression_support.py:

  • validate_compressors() — string vs. iterable input, comma-separated parsing, order preservation, empty input, unknown-name warning, and per-compressor "library unavailable" warnings (snappy / zlib / zstd, including the Py3.14 message split). Uses patch("pymongo.compression_support._have_xxx", ...) so results are deterministic regardless of which optional libraries are installed locally.
  • validate_zlib_compression_level() — bounds (-1 / 9), out-of-range ValueError, non-integer TypeError, and string-to-int coercion.
  • CompressionSettings.get_compression_context() — returns the right *Context subclass per compressor name, picks the first compressor when several are listed, and returns None for empty / unknown input.
  • ZlibContext — compress/decompress roundtrip.
  • decompress() — zlib branch (bytes and memoryview inputs), snappy and zstd roundtrips (gated on _have_snappy() / _have_zstd()), and the unknown-compressorId ValueError path.

zlib-dependent tests are gated on _have_zlib() and import zlib lazily so the module loads on Python builds without zlib.

Test Plan

uv run --extra test python -m pytest test/test_compression_support.py -v

Checklist

Checklist for Author

  • Did you update the changelog (if necessary)?
  • Is there test coverage?
  • Is any followup work tracked in a JIRA ticket? If so, add link(s).

Checklist for Reviewer

  • Does the title of the PR reference a JIRA Ticket?
  • Do you fully understand the implementation? (Would you be comfortable explaining how this code works to someone else?)
  • Is all relevant documentation (README or docstring) updated?

@aclark4life aclark4life requested a review from a team as a code owner April 23, 2026 21:30
@aclark4life aclark4life requested review from caseyclements and Copilot and removed request for Copilot April 23, 2026 21:30
@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Apr 23, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 88.04%. Comparing base (f4219bd) to head (a0af3a6).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2770      +/-   ##
==========================================
+ Coverage   82.68%   88.04%   +5.36%     
==========================================
  Files         141      141              
  Lines       24406    24406              
  Branches     4176     4176              
==========================================
+ Hits        20179    21489    +1310     
+ Misses       3328     2024    -1304     
+ Partials      899      893       -6     
Flag Coverage Δ
auth-aws-rhel8-test-auth-aws-rapid-web-identity-python3.14-cov 35.01% <ø> (ø)
auth-aws-win64-test-auth-aws-rapid-web-identity-python3.14-cov 35.01% <ø> (-0.03%) ⬇️
auth-enterprise-macos-test-standard-auth-latest-python3.11-auth-ssl-sharded-cluster-cov 43.75% <ø> (ø)
auth-enterprise-rhel8-test-standard-auth-latest-python3.11-auth-ssl-sharded-cluster-cov 43.75% <ø> (ø)
auth-enterprise-win64-test-standard-auth-latest-python3.11-auth-ssl-sharded-cluster-cov 43.78% <ø> (ø)
auth-oidc-local-ubuntu-22-test-auth-oidc-default 48.61% <ø> (?)
compression-snappy-rhel8-test-standard-latest-python3.11-async-noauth-nossl-standalone-cov 59.36% <ø> (+0.01%) ⬆️
compression-snappy-rhel8-test-standard-latest-python3.12-async-noauth-ssl-replica-set-cov 61.48% <ø> (ø)
compression-snappy-rhel8-test-standard-latest-python3.13-async-auth-ssl-sharded-cluster-cov 61.09% <ø> (ø)
compression-snappy-rhel8-test-standard-latest-python3.14-async-noauth-nossl-standalone-cov 58.99% <ø> (-0.01%) ⬇️
compression-zlib-rhel8-test-standard-latest-python3.11-async-noauth-nossl-standalone-cov 59.35% <ø> (+<0.01%) ⬆️
compression-zlib-rhel8-test-standard-latest-python3.12-async-noauth-ssl-replica-set-cov 61.49% <ø> (-0.02%) ⬇️
compression-zlib-rhel8-test-standard-latest-python3.13-async-auth-ssl-sharded-cluster-cov 61.09% <ø> (ø)
compression-zlib-rhel8-test-standard-latest-python3.14-async-noauth-nossl-standalone-cov 59.00% <ø> (-0.03%) ⬇️
compression-zstd-rhel8-test-standard-latest-python3.11-async-noauth-nossl-standalone-cov 59.34% <ø> (-0.02%) ⬇️
compression-zstd-rhel8-test-standard-latest-python3.12-async-noauth-ssl-replica-set-cov 61.48% <ø> (+<0.01%) ⬆️
compression-zstd-rhel8-test-standard-latest-python3.13-async-auth-ssl-sharded-cluster-cov 61.09% <ø> (ø)
compression-zstd-rhel8-test-standard-latest-python3.14-async-noauth-nossl-standalone-cov 59.02% <ø> (+<0.01%) ⬆️
compression-zstd-ubuntu-22-test-standard-latest-python3.14-async-noauth-nossl-standalone-cov 58.98% <ø> (ø)
coverage-report-coverage-report 88.01% <ø> (+5.59%) ⬆️
disable-test-commands-rhel8-test-standard-latest-python3.11-async-noauth-nossl-standalone-cov 59.34% <ø> (-0.01%) ⬇️
disable-test-commands-rhel8-test-standard-latest-python3.12-async-noauth-ssl-replica-set-cov 61.50% <ø> (-0.01%) ⬇️
disable-test-commands-rhel8-test-standard-latest-python3.13-async-auth-ssl-sharded-cluster-cov 61.09% <ø> (ø)
disable-test-commands-rhel8-test-standard-latest-python3.14-async-noauth-nossl-standalone-cov ?
encryption-crypt_shared-macos-test-non-standard-latest-python3.13-noauth-nossl-standalone-cov 52.72% <ø> (?)
encryption-crypt_shared-macos-test-non-standard-latest-python3.14-auth-ssl-sharded-cluster-cov 54.54% <ø> (?)
encryption-crypt_shared-macos-test-non-standard-latest-python3.14t-noauth-ssl-replica-set-cov 54.35% <ø> (?)
encryption-crypt_shared-rhel8-test-non-standard-latest-python3.13-noauth-nossl-standalone-cov 52.72% <ø> (?)
encryption-crypt_shared-rhel8-test-non-standard-latest-python3.14-auth-ssl-sharded-cluster-cov 54.42% <ø> (?)
encryption-crypt_shared-rhel8-test-non-standard-latest-python3.14t-noauth-ssl-replica-set-cov 54.34% <ø> (?)
encryption-crypt_shared-win64-test-non-standard-latest-python3.13-noauth-nossl-standalone-cov 52.60% <ø> (?)
encryption-crypt_shared-win64-test-non-standard-latest-python3.14-auth-ssl-sharded-cluster-cov 54.45% <ø> (?)
encryption-crypt_shared-win64-test-non-standard-latest-python3.14t-noauth-ssl-replica-set-cov 54.42% <ø> (?)
encryption-macos-test-non-standard-latest-python3.13-noauth-nossl-standalone-cov 52.72% <ø> (?)
encryption-macos-test-non-standard-latest-python3.14-auth-ssl-sharded-cluster-cov 54.55% <ø> (?)
encryption-macos-test-non-standard-latest-python3.14t-noauth-ssl-replica-set-cov 54.34% <ø> (?)
encryption-pyopenssl-rhel8-test-non-standard-latest-python3.13-noauth-nossl-standalone-cov 53.38% <ø> (?)
encryption-pyopenssl-rhel8-test-non-standard-latest-python3.14-auth-ssl-sharded-cluster-cov 55.10% <ø> (?)
encryption-pyopenssl-rhel8-test-non-standard-latest-python3.14t-noauth-ssl-replica-set-cov 55.00% <ø> (?)
encryption-rhel8-test-non-standard-latest-python3.13-noauth-nossl-standalone-cov 52.72% <ø> (?)
encryption-rhel8-test-non-standard-latest-python3.14-auth-ssl-sharded-cluster-cov 54.41% <ø> (?)
encryption-rhel8-test-non-standard-latest-python3.14t-noauth-ssl-replica-set-cov 54.35% <ø> (?)
encryption-win64-test-non-standard-latest-python3.13-noauth-nossl-standalone-cov 52.60% <ø> (?)
encryption-win64-test-non-standard-latest-python3.14-auth-ssl-sharded-cluster-cov 54.53% <ø> (?)
encryption-win64-test-non-standard-latest-python3.14t-noauth-ssl-replica-set-cov 54.43% <ø> (?)
load-balancer-test-non-standard-latest-python3.14-auth-ssl-sharded-cluster-cov 48.40% <ø> (?)
mongodb-latest-test-server-version-python3.10-async-auth-ssl-sharded-cluster-min-deps-cov 61.47% <ø> (+<0.01%) ⬆️
mongodb-latest-test-server-version-python3.10-async-noauth-nossl-standalone-min-deps-cov 59.34% <ø> (-0.02%) ⬇️
mongodb-latest-test-server-version-python3.10-sync-auth-ssl-sharded-cluster-min-deps-cov 59.59% <ø> (+0.08%) ⬆️
mongodb-latest-test-server-version-python3.10-sync-noauth-nossl-replica-set-min-deps-cov 59.68% <ø> (+0.08%) ⬆️
mongodb-latest-test-server-version-python3.11-async-noauth-nossl-replica-set-cov 61.40% <ø> (-0.02%) ⬇️
mongodb-rapid-test-server-version-python3.10-async-auth-ssl-sharded-cluster-min-deps-cov 61.48% <ø> (ø)
mongodb-rapid-test-server-version-python3.10-async-noauth-nossl-standalone-min-deps-cov 59.34% <ø> (-0.02%) ⬇️
mongodb-rapid-test-server-version-python3.10-sync-auth-ssl-sharded-cluster-min-deps-cov 59.59% <ø> (+0.08%) ⬆️
mongodb-rapid-test-server-version-python3.10-sync-noauth-nossl-replica-set-min-deps-cov 59.68% <ø> (+0.08%) ⬆️
mongodb-rapid-test-server-version-python3.11-async-noauth-nossl-replica-set-cov 61.42% <ø> (-0.01%) ⬇️
mongodb-v4.2-test-server-version-python3.10-async-auth-ssl-sharded-cluster-min-deps-cov 57.17% <ø> (ø)
mongodb-v4.2-test-server-version-python3.10-async-noauth-nossl-standalone-min-deps-cov 55.62% <ø> (+0.01%) ⬆️
mongodb-v4.2-test-server-version-python3.10-sync-auth-ssl-sharded-cluster-min-deps-cov 57.15% <ø> (+0.08%) ⬆️
mongodb-v4.2-test-server-version-python3.10-sync-noauth-nossl-replica-set-min-deps-cov 57.25% <ø> (+0.08%) ⬆️
mongodb-v4.2-test-server-version-python3.11-async-noauth-nossl-replica-set-cov 57.35% <ø> (ø)
mongodb-v4.4-test-server-version-python3.10-async-auth-ssl-sharded-cluster-min-deps-cov 59.57% <ø> (ø)
mongodb-v4.4-test-server-version-python3.10-async-noauth-nossl-standalone-min-deps-cov 57.59% <ø> (+<0.01%) ⬆️
mongodb-v4.4-test-server-version-python3.10-sync-auth-ssl-sharded-cluster-min-deps-cov 57.66% <ø> (+0.08%) ⬆️
mongodb-v4.4-test-server-version-python3.10-sync-noauth-nossl-replica-set-min-deps-cov 57.74% <ø> (+0.08%) ⬆️
mongodb-v4.4-test-server-version-python3.11-async-noauth-nossl-replica-set-cov 59.37% <ø> (+0.02%) ⬆️
mongodb-v5.0-test-server-version-python3.10-async-auth-ssl-sharded-cluster-min-deps-cov 59.75% <ø> (-0.02%) ⬇️
mongodb-v5.0-test-server-version-python3.10-async-noauth-nossl-standalone-min-deps-cov 57.74% <ø> (ø)
mongodb-v5.0-test-server-version-python3.10-sync-auth-ssl-sharded-cluster-min-deps-cov 57.86% <ø> (+0.08%) ⬆️
mongodb-v5.0-test-server-version-python3.10-sync-noauth-nossl-replica-set-min-deps-cov 57.97% <ø> (+0.08%) ⬆️
mongodb-v5.0-test-server-version-python3.11-async-noauth-nossl-replica-set-cov 59.59% <ø> (+<0.01%) ⬆️
mongodb-v6.0-test-server-version-python3.10-async-auth-ssl-sharded-cluster-min-deps-cov 59.78% <ø> (+0.01%) ⬆️
mongodb-v6.0-test-server-version-python3.10-async-noauth-nossl-standalone-min-deps-cov 57.75% <ø> (+<0.01%) ⬆️
mongodb-v6.0-test-server-version-python3.10-sync-auth-ssl-sharded-cluster-min-deps-cov 57.88% <ø> (+0.08%) ⬆️
mongodb-v6.0-test-server-version-python3.10-sync-noauth-nossl-replica-set-min-deps-cov 58.02% <ø> (+0.08%) ⬆️
mongodb-v6.0-test-server-version-python3.11-async-noauth-nossl-replica-set-cov 59.72% <ø> (-0.03%) ⬇️
mongodb-v7.0-test-server-version-python3.10-async-auth-ssl-sharded-cluster-min-deps-cov 59.83% <ø> (+0.02%) ⬆️
mongodb-v7.0-test-server-version-python3.10-async-noauth-nossl-standalone-min-deps-cov 57.73% <ø> (ø)
mongodb-v7.0-test-server-version-python3.10-sync-auth-ssl-sharded-cluster-min-deps-cov 57.93% <ø> (+0.08%) ⬆️
mongodb-v7.0-test-server-version-python3.10-sync-noauth-nossl-replica-set-min-deps-cov 58.01% <ø> (+0.08%) ⬆️
mongodb-v7.0-test-server-version-python3.11-async-noauth-nossl-replica-set-cov 59.72% <ø> (-0.02%) ⬇️
mongodb-v8.0-test-server-version-python3.10-async-auth-ssl-sharded-cluster-min-deps-cov 61.49% <ø> (+0.01%) ⬆️
mongodb-v8.0-test-server-version-python3.10-async-noauth-nossl-standalone-min-deps-cov 59.35% <ø> (+0.02%) ⬆️
mongodb-v8.0-test-server-version-python3.10-sync-auth-ssl-sharded-cluster-min-deps-cov 59.58% <ø> (+0.08%) ⬆️
mongodb-v8.0-test-server-version-python3.10-sync-noauth-nossl-replica-set-min-deps-cov 59.68% <ø> (+0.08%) ⬆️
mongodb-v8.0-test-server-version-python3.11-async-noauth-nossl-replica-set-cov 61.42% <ø> (+0.01%) ⬆️
no-c-ext-rhel8-test-standard-latest-python3.11-async-noauth-nossl-standalone-cov 60.56% <ø> (+0.01%) ⬆️
no-c-ext-rhel8-test-standard-latest-python3.12-async-noauth-ssl-replica-set-cov 62.68% <ø> (-0.01%) ⬇️
no-c-ext-rhel8-test-standard-latest-python3.13-async-auth-ssl-sharded-cluster-cov 62.30% <ø> (ø)
no-c-ext-rhel8-test-standard-latest-python3.14-async-noauth-nossl-standalone-cov ?
ocsp-rhel8-test-ocsp-ecdsa-valid-cert-server-staples-latest-python3.14-cov 34.23% <ø> (+0.02%) ⬆️
ocsp-rhel8-test-ocsp-rsa-valid-cert-server-staples-latest-python3.14-cov 34.23% <ø> (+0.02%) ⬆️
pyopenssl-macos-test-standard-latest-python3.12-async-noauth-ssl-replica-set-cov 61.72% <ø> (?)
pyopenssl-rhel8-test-standard-latest-python3.12-async-noauth-ssl-replica-set-cov 61.75% <ø> (?)
pyopenssl-win64-test-standard-latest-python3.12-async-noauth-ssl-replica-set-cov 61.67% <ø> (?)
stable-api-accept-v2-rhel8-auth-test-standard-latest-python3.11-async-noauth-nossl-standalone-cov 59.35% <ø> (+<0.01%) ⬆️
stable-api-accept-v2-rhel8-auth-test-standard-latest-python3.14-async-noauth-nossl-standalone-cov 59.00% <ø> (-0.02%) ⬇️
stable-api-require-v1-rhel8-auth-test-standard-latest-python3.11-async-noauth-nossl-standalone-cov 59.32% <ø> (+<0.01%) ⬆️
stable-api-require-v1-rhel8-auth-test-standard-latest-python3.13-async-auth-ssl-sharded-cluster-cov 60.95% <ø> (ø)
stable-api-require-v1-rhel8-auth-test-standard-latest-python3.14-async-noauth-nossl-standalone-cov ?
storage-inmemory-rhel8-test-standard-latest-python3.11-async-noauth-nossl-standalone-cov 59.37% <ø> (+0.03%) ⬆️
storage-inmemory-rhel8-test-standard-latest-python3.14-async-noauth-nossl-standalone-cov 59.01% <ø> (-0.01%) ⬇️
test-macos-arm64-test-standard-latest-python3.11-async-noauth-nossl-standalone-cov 59.33% <ø> (ø)
test-macos-arm64-test-standard-latest-python3.12-async-noauth-ssl-replica-set-cov 61.49% <ø> (-0.03%) ⬇️
test-macos-arm64-test-standard-latest-python3.13-async-auth-ssl-sharded-cluster-cov 61.09% <ø> (+<0.01%) ⬆️
test-macos-arm64-test-standard-latest-python3.14-async-noauth-nossl-standalone-cov 58.98% <ø> (+0.01%) ⬆️
test-macos-test-standard-latest-python3.11-async-noauth-nossl-standalone-cov 59.33% <ø> (+0.02%) ⬆️
test-macos-test-standard-latest-python3.12-async-noauth-ssl-replica-set-cov 61.50% <ø> (+0.01%) ⬆️
test-macos-test-standard-latest-python3.13-async-auth-ssl-sharded-cluster-cov 61.09% <ø> (+0.01%) ⬆️
test-macos-test-standard-latest-python3.14-async-noauth-nossl-standalone-cov 58.98% <ø> (-0.01%) ⬇️
test-numpy-macos-arm64-test-numpy-python3.14-python3.14-cov 32.61% <ø> (-0.02%) ⬇️
test-numpy-macos-test-numpy-python3.14-python3.14-cov 32.61% <ø> (ø)
test-numpy-rhel8-test-numpy-python3.14-python3.14-cov 32.61% <ø> (ø)
test-numpy-win32-test-numpy-python3.14-python3.14-cov 32.59% <ø> (ø)
test-numpy-win64-test-numpy-python3.14-python3.14-cov 32.59% <ø> (ø)
test-win32-test-standard-latest-python3.11-async-noauth-nossl-standalone-cov 59.22% <ø> (+0.01%) ⬆️
test-win32-test-standard-latest-python3.12-async-noauth-ssl-replica-set-cov 61.47% <ø> (+0.03%) ⬆️
test-win32-test-standard-latest-python3.13-async-auth-ssl-sharded-cluster-cov 61.07% <ø> (ø)
test-win32-test-standard-latest-python3.14-async-noauth-nossl-standalone-cov 58.86% <ø> (-0.01%) ⬇️
test-win64-test-standard-latest-python3.11-async-noauth-nossl-standalone-cov 59.20% <ø> (+<0.01%) ⬆️
test-win64-test-standard-latest-python3.12-async-noauth-ssl-replica-set-cov 61.44% <ø> (-0.01%) ⬇️
test-win64-test-standard-latest-python3.13-async-auth-ssl-sharded-cluster-cov 61.07% <ø> (ø)
test-win64-test-standard-latest-python3.14-async-noauth-nossl-standalone-cov 58.87% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copilot AI review requested due to automatic review settings April 23, 2026 22:45
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds a new unit test module to increase coverage of pymongo/compression_support.py, focusing on optional-compression dependency detection, validation helpers, context selection, and zlib decompression behavior.

Changes:

  • Introduces test/test_compression_support.py with unit tests for _have_* helpers and validation functions.
  • Adds coverage for CompressionSettings.get_compression_context() and decompress() (including memoryview input for zlib).

Comment thread test/test_compression_support.py Outdated
Comment thread test/test_compression_support.py Outdated
@aclark4life aclark4life removed the request for review from caseyclements May 1, 2026 16:13
@aclark4life aclark4life marked this pull request as draft May 6, 2026 13:14
@aclark4life aclark4life marked this pull request as ready for review May 6, 2026 13:14
@aclark4life aclark4life marked this pull request as draft May 6, 2026 18:20
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 4 comments.

Comment thread test/test_compression_support.py
Comment thread test/test_compression_support.py
Comment thread test/test_compression_support.py
Comment thread test/test_compression_support.py
@aclark4life aclark4life force-pushed the PYTHON-5779 branch 2 times, most recently from 17f758a to cca1bf9 Compare May 7, 2026 00:27
@aclark4life aclark4life requested a review from Copilot May 7, 2026 02:02
@aclark4life aclark4life changed the title PYTHON-5779 Increase code coverage for compression_support.py PYTHON-5779 Improve code coverage for compression_support.py May 7, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 2 comments.

Comment thread test/test_compression_support.py Outdated
Comment on lines +51 to +52
self.assertIn("zlib", result)
self.assertIn("snappy", result)
Comment on lines +218 to +219
result = decompress(compressed, SnappyContext.compressor_id)
self.assertEqual(result, data)
@aclark4life aclark4life changed the title PYTHON-5779 Improve code coverage for compression_support.py PYTHON-5779 Improve coverage for compression_support.py May 7, 2026
@aclark4life aclark4life changed the title PYTHON-5779 Improve coverage for compression_support.py PYTHON-5779 Improve coverage for compression_support.py May 7, 2026
@aclark4life aclark4life changed the title PYTHON-5779 Improve coverage for compression_support.py PYTHON-5779 Coverage improvements for compression_support.py May 7, 2026
@aclark4life aclark4life changed the title PYTHON-5779 Coverage improvements for compression_support.py PYTHON-5779 Coverage improvement for compression_support.py May 7, 2026
@aclark4life aclark4life requested a review from Copilot May 7, 2026 02:29
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.

@aclark4life aclark4life changed the title PYTHON-5779 Coverage improvement for compression_support.py PYTHON-5779 Coverage increase for compression_support.py May 7, 2026
@aclark4life aclark4life requested a review from Copilot May 7, 2026 03:02
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants