Skip to content

PYTHON-5728 Improve bson code coverage - #2880

Merged
aclark4life merged 3 commits into
mongodb:masterfrom
aclark4life:PYTHON-5728
Jun 17, 2026
Merged

aclark4life merged 3 commits into
mongodb:masterfrom
aclark4life:PYTHON-5728

Conversation

@aclark4life

@aclark4life aclark4life commented Jun 17, 2026 •

Copy link
Copy Markdown
Contributor

PYTHON-5728

Changes in this PR

Test Plan

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?

Copilot AI review requested due to automatic review settings June 17, 2026 16:53
@aclark4life
aclark4life requested a review from a team as a code owner June 17, 2026 16:53
@aclark4life
aclark4life requested a review from NoahStapp June 17, 2026 16:53

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Adds targeted regression/unit tests to improve BSON-related code coverage, focusing on list encoding edge cases and DatetimeMS behavior.

Changes:

  • Add a round-trip encoding/decoding test for lists that cross the gen_list_name cached-key boundary.
  • Add tests covering DatetimeMS hashing, repr round-tripping, and constructor type/range validation.

Comment thread test/test_bson.py Outdated
Comment on lines +1766 to +1768
# Unequal values should produce unequal hashes (not guaranteed, but
# true for plain int hashes which is what DatetimeMS delegates to).
self.assertNotEqual(hash(DatetimeMS(0)), hash(DatetimeMS(1)))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I agree with the robot, we have enough issues caused by potential CPython/PyPy conflicts 😅 .

Comment thread test/test_bson.py Outdated
# Spot-check: the 1000th and 1001st elements (0-indexed) must
# survive the cache/on-demand boundary intact.
self.assertEqual(decode(doc)["a"][1000], 1000)
self.assertEqual(decode(doc)["a"][1001], 1001)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We should also check that the other side of the boundary doc["a"][999] is correct.

Comment thread test/test_bson.py Outdated
# boundary and verify the round-trip is correct.
values = list(range(1002))
doc = encode({"a": values})
self.assertEqual(decode(doc)["a"], values)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Store decode(doc) in a variable instead of decoding three times.

Comment thread test/test_bson.py Outdated
Comment on lines +1766 to +1768
# Unequal values should produce unequal hashes (not guaranteed, but
# true for plain int hashes which is what DatetimeMS delegates to).
self.assertNotEqual(hash(DatetimeMS(0)), hash(DatetimeMS(1)))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I agree with the robot, we have enough issues caused by potential CPython/PyPy conflicts 😅 .

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 requested a review from NoahStapp June 17, 2026 17:53
@aclark4life
aclark4life merged commit 18757e1 into mongodb:master Jun 17, 2026
85 of 90 checks passed
@aclark4life
aclark4life deleted the PYTHON-5728 branch June 17, 2026 19:17
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.

4 participants